Processing Control Levels
When you sort an extract dataset, control levels are defined in it. 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 AT statement within a loop to program statement blocks that the system processes only at a control break, that is, when the control level changes.
AT NEW
| AT END OF ....ENDAT.A control break occurs when the value of the field 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 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 00 in the field 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 , , ..., the processing of the control levels should be written between the other control statements as follows:LOOP.AT FIRST.... ENDAT.AT NEW ....... ENDAT. AT NEW ....... ENDAT. ...AT ..... ENDAT. ...AT END OF .... ENDAT. AT END OF .... ENDAT. AT LAST..... ENDAT.ENDLOOP.You do not have to use all of the statement blocks listed here, but only the ones you require. REPORT DEMO.DATA: T1(4), 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: In the loop, the system displays the contents of the dataset and the control breaks it encountered as follows:
No comments:
Post a Comment