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 EVENTS

Former Member
0 Likes
10,878

WHERE CONTROL BREAK EVENTS ARE USED?can anybody give clear information?

4 REPLIES 4
Read only

Former Member
0 Likes
6,690

control break statements are

<b>at new</b>(every new record follows)

<b>at first</b> (at the top of the list i.e,first statement like headers)

<b>at end of</b> (every record ends it get triggered)

<b>at last</b> ( it is useful in summation of records) these r used in loop statements only

If you want to execute some statements for certain records of the dataset only, use the control statements AT and ENDAT.

The system processes the statement blocks between the control statements for the different options of AT as follows:

<b>AT FIRST</b>

The system executes the statement block once for the first record of the dataset.

<b>AT LAST</b>

The system executes the statement block once for the last record of the dataset.

You can also use the AT and ENDAT statements for control level processing.

reward if it helps u

vijay pawar

Read only

Former Member
0 Likes
6,690

hi Reddy,

they are used in LOOP ... ENDLOOPs.

loop at itab.

AT FIRST -


> Gets triggered before the first row is looped

AT NEW MATNR -


> for every change in MATNR AT NEW gets triggered

AT END OF MATNR-----> At the end of every change in MATNR

AT LAST.----


> After last record

endloop.

Read only

Former Member
0 Likes
6,690

Hi

Control break statements are used in reports. They r used between Loop and Endloop.

Please award points to the suitable answers and close the thread if ur problem is solved.

Regards

Haritha.

Read only

Former Member
0 Likes
6,690

AT - Control breaks with internal tables

Variants:

1. AT NEW f.

2. AT END OF f.

3. AT FIRST.

4. AT LAST.

Effect

In a LOOP which processes an internal table, 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 them is then executed if a control break occurs.

You can use these key words for control break processing with internal tables only if a loop is actively processing an internal table and reference is to the innermost currently active loop.

The control level structure with internal tables is static. It corresponds exactly to the sequence of columns in the internal table (from left to right). In this context, the criteria according to which you sort the internal table are unimportant.

At the start of a new control level (i.e. immediately after AT), the following occurs in the output area of the current LOOP statement:

All character type fields (on the right) are filled with "*" after the current control level key.

All other fields (on the right) are set to their initial values after the current control level key.

Between AT and ENDAT, you can use SUM to insert the appropriate control totals in the numeric fields (see also ABAP Number Types) of the LOOP output area (on the right) after the current control level key. Summing is supported both at the beginning of a control level (AT FIRST, AT NEW f) and also the end of a control level (AT END OF f, AT LAST).

At the end of the control level processing (i.e. after ENDAT), the old contents of the LOOP output area are restored.

Notes

When calculating totals, you must ensure that the totals are inserted into the same sub-fields of the LOOP output area as those where the single values otherwise occur. If there is an overflow, processing terminates with a runtime error.

If an internal table is processed only in a restricted form (using the additions FROM, TO and/or WHERE with the LOOP statement), you should not use the control structures for control level processing because the interaction of a restricted LOOP with the AT statement is currenly not properly defined.

With LOOPs on extracts, there are also special control break control structures you can use.

Note

Non-Catchable Exceptions:

SUM_OVERFLOW: Overflow when calculating totals with SUM.

Variant 1

AT NEW f.

Variant 2

AT END OF f.

The syntax check performed in an ABAP Objects context is stricter than in other ABAP areas.See Compatible Work Area with Control Level Processing and Field Symbols Not Allowed as Control Level Criterion.

Effect

f is a sub-field of an internal table processed with LOOP. The sequence of statements which follow it is executed if the sub-field f or a sub-field in the current LOOP line defined (on the left) before fhas a different value than in the preceding (AT NEW) or subsequent (AT END OF) table line.

Example

TYPES: BEGIN OF COMPANIES_TYPE, 
        NAME(30), 
        PRODUCT(20), 
        SALES TYPE I, 
      END   OF COMPANIES_TYPE. 

DATA: COMPANIES TYPE STANDARD TABLE OF COMPANIES_TYPE WITH 
                     NON-UNIQUE DEFAULT KEY INITIAL SIZE 20, 
      WA_COMPANIES TYPE COMPANIES_TYPE. 

... 

LOOP AT COMPANIES INTO WA_COMPANIES. 
  AT NEW NAME. 
    NEW-PAGE. 
    WRITE / WA_COMPANIES-NAME. 
  ENDAT. 
  WRITE: / WA_COMPANIES-PRODUCT, WA_COMPANIES-SALES. 
  AT END OF NAME. 
    SUM. 
    WRITE: / WA_COMPANIES-NAME, WA_COMPANIES-SALES. 
  ENDAT. 
ENDLOOP.

The AT statements refer to the field COMPANIES-NAME.

Notes

If a control break criterion is not known until runtime, you can use AT NEW (name) or AT END OF (name) to specify it dynamically as the contents of the field name. If name is blank at runtime, the control break criterion is ignored and the sequence of statements is not executed. If name contains an invalid component name, a runtime error occurs.

By defining an offset and/or length, you can further restrict control break criteria - regardless of whether they are specified statically or dynamically.

A field symbol pointing to the LOOP output area can also be used as a dynamic control break criterion. If the field symbol does not point to the LOOP output area, a runtime error occurs.

If you use AT within a LOOP with an explicitly-specified output area, the area must be compatible with the line type of the internal table so that it can be initialized properly (as described above) at the start of a new control level.

You can restrict control break criteria further, regardless of whether they were defined statically or dynamically, by specifying offset and/or length.

Variant 3

AT FIRST.

Variant 4

AT LAST.

Effect

Executes the appropriate sequence of statements once during the first (AT FIRST) or last (AT LAST) loop pass.

Example

TYPES: BEGIN OF COMPANIES_TYPE, 
        NAME(30), 
        PRODUCT(20), 
        SALES TYPE I, 
      END   OF COMPANIES_TYPE. 

DATA: COMPANIES TYPE STANDARD TABLE OF COMPANIES_TYPE WITH 

                     NON-UNIQUE DEFAULT KEY INITIAL SIZE 20, 

      WA_COMPANIES TYPE COMPANIES_TYPE. 

... 
LOOP AT COMPANIES INTO WA_COMPANIES. 
AT FIRST. 
SUM. 
WRITE: 'Sum of all SALES:', 
55 WA_COMPANIES-SALES. 
ENDAT. 
WRITE: / WA_COMPANIES-NAME, WA_COMPANIES-PRODUCT, 
55 WA_COMPANIES-SALES. 
ENDLOOP.