Application Development and Automation Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

Control break statements

Former Member
0 Likes
552

Hi Guys,

I want to know all the control break statements. Thanks in advance.

Regards,

nagaraju

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
525

[AT FIRST.

...

ENDAT.]

[AT NEW comp1.

...

ENDAT.

[AT NEW comp2.

...

ENDAT.

[...]]]

[ ... ]

[[[...]

AT END OF comp2.

...

ENDAT.]

AT END OF comp1.

...

ENDAT.]

[AT LAST.

...

ENDAT.]

4 REPLIES 4
Read only

Former Member
0 Likes
526

[AT FIRST.

...

ENDAT.]

[AT NEW comp1.

...

ENDAT.

[AT NEW comp2.

...

ENDAT.

[...]]]

[ ... ]

[[[...]

AT END OF comp2.

...

ENDAT.]

AT END OF comp1.

...

ENDAT.]

[AT LAST.

...

ENDAT.]

Read only

Former Member
0 Likes
525

Hi,

Please refer to the docu below, extract from ABAPDOCU

1. AT NEW f.

2. AT END OF f.

3. AT FIRST.

4. AT LAST.

Variant 1

AT NEW f.

Variant 2

AT END OF f.

Effect

f is a sub-field of an internal table or extract dataset (EXTRACT) which is being processed with LOOP, i.e. the variants 1 and 2 only make sense within a LOOP.

Both "AT NEW f." and "AT END OF f. " introduce processing blocks which are concluded by " ENDAT.".

These processing blocks are processed whenever the contents of a field f or a sub-field defined before f change as a result of processing with LOOP. "AT NEW f." begins a new group of (table) lines with the same contents as the field f while "AT END OF f." concludes such a group.

Within the AT ... ENDAT processing of internal tables, all argument fields following f are filled with "*".


Examples 
1. AT for sub-fields of an internal table 


DATA: BEGIN OF COMPANIES OCCURS 20, 
        NAME(30), 
        PRODUCT(20), 
        SALES TYPE I, 
      END   OF COMPANIES. 
... 
LOOP AT COMPANIES. 
  AT NEW NAME. 
    NEW-PAGE. 
    WRITE / COMPANIES-NAME. 
  ENDAT. 
  WRITE: / COMPANIES-PRODUCT, COMPANIES-SALES. 
  AT END OF NAME. 
    SUM. 
    WRITE: / COMPANIES-NAME, COMPANIES-SALES. 
  ENDAT. 
ENDLOOP. 

The AT statements refer to the field COMPANIES-NAME.

Examples

2. AT for the field of an extract dataset


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. 

Notes

If the processing you want to perform on an internal table is fairly restricted (i.e. a WHERE addition with the LOOP statement), do not use the AT statements specified in variants 1 to 5, since the interaction of the WHERE addition and the AT statement is currently not defined.

When you use LOOP with an extract dataset, fields on hex zero are ignored during control level checking with AT NEW or AT END OF . This procedure is the same as the SORT statement. When sorting extracted datasets, this statement always sorts blank fields (i.e. fields on hex zero) regardless of the sequence (ascending or descending) before all fields that contain values.

Since fields addressed with AT are not set to an initial value when you enter a LOOP, the first new group of (table) lines in AT NEW f may not be processed, if f happens to be set to this value.

Variant 3

AT FIRST.

Variant 4

AT LAST.

Effect

The variants 3 and 4 only make sense within a LOOP.

The processing block between AT FIRST and ENDAT is executed before the individual lines are processed; the processing block between AT LAST and ENDAT is executed after all the individual lines have been processed.

In AT FIRST or AT LAST ... ENDAT processing, all argument fields are filled with "*" (internal tables).

When you are processing extract datasets, a control total SUM(n) can only be processed with AT END OF or AT LAST.


Example
DATA: BEGIN OF COMPANIES OCCURS 20, 
        NAME(30), 
        PRODUCT(20), 
        SALES TYPE I, 
      END   OF COMPANIES. 
... 
LOOP AT COMPANIES. 
  AT FIRST. 
    SUM. 
    WRITE:    'Sum of all SALES:', 
           55 COMPANIES-SALES. 
  ENDAT. 
  WRITE: / COMPANIES-NAME, COMPANIES-PRODUCT, 
        55 COMPANIES-SALES. 
ENDLOOP. 

Thanks,

Sriram Ponna

Read only

Former Member
0 Likes
525

HAi NAg

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 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 <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 00 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 as follows:

LOOP.

AT FIRST.... ENDAT.

AT NEW <f1>....... ENDAT.

AT NEW <f2>....... ENDAT.

...

AT <fgi>..... ENDAT.

<single line processing without control statement>

...

AT END OF <f2>.... ENDAT.

AT END OF <f1>.... 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.

Read only

Former Member
0 Likes
525

Hi

Control break statements are used to create statement blocks which process only specific table lines the LOOP – ENDLOOP block.

You open such a statement block with the control level statement AT and close it with the control level statement ENDAT. The syntax is as follows:

Table should be sorted when you use control-break statements

You can break the sequential access of internal tables by using these statements.

Syntax:

At first.

<Statement block>

Endat.

This is the first statement to get executed inside the loop (remember control break statements are applicable only inside the loop)

So in this block you can write or process those statements which you want to get executed when the loop starts.

At New carrid.

Write:/ carrid.

Endat.

In this case whenever the new carrid is reached, carrid will be written.

At End of carrid.

Uline.

Endat.

In this case whenever the end of carrid is reached, a line will be drawn.

At Last.

Write:/ ‘Last Record is reached’.

Endat.

Processing of statements within this block is done when entire processing of entire internal table is over. Usually used to display grand totals.

You can use either all or one of the above control break statements with in the loop for processing internal table.

At end of carrid.

Sum.

Endat.

In above case the statement SUM (applicable only within AT-ENDAT) will sum up all the numeric fields in internal table and result is stored in same internal table variable.