Show TOC

LOOPLocate this document in the navigation structure

LOOP ( <table_parameter> , <alias_parameter> ).

LOOP ( <table_parameter> , <alias_parameter> , <command interface> ).

LOOP...ENDLOOP is more suitable than DO...ENDDO for looping over table parameters. The normal use case is where some action is to be performed on only a few table lines depending on the content of the table fields. Using LOOP avoids the complex expressions typical for DO…ENDDO.

The command interface allows you to specify WHERE conditions. Only the rows of the table that satisfy the conditions are looped over. If you do not specify conditions in the command interface, or there is no command interface, all the rows of the table are looped over.

The alias parameter must have the same structure as the line type of the table parameter. Select the Alias Parameter checkbox in the parameter list.

Inside the loop, the alias parameter references the current row of the table. If any changes are made to the parameter (for example, assignment of a value to a field), these changes instantly affect the table parameter.

Nesting

LOOP...ENDLOOP loops can be nested. An application for this would be where a field of the row is also a table.

Special Variables

&LTC

Loop table counter - the number of rows looped over. This increments by 1 for each row.

&TABIX

Table index - the index of the current table row.

Command Interface

The command interface contains a SELECTION field where you can define a table of WHERE conditions.

FIELD

Only elementary fields of the row can be used (not structured fields).

VALUE

If you enter a value, the WHERE condition is equals. If you enter no value, this is ignored (unless you specify something in RANGES).

RANGES

You can specify more complex conditions (for example, SIGN 'I', OPTION 'BT', LOW 'AA', HIGH 'LH').

Notes

Alias parameters cannot be used inside inline ABAP.

You can use EXIT to exit a loop.

Example

Examples of LOOP...ENDLOOP and DO...ENDDO with the same function:

LOOP ( SPFLI_TABLE , SPFLI_ROW ).

LOG ( SPFLI_ROW-CARRID ).

ENDLOOP.

GETLEN ( SPFLI_TABLE , LEN ).

DO ( LEN ).

LOG ( SPFLI_TABLE[&LPC]-CARRID ).

ENDDO.