Entering content frame

Control Level Processing Locate the document in its SAP Library structure

When you perform a sort using the SORTstatement, control levels are defined in the extract dataset. For general information about control levels, refer to Processing Internal Tables in Loops The control level hierarchy of an extract dataset corresponds to the sequence of the fields in the header field group. After sorting, you can use the ATstatement within a LOOP loop to program statement blocks that the system processes only when the control level changes.

AT NEW f | AT END OF f.
...

ENDAT.

A control break occurs when the value of the field f or a superior field in the current record has a different value from the previous record (AT NEW) or the subsequent record (AT END). Field f must be part of the header field group.

If the extract dataset is not sorted, the AT - ENDAT block is never executed. Furthermore, all extract records with the value HEX null in the field f are ignored when the control breaks are determined.

The AT... ENDAT blocks in a loop are processed in the order in which they occur. This sequence should be the same as the sort sequence. This sequence must not necessarily be the sequence of the fields in the header field group, but can also be the one determined in the SORT statement.

If you have sorted an extract dataset by the fields f1, f2, …, the processing of the control levels should be written between the other control statements in the LOOP loop as follows:

LOOP.
  AT FIRST.... ENDAT.
    AT NEW f
1....... ENDAT.
      AT NEW f
2....... ENDAT.
     ...
          AT fg
i..... ENDAT.
          Single record processing without control statement
     ...

      AT END OF f
2.... ENDAT.
    AT END OF f
1.... ENDAT.
  AT LAST..... ENDAT.
ENDLOOP.

You do not have to use all of the statement blocks listed here, but only the ones you require.

Example

REPORT demo_extract_at_new.

DATA: t1(4) TYPE c, t2 TYPE i.

FIELD-GROUPS: header.

INSERT t2 t1 INTO header.

t1 ='AABB'. t2 = 1. EXTRACT header.
t1 ='BBCC'. t2 = 2. EXTRACT header.
t1 ='AAAA'. t2 = 2. EXTRACT header.
t1 ='AABB'. t2 = 1. EXTRACT header.
t1 ='BBBB'. t2 = 2. EXTRACT header.
t1 ='BBCC'. t2 = 2. EXTRACT header.
t1 ='AAAA'. t2 = 1. EXTRACT header.
t1 ='BBBB'. t2 = 1. EXTRACT header.
t1 ='AAAA'. t2 = 3. EXTRACT header.
t1 ='AABB'. t2 = 1. EXTRACT header.

SORT BY t1 t2.

LOOP.

  AT FIRST.
    WRITE 'Start of LOOP'.
    ULINE.
  ENDAT.

  AT NEW t1.
    WRITE / '   New T1:'.
  ENDAT.

  AT NEW t2.
    WRITE / '   New T2:'.
  ENDAT.

  WRITE: /14 t1, t2.

  AT END OF t2.
    WRITE / 'End of T2'.
  ENDAT.

  AT END OF t1.
    WRITE / 'End of T1'.
  ENDAT.

  AT LAST.
    ULINE.
  ENDAT.

ENDLOOP.

This program creates a sample extract, containing the fields of the header field group only. After the sorting process, the extract dataset has several control breaks for the control levels T1 and T2, which are indicated in the following figure:

This graphic is explained in the accompanying text

In the LOOP loop, the system displays the contents of the dataset and the control breaks it recognized as follows:

This graphic is explained in the accompanying text

 

 

 

 

Leaving content frame