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: 

Explain At New At End At first At Last On change of

Former Member
0 Kudos

Dear All

Pls Explain At New, At End of, At first, At Last ,On change of .

Vikas

2 REPLIES 2

Former Member
0 Kudos

Hi

All this AT NEW, AT FIRST, AT END OF and AT LAST are called control break statements of Internal tables and are used to calculate the TOTALS based on sertain key fields in that internal table

FIrst to use these statements the ITAB has to be sorted by the key fields on whcih you need the SUM of the fields.

Some time you will get * when mopving data from this int table to other table using these commands

so you have to use

READ TABLE ITAB INDEX SY-TABIX in AT..ENDAT..if you are using other fields between them

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.

<b>Reward points for useful Answers</b>

Regards

Anji

Former Member
0 Kudos

hi,

Control break logic dictates that the table be sorted in the order of the "break" fields.

a) When AT NEW occurs,

the alpha-numeric fields have ******* in their value,

b) where as in case of ON CHANGE,

the alpha-numeric fields have their corresponding value,

of that particular record,

where the Event gets fired.*----


Other differences are :

ON CHANGE OF can be used any where in the program..

on change of differs from at new in the following respects:

1.It can be used in any loop construct, not just loop at. For example, it can be used within select and endselect, do and enddo, or while and endwhile, as well as inside get events.

2.A single on change of can be triggered by a change within one or more fields named after of and separated by or. These fields can be elementary fields or field strings. If you are within a loop, these fields do not have to belong to the loop.

3.When used within a loop, a change in a field to the left of the control level does not trigger a control break.

4.When used within a loop, fields to the right still contain their original values; they are not changed to contain zeros or asterisks.

5.You can use else between on change of and endon.

6.You can use it with loop at it where . . ..

7.You can use sum with on change of. It sums all numeric fields except the one(s) named after of.

8.Any values changed within on change of remain changed after endon. The contents of the header line are not restored as they are for at and endat.

while

AT NEW can be used only within a loop of an INTERNAL TABLE..

*----


5. Sample program to get the taste of it

(just copy paste)

6.

REPORT ABC.

DATA : BEGIN OF ITAB OCCURS 0,

bukrs like t001-bukrs,

f1(10) type c,

end of itab.

itab-bukrs = '1000'.

itab-f1 = '1111111'.

append itab.

itab-bukrs = '1100'.

itab-f1 = '3333333'.

append itab.

itab-bukrs = '1200'.

itab-f1 = '555555'.

append itab.

*----


AT NEW

loop at itab.

at new bukrs.

write 😕 itab-bukrs , itab-f1.

endat.

endloop.

*----


AT ONCHANGE

loop at itab.

ON CHANGE OF ITAB-BUKRS.

write 😕 itab-bukrs , itab-f1.

ENDON.

endloop.

check these threads..