Application Development 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: 

control break commands

Former Member
0 Kudos

hi all

let me make it clear it to u that i know what are the control commands and what is there purpose.

but only thing i want to know that how should i decide

that when to use which control command.

plz clarify my doubt

thanks & regards

sanjeev

1 ACCEPTED SOLUTION

Former Member
0 Kudos

Hi Sanjeev

As with most things I think it depends on the circumstances! For example, you might use AT NEW within a loop if you want to display some kind of sub-heading line on a report before processing the actual data or two refresh a counter variable. Conversely, you might use the AT END control break to output some sub-total summary data for each group of records. AT FIRST and AT LAST could be used for overall Heading data or grand totals respectively.

Hope this is of some help - please feel free to post a specific example if you need more help.

Andy

7 REPLIES 7

Former Member
0 Kudos

Hi Sanjeev

As with most things I think it depends on the circumstances! For example, you might use AT NEW within a loop if you want to display some kind of sub-heading line on a report before processing the actual data or two refresh a counter variable. Conversely, you might use the AT END control break to output some sub-total summary data for each group of records. AT FIRST and AT LAST could be used for overall Heading data or grand totals respectively.

Hope this is of some help - please feel free to post a specific example if you need more help.

Andy

Former Member
0 Kudos

Hi Sanjeev,

Check

<b>Control Break Statements</b>

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.

Regards,

Santosh

Former Member
0 Kudos

Have a look at this link. It may help you.

http://www.sts.tu-harburg.de/teaching/sap_r3/ABAP4/at_itab.htm

Best Regards,

Vibha

*Please mark all the helpful answers

former_member404244
Active Contributor
0 Kudos

Hi Sanjeev,

control break statements are used inorder to break the sequential access of an internal table.

Before using control break statements we should sort the internal table.

also it should be used with in LOOP/ENDLOOP.

Sort itab.

loop at itab..

at first

....

endat.

at new <field>

...

endat.

at end of <field>

....

endat.

at last.

...

endat.

endloop.

Hoping this helps u.

Regards,

nagaraj

Former Member
0 Kudos

refrer program in SE38.

to get in detail..

REPORT demo_int_tables_at_2 .

and also......u can read this...

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

Runtime errors:

SUM_OVERFLOW: Overflow when calculating totals with SUM.

Variant 1

AT NEW f.

Variant 2

AT END OF f.

In an ABAP Objects context, a more severe syntax check is performed that 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 f has 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.

Note

Runtime errors:

AT_BAD_PARTIAL_FIELD_ACCESS: Invalid sub-field access when dynamically specifying the control break criterion.

AT_ITAB_FIELD_INVALID: When dynamically specifying the control break criterion via a field symbol, the field symbol does not point to the LOOP output area.

ITAB_ILLEGAL_COMPONENT: When dynamically specifying the control break criterion via (name) the field (name) does not contain a valid sub-field name.

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.

Additional help

Processing Table Lines in Loops

Former Member
0 Kudos

Hi,

assume scenario where you want to display

for each material plant total available stock.

matnr werks lgort qty

A 1000 W200 10

A 1000 w201 20

B 1000 w202 10.

output

A 1000 30

b 1000 10.

for above scenario

sort itab by matnr werks lgort.

loop at itab.

at end of matnr.

sum.

write:itab-matnr,itab-werks,itab-qty.

endloop.

endloop.

Regards

Amole

Former Member
0 Kudos

The decision on which control command to use depends on the requirement...but you can check the below guidelines.

AT FIRST.

->Write headings

->Initialise variables for total etc.

->Set the flags for first record etc

AT LAST.

->Grand totals.

->Write footer

AT NEW

->Initialise variables

->Any specific routine on the start of new combination.

AT END

->Any specific routine on end of the combination.

->to get sub-totals etc