‎2007 Jul 12 12:47 PM
Hi,
give me a brief description about on change of, at first, at last, exit, contine, stop with example.
please help me.
shyja
‎2007 Jul 12 12:50 PM
Hi
EXIT --Exits that current Loop pass
COntinue --also skips that Loop pass for which the condition fails
STOP - Comes out of that processing block and goes to end-of-selection
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
Message was edited by:
Anji Reddy Vangala
‎2007 Jul 12 12:50 PM
Hi
EXIT --Exits that current Loop pass
COntinue --also skips that Loop pass for which the condition fails
STOP - Comes out of that processing block and goes to end-of-selection
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
Message was edited by:
Anji Reddy Vangala
‎2007 Jul 12 12:51 PM
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..
‎2007 Jul 12 12:57 PM
Hi,
go through the below link.
http://www.sts.tu-harburg.de/teaching/sap_r3/ABAP4/at_itab.htm
Regards,
Nagaraj
‎2007 Jul 12 1:28 PM
hi
&----
*& Report YCL_CONTROL_LEVEL_STMT *
*& *
&----
*& *
*& *
&----
REPORT YCL_EVENT_CONTROL_LVL_ST .
DATA:
BEGIN OF WA_ACC,
CUSTno TYPE ZACCTMAST2-CUSTNO, " ASTER-CUSTID,
ACCTYPE TYPE ZACCTMAST2-ACCTYPE, " ZCL_ACCMASTER-ACCTYPE,
ACCNO TYPE ZACCTMAST2-AccNo, " ZCL_ACCMASTER-ACCNO,
value TYPE ZACCTMAST2-Value, " ZCL_ACCMASTER-value,
end of wa_Acc,
IT_ACC like TABLE OF wa_acc.
SELECT * FROM ZCL_ACCMASTER INTO corresponding fields of TABLE IT_ACC.
SELECT * FROM ZACCTMAST2 INTO corresponding fields of TABLE IT_ACC.
SORT IT_ACC BY CUSTno acctype.
LOOP AT IT_ACC INTO WA_ACC.
AT FIRST.
FORMAT COLOR COL_KEY.
WRITE: / 'Customer wise balance report' .
FORMAT COLOR OFF.
ENDAT.
AT NEW CUSTno .
FORMAT COLOR COL_HEADING.
WRITE: / 'Customer ID: ', WA_ACC-CUSTno .
FORMAT COLOR OFF.
ENDAT.
ON CHANGE OF wa_acc-acctype.
write: / 'Account Type :' , wa_acc-acctype.
endon.
WRITE: /10 WA_ACC-ACCNO, wa_ACC-value.
AT end of CUSTno .
SUM.
FORMAT COLOR COL_TOTAL.
WRITE: / 'Customer Balance: ', WA_ACC-VALUE .
FORMAT COLOR OFF.
ENDAT.
AT LAST.
SUM.
FORMAT COLOR COL_KEY.
WRITE: / 'Total Customer Balance' , WA_ACC-VALUE .
FORMAT COLOR OFF.
ENDAT.
ENDLOOP.
*do 50 times.
*write / sy-index.
*if sy-index = 10.
*exit.
*endif.
*enddo.
*
*do 15 times.
*if sy-index = 10.
*continue.
*endif.
*write / sy-index.
*enddo.
*
do 50 times.
check sy-index = 10.
write / sy-index.
exit.
enddo.
reward if useful