AT - Control Level Processing

AT - Control breaks with extracts

Variants:

1. AT NEW f.
2. AT END OF f.
3. AT FIRST.
4. AT LAST.
5. AT fg.

Effect

In a LOOP which processes a dataset created with EXTRACT , you can use special control structures for control break processing. All these structures begin with AT and end with ENDAT. The sequence of statements which lies between is executed whenever a control break occurs.

You can use these key words for control break processing with extract datasets only if the active LOOP statement is processing an extract dataset.

The control level structure with extract datasets is dynamic. It corresponds exactly to the sort key of the extract dataset, i.e. to the order of fields in the field group HEADER by which the extract dataset was sorted .

At the end of a control group (AT END OF, AT LAST), there are two types of control level information between AT and ENDAT:

The fields CNT(h) and SUM(g) can only be addressed after they have been sorted. Otherwise, a runtime error may occur.

Effect

f is a field from the field group HEADER. The enclosed sequence of statements is executed if

If f is not an assigned field symbol, the control break criterion is ignored, and the subsequent sequence of statements is not executed. If a field symbol is assigned, but does not point to the HEADER field group, the system triggers a runtime error.

Example

DATA: NAME(30), 
	SALES TYPE I. 
FIELD-GROUPS: HEADER, INFOS. 
INSERT: NAME  INTO HEADER, 
		SALES INTO INFOS. 
... 
LOOP. 
  AT NEW NAME. 
	NEW-PAGE. 
  ENDAT. 
  ... 
  AT END OF NAME. 
	WRITE: / NAME, SUM(SALES). 
  ENDAT. 
ENDLOOP.

If the extract dataset is not sorted before processing with LOOP, no control level structure is defined and the statements following AT NEW or AT END OF are not executed.

Effect

Executes the relevant series of statements just once - either on the first loop pass (with AT FIRST) or on the last loop pass (with AT LAST).

Addition:

... WITH fg1

Effect

This statement makes single record processing dependent on the type of extracted record.

The sequence of statements following AT fg are executed whenever the current LOOP record is created with EXTRACT fg (in other words: when the current record is a fg record).

Effect

Executes the sequence of statements belonging to AT fg WITH fg1 only if the record of the field group fg in the dataset is immediately followed by a record of the field group fg1.