2008 Nov 17 1:29 PM
Hi, Gurus
2008 Nov 17 1:30 PM
2008 Nov 17 1:30 PM
2008 Nov 17 1:34 PM
hi
issue is incomplete
at ... endat is operation on internal table event which gets triggered at en of a pertiular pattern
shiva
2008 Nov 17 1:55 PM
Hi, Gurus.
I have been trying to display the total number of units for each counter in my (sorted) internal table, it, using the above statement. My syntax doesn't seem to do the trick. For instance if the internal table with fields X,Y,Z contains:
X Y Z
1 A 100
2 A 200
3 B 100
4 C 50
5 C 65
I want it to display
A 300
B 100
C 115
Here, column Y is the counter and Z is the number of units. They are both not part of the key.
My code is as follows:
sort it ascending by counter.
loop at it.
at first.
write 'List of counters against number of units'.
endat.
at new counter.
clear total.
endat.
at end of counter.
add it-units to total.
write sy-uline.
write:/ it-counter, 20 total.
endat.
at last.
sum.
write: 'Total number of units for all counters:', it-units.
endat.
endloop.
2008 Nov 17 1:57 PM
Hi
Use Collect Statement
Example:
DATA: BEGIN OF seats,
carrid TYPE sflight-carrid,
connid TYPE sflight-connid,
seatsocc TYPE sflight-seatsocc,
END OF seats.
DATA seats_tab LIKE HASHED TABLE OF seats
WITH UNIQUE KEY carrid connid.
SELECT carrid connid seatsocc
FROM sflight
INTO seats.
COLLECT seats INTO seats_tab.
ENDSELECT.
The collect statement will do the addition for numeric fields
Thanks & Regards
Srinivasu
Edited by: srinivasu bv on Nov 17, 2008 2:57 PM
2008 Nov 17 1:58 PM
You can do the same in this way also.
**-- Taking the condition that we only want to display the Materials in there latest stage.
**-- For the same we will compare the internal Table with there Material Number (what ever you say)
**-- and there stage number and delete the others.
**-- Before this Loop the Internal Table should be sorted in such a manner that Material
**-- and Stage Should be as below example.
Material Number Stage ---> Header Information.
000000000001 1
000000000001 2
000000000001 3
000000000012 1
000000000012 2
Loop at the Internal Table which has all the data that needs to be displayed.
loop at itab into wa.
Below Condition will work only once.
if wa2 is initial.
wa2 = wa.
endif.
if ( wa-material_number = wa2-material_number ) and ( wa-stage <> wa2-stage ).
In loop if the Material Number is same and stage is different than store the new
Information into the work area.
wa2 = wa.
else.
If new Material Number comes in Loop then our second work area will contain the
Details regarding the last stage of the Previous Material and that is what was needed.
Get the same information into Internal Table which is our Final Internal Table
and this needs to go to the Report Output.
append wa2 to itab2.
clear wa2.
wa2 = wa.
endif.
endloop.
Above is just a example. Just try to implement the same in your code.
Thanks
Jayant
2008 Nov 17 1:59 PM
coloumn Y has to be the first field of your internal table, otherwise hand it has no chance to work. On the other hand it would be simplier to code like this:
LOOP AT itab.
AT END of Y.
SUM. "Now you have summarized data in the work area based on Y
ENDAT.
ENDLOOP.
2008 Nov 17 2:04 PM
try this:
loop at itab into wa.
at end of y.
flag = 'X'.
endat.
if flag = 'X'
collect wa into itab1. "itab1 should have same structure as itab.
clear: wa, flag.
endif.
endloop.
regards,
padma
2008 Nov 17 2:23 PM
2008 Nov 18 5:37 PM
Hi, Gurus,
I am glad to say I have learnt quite a lot from all your contributions. Your Assistance is greatly appreciated. The solution I found has to do with making the field in question be the first field in the internal table so that the AT...ENDAT statements can work.