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
1,102

hi all,

can any one please tell me more about the control break statements like at new, at first, at end etc... it would be helpful for me if u put in ur own words...

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
1,066

Hi,

Control break statements are used to stop the control at a particular point.

At New.

At End.

At First.

At Last.

On change of.

At New is used when we need to write something for a particular field.i.e.for every new item.

At End is used at the end of the item.

At First and At Last are also like that.

Message was edited by:

Roja Velagapudi

9 REPLIES 9
Read only

Former Member
0 Likes
1,067

Hi,

Control break statements are used to stop the control at a particular point.

At New.

At End.

At First.

At Last.

On change of.

At New is used when we need to write something for a particular field.i.e.for every new item.

At End is used at the end of the item.

At First and At Last are also like that.

Message was edited by:

Roja Velagapudi

Read only

Former Member
0 Likes
1,066

Hi,

1. AT NEW f.

2. AT END OF f.

3. AT FIRST.

4. AT LAST.

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 them is then executed if a control break occurs.

You can use these key words for control break processing with extract datasets only if the active LOOP statement is proceesing 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 start of a new control level (i.e. immediately after AT ), the following occurs in the output area of the current LOOP statement:

All default key 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 number fields (see also ABAP/4 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 LOOP s 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.

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 differnt value than in the preceding ( AT NEW ) or subsequent ( AT END OF ) table line.

Example

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 .

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.

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

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.

Regards,

Priyanka.

Read only

Former Member
0 Likes
1,066

Hi,

Control Break statements are used while displaying the output in a report or if we want do any processing on a special record say First record of the data or last record or on change of any data.

Different Control Break statements are : AT NEW, AT END OF, ON CHANGE OF, AT FIRST, AT LAST.

AT FIRST : AT FIRST is used if we want to do any processing on the first record of the loop. e.g. If we want to display the headers.

AT LAST : This is used if any processing is required at the last record of the loop. e.g. If we wanna display the footers.

AT NEW : This statement is used if we want to trigger the processing on a new record.e.g. Say if a table has the following records :

MATNR MATKL QTY

A 1 2

A 3 5

B 2 1

B 4 6

In this case AT NEW MATNR will be fired at A 1 2 and record B 2 1

AT END OF: This statement is used if we want to trigger the processing on the end of a set of records.e.g. Say if a table has the following records :

MATNR MATKL QTY

A 1 2

A 3 5

B 2 1

B 4 6

In this case AT END OF MATNR will be fired at A 3 5 and record B 4 6

Regards,

Himanshu

Read only

Former Member
0 Likes
1,066

See the sample program and i did not use collect command,eventhough i am displaying totals and subtotals.

&----


*& Report ZTEST_IEVENTS

*&

&----


*&

*&

&----


REPORT ZTEST_IEVENTS no standard page heading

line-count 40(2).

tables : vbap.

data : begin of i_vbap occurs 0,

vbeln like vbap-vbeln,

posnr like vbap-posnr,

matnr like vbap-matnr,

kwmeng like vbap-kwmeng,

netpr like vbap-netpr,

end of i_vbap.

data wa_vbap like line of i_vbap.

data v_flag type c.

select-options s_vbeln for vbap-vbeln obligatory.

start-of-selection.

select vbeln

posnr

matnr

kwmeng

netpr from vbap

into table i_vbap

where vbeln in s_vbeln.

sort i_vbap by vbeln posnr.

end-of-selection.

loop at i_vbap.

move i_vbap to wa_vbap.

at first.

write:/2 'Order #',15 'Item #',28 'Material #',50 'Qty', 70 'Net value'.

skip 1.

endat.

at new vbeln.

write:/2 wa_vbap-vbeln,15 wa_vbap-posnr,28 wa_vbap-matnr,

47 wa_vbap-kwmeng,65 wa_vbap-netpr.

v_flag = 'X'.

endat.

if v_flag ne 'X'.

write:/15 wa_vbap-posnr,28 wa_vbap-matnr,

47 wa_vbap-kwmeng,65 wa_vbap-netpr.

endif.

at end of vbeln.

sum.

skip 1.

write:/5 'Sub totals', 47 i_vbap-kwmeng,65 i_vbap-netpr.

skip 1.

endat.

at last .

skip 1.

sum.

write:/5 'Grand Totals',47 i_vbap-kwmeng,65 i_vbap-netpr.

skip 1.

write:/ 'end of page', 'Footer'.

endat.

clear v_flag.

endloop.

Reward Points if it is helpful

Thanks

Seshu

Read only

Former Member
0 Likes
1,066

Hi

Control break statements use in Loop..endloop.

At new

Ex AT NEW matnr

write : / something

endat.

whenever new material,display something.

At first field

display soemthig

endat

at last

if you want to write or any calclation after that last field use this

end at

at end

if u want to do sum for material

use

AT END

SUM

ENDAT

calculations can be done .

Thanks

Read only

Former Member
0 Likes
1,066

Hi,

1)

<b>AT NEW will be triggered when the first occurence of the value in the internal table..</b>

Let's say..

1

1

1

2

The AT NEW will be triggered when SY-TABIX = 1 AND SY-TABIX = 4.

<b>2) the AT FIRST will be triggered at the first time of the internal table processing..</b>

IF SY-TABIX = 1.

<b>3) The AT END OF will be triggered at the last occurence of the value..</b>

Let's say..

1

1

1

2

The AT END OF will be triggered at the rows SY-TABIX = 3 & 4

<b>4) AT LAST</b>

AT LAST will be triggered at the last occurence of the internal table processing..

Thanks,

Naren

Read only

Former Member
0 Likes
1,066

Hi,

AT NEW will be triggered at the first occurence of the field value..

AT END OF will be triggered at the last occurenct of the field value..

Ex for AT NEW & AT END :

DATA: ITAB LIKE MARA OCCURS 0 WITH HEADER LINE.

ITAB-MATNR = '123'. APPEND ITAB.

ITAB-MATNR = '123'. APPEND ITAB.

ITAB-MATNR = '123'. APPEND ITAB.

ITAB-MATNR = '123'. APPEND ITAB.

ITAB-MATNR = '1234'. APPEND ITAB.

SORT ITAB BY MATNR.

LOOP AT ITAB.

AT NEW MATNR.

WRITE: / 'AT NEW TRIGGERED - ROW NO - ', SY-TABIX.

ENDAT.

AT END OF MATNR.

WRITE: / 'AT END TRIGGERED - ROW NO - ', SY-TABIX.

ENDAT.

ENDLOOP.

Regards,

Padmam.

Read only

0 Likes
1,066

thanks to all..

Read only

Former Member
0 Likes
1,066

Hi,

Please close the thread if the problem is solved..

Thanks,

Naren