Syntax for LOOP on Internal Table part two

This syntax check on loop in internal table is in continuation with part one .

Addition 1

... FROM n1

Addition 2

... TO n2

Effect

Places all internal table entries from the entry with the index (SY-TABIX ) = n1 to the entry with the index = n2 inclusive in the output area in turn.

If either one of the additions " FROM n1 " or " TO n2 " is missing, then the table is processed either from the first entry or up to the last entry (according to what is missing).

Example

Output table entries 7 and 8:

DATA: BEGIN OF T OCCURS 100,

BAREA(5), BLNCE(5),

END OF T.

LOOP AT T FROM 7 TO 8.

WRITE: / T-BAREA, T-BLNCE.

ENDLOOP.

Addition 3


... WHERE logexp

Effect

Places all internal table entries which satisfy the condition logexp in turn in the output area. The condition logexp can be almost any logical expression . The only restriction is that the first field for each comparison must be a sub-field of the line structure of the internal table itab .

Example

DATA: BEGIN OF T OCCURS 100,

BAREA(5), BLNCE(5),

END OF T.

LOOP AT T WHERE BAREA > 0.

WRITE: / T-BAREA, T-BLNCE.

ENDLOOP.

which has the same effect as:

LOOP AT T.

CHECK T-BAREA > 0.

WRITE: / T-BAREA, T-BLNCE.

ENDLOOP.

Avoid using either the AT NEW/END OF or FIRST/LAST statements in a LOOP loop with a WHERE condition.

The performance of a LOOP AT ... WHERE statement can be improved significantly if the fields to be compared always have the same data type. The comparison fields should be defined as follows:

DATA LIKE .

Example

DATA: BEGIN OF T OCCURS 100,

BAREA(5), BLNCE(5),

END OF T.

DATA CMP_BAREA LIKE T-BAREA.

CMP_BAREA = '01'.

LOOP AT T WHERE BAREA = CMP_BAREA.

WRITE: / T-BAREA, T-BLNCE.

ENDLOOP.

IF KEYWORD

IMPORT PART ONE AND TWO

INCLUDE


INFOTYPES

No comments :

Post a Comment