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

regarding control break statements

Former Member
0 Likes
870

hi to all.

i fetch the data from 3 tables(sorted by region also).

n list is like

group g/l a/c plant amount region(east/west/north/sth).

now my requirement is i want to sum amounts at the end of each region.

i used AT END OF REGION.

but the o/p comes for each record.

if i used AT END OF G/LACC.

OUTPUT IS CORRECT like at the end of each g/l total sum of amounts.

i want only at the end of each region.

plz giv me reply asap.

thanks n regards

satya

8 REPLIES 8
Read only

Former Member
0 Likes
844

try this

it will surely give you some idea.

Pls reward if help.

AT - Control break 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 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.

DATA: sflight_tab TYPE SORTED TABLE OF sflight

WITH UNIQUE KEY carrid connid fldate,

sflight_wa LIKE LINE OF sflight_tab.

SELECT *

FROM sflight

INTO TABLE sflight_tab.

LOOP AT sflight_tab INTO sflight_wa.

AT NEW connid.

WRITE: / sflight_wa-carrid,

sflight_wa-connid.

ULINE.

ENDAT.

WRITE: / sflight_wa-fldate,

sflight_wa-seatsocc.

AT END OF connid.

SUM.

ULINE.

WRITE: / 'Sum',

sflight_wa-seatsocc UNDER sflight_wa-seatsocc.

SKIP.

ENDAT.

AT END OF carrid.

SUM.

ULINE.

WRITE: / 'Carrier Sum',

sflight_wa-seatsocc UNDER sflight_wa-seatsocc.

NEW-PAGE.

ENDAT.

AT LAST.

SUM.

WRITE: / 'Overall Sum',

sflight_wa-seatsocc UNDER sflight_wa-seatsocc.

ENDAT.

ENDLOOP.

Read only

Former Member
0 Likes
844

Data in fields to the left affect the field on which you are using control break statements.

Create your internal table with Region as the 1st field. Sort the internal table data. Then use the control break statement AT NEW REGION.

Read only

0 Likes
844

hi rao,

the postion of region must be last,req is like daat.

is there any other option.

regards

satya

Read only

0 Likes
844

hi rao,

i put the region in internal table as a first field.n sort out.

still no use,the o/p comes at the end of each record,

y itz taking like dat.

plz help me,

regards

satya

Read only

Former Member
0 Likes
844

In the output internal table put the amount field in the last

as

group g/l a/c plant region(east/west/north/sth) amount .

Sort the internal table

SORT itab by group

g/l a/c

plant

region.

Now use

at end of region.

sum.

z_amount = amount.

endat.

Read only

0 Likes
844

hi mukesh,

i didnt gget ur control break logic.

plz xplain clearly.

regards

satya

Read only

0 Likes
844

hi mukesh n rao.

i tried for all fields with AT END OF,i got the o/p (except region).

y itz nt coming for this particular field.

my requirement is based on region wise,i want to summarize all of the amounts under region..

plz giv me some idea asap.

regards

satya

Read only

Former Member
0 Likes
844

Internal table (ITAB) fields declaration (use the same order)

Region

Group

G/L a/c

Plant

Amount

SORT itab.

Loop at ITAB.

AT END of REGION.

SUM.

ENDAT.

Endloop.