abap last row in loop
To retrieve the last row in a loop in ABAP, you can use the LOOP AT ... ENDLOOP
statement along with the END OF
addition. Here's an example:
DATA: lt_table TYPE TABLE OF string,
lv_last_row TYPE string.
APPEND 'Row 1' TO lt_table.
APPEND 'Row 2' TO lt_table.
APPEND 'Row 3' TO lt_table.
LOOP AT lt_table INTO lv_last_row.
IF sy-tabix = lines( lt_table ).
WRITE: / 'Last row:', lv_last_row.
ENDIF.
ENDLOOP.
In this example, we have a table lt_table
with three rows. The LOOP AT lt_table INTO lv_last_row
statement iterates through each row of the table. The IF sy-tabix = lines( lt_table )
condition checks if the current row is the last row by comparing the system field sy-tabix
(which represents the current loop index) with the total number of lines in the table lines( lt_table )
. If it is the last row, the value of lv_last_row
is displayed using the WRITE
statement.
Please note that the example provided is a simplified version to demonstrate the concept. In a real-world scenario, you would typically have more complex logic within the loop.