‎2010 Jan 19 3:34 AM
Hi all,
Thanks for spending the time reading my thread.
I need to do a data comparison in an internal table, comparing the 1st row to the 2nd row, 2nd row to the 3rd subsequently.
This is the code i have came out.
**
SORT ITAB ASCENDING BY ebeln ASCENDING.
loop at itab.
At first.
move itab-grmenge to total.
move-corresponding itab to gtab.
continue.
endat.
if gtab-ebeln = itab-ebeln and gtab-ebelp = itab-ebelp.
total = itab-grmenge + total.
move-corresponding itab to gtab.
else.
move total to gtab-grmenge.
append gtab.
clear total.
move itab-grmenge to total.
move-corresponding itab to gtab.
endif.
endloop.
**
I encounter a problem at the "at first" command.
When i test the code in steps, i noticed when it reached "at first", the itab becomes a wild card.
My intention is to copy the 1st row of data to my 2nd table(gtab),
go back the loop and compare the 1st row of data in 2nd table(gtab) with the 2nd row of data in 1st table(itab).
Please advise me how should i approach it, thanks alot.
‎2010 Jan 19 3:45 AM
YOU have a SY-TABIX system variable by which you will get the the current index of itab in a loop you can catch it and then use
READ STATMENT WITH INDEX SY-TABIX + 1 , SY-TABIX +2 SO ON and so...on
Edited by: Anup Deshmukh on Jan 19, 2010 4:45 AM
‎2010 Jan 19 3:45 AM
YOU have a SY-TABIX system variable by which you will get the the current index of itab in a loop you can catch it and then use
READ STATMENT WITH INDEX SY-TABIX + 1 , SY-TABIX +2 SO ON and so...on
Edited by: Anup Deshmukh on Jan 19, 2010 4:45 AM
‎2010 Jan 19 3:49 AM
Hi,
With your logic, just check if a particular EBELN has more than one EBELP values, how does it work. By your logic the total of the first record will be added alway, is that you wanted.
Regarding the wildcard values, you can just simply move the workarea to another work area after LOOP statement.
LOOP AT itab.
wa_itab = itab. " wa_itab is same as itab.
.
.
.
.
ENDLOOP
Regards
Bala Krishna
‎2010 Jan 19 3:58 AM
Hello,
Control break events (At First,At Last,At New, At End of) are events where if you call a field inside these events, the value is replaced by '*' for all fields which are on the right of the field on which the event is triggered.
Before entering the AT .... ENDAT assign the contents of itab into a temporary variable and assign the value of that temporary variable to the new internal table gtab. Also the value of grmenge is to be assigned to a variable and then you can use it to add to total.
For example if wa is a variable with a structure similar to itab and temp is a variable of type grmenge then before AT First
move itab-grmenge to temp
move itab to wa.
Now inside the AT....ENDAT
replace the itab-grmenge with temp and itab with wa. wa contains the actual vaues which will be passed to gtab rather than '*'.
Hope this helps in solvibg your issue.
Reagrds,
Sachin
‎2010 Jan 19 4:04 AM
Hi Anup, Bala and Sachin,
Thanks for the swift replies.
Let me try on the methods to see if it works out.
Edited by: calibertto on Jan 19, 2010 5:05 AM
Edited by: calibertto on Jan 19, 2010 5:05 AM
‎2010 Jan 21 2:33 AM
I've managed to solve the problem by adding the "read table index sy-tabix" in the AT statement.
Thank you for all your help.