11-15-2007 3:52 PM
Hello,
I want to loop over a table and make sums per arbpl:
TYPES: BEGIN OF hd_auf,
aufnr TYPE afko-aufnr,
matnr TYPE afko-plnbez,
eckd TYPE afko-gltrp,
arbpl TYPE crhd-arbpl,
rmenge TYPE zzppauftrag-gutmenge,
rzeit TYPE zzppauftrag-ruestzeit,
ist TYPE zzppauftrag-istgeschw,
END OF hd_auf.
TYPES: auftragsinfo TYPE TABLE OF hd_auf.
DATA: auf_header TYPE hd_auf.
DATA: auf TYPE auftragsinfo.
... put data into table auf ...
SORT auf BY arbpl ASCENDING eckd ASCENDING.
LOOP AT auf INTO auf_header.
WRITE:/01 auf_header-arbpl, auf_header-aufnr, auf_header-matnr,
auf_header-eckd, auf_header-rmenge, auf_header-ist,
auf_header-rzeit, status.
AT END OF arbpl.
SUM.
WRITE: /01 auf_header-rzeit.
ENDAT.
ENDLOOP.
This does not work. I will always get one sum per line, regardless how much equal lines with the same arbpl are in the table auf.
This is the output (the line with the number is the sum-line):
D-OFF 1000840 110220-1
0,013
D-OFF 1000740 211220-1
16,667
THM-U001 1000642 250220-17373G
0,028
THM-U001 1000660 250220-10021S
0,167
UMM. 001 1000640 250220-17373G
0,111
UMM. 001 1000641 250220-17373G
0,056
UMM. 001 1000629 250220-17373G
0,111
UMM. 001 1000780 211220-10101
0,167
UMM. 001 1000741 211220-10101
0,139
But I need the following output:
D-OFF 1000840 110220-1
D-OFF 1000740 211220-1
16,68
THM-U001 1000642 250220-17373G
THM-U001 1000660 250220-10021S
0,195
UMM. 001 1000640 250220-17373G
UMM. 001 1000641 250220-17373G
UMM. 001 1000629 250220-17373G
UMM. 001 1000780 211220-10101
UMM. 001 1000741 211220-10101
0,584
What is wrong with my loop?
Could anyone please help me?
Thanks.
Regards,
Oliver
11-15-2007 4:03 PM
hi Oliver,
AT END OF works like that each single field are taken into account which are before <i>arbpl</i>. So in your case aufnr, matnr, eckd and arbpl are concatenated by the system and SAP sees as one string and carries out the AT END OF statement accordingly.
You have to define your internal table so, that arbpl is the first field in the table, than it works properly.
hope this helps
ec
11-15-2007 4:01 PM
Hi Oliver,
first Sort itab by aufnr and arbpl and then do sum at end of arbpl.
or keep arbpl in the first place of itab
Reward if it helps,
Satish
Message was edited by:
Satish Panakala
11-15-2007 4:03 PM
hi Oliver,
AT END OF works like that each single field are taken into account which are before <i>arbpl</i>. So in your case aufnr, matnr, eckd and arbpl are concatenated by the system and SAP sees as one string and carries out the AT END OF statement accordingly.
You have to define your internal table so, that arbpl is the first field in the table, than it works properly.
hope this helps
ec
11-15-2007 4:04 PM
Hi
U should consider this:
TYPES: BEGIN OF hd_auf,
aufnr TYPE afko-aufnr,
matnr TYPE afko-plnbez,
eckd TYPE afko-gltrp,
arbpl TYPE crhd-arbpl,
.................................................
LOOP AT auf INTO auf_header.
...........................................
AT END OF arbpl.
in this situation the event is triggered as soon as a value at the left of ARBPL is changing.
If you want be sure the event triggered in right way your table should have ARBPL as first field:
TYPES: BEGIN OF hd_auf,
arbpl TYPE crhd-arbpl,
aufnr TYPE afko-aufnr,
matnr TYPE afko-plnbez,
eckd TYPE afko-gltrp,
...................................
Max
11-15-2007 4:05 PM
HI,
when you use AT new or AT END events, it works when change all the fields before the field you indicate. So at the change of:
aufnr matnr eckd arbpl
.
rgs
11-15-2007 4:06 PM
Hi,
Please try this ... perhaps it may help.
...
SORT auf STABLE BY arbpl ASCENDING eckd ASCENDING.
...
Regards,
Ferry Lianto
11-15-2007 4:13 PM
Hi,
LOOP AT auf INTO auf_header.
WRITE:/01 auf_header-arbpl, auf_header-aufnr, auf_header-matnr,
auf_header-eckd, auf_header-rmenge, auf_header-ist,
auf_header-rzeit, status.
AT END OF aufnr.
SUM.
WRITE: /01 auf_header-rzeit.
ENDAT.
ENDLOOP.
Try this,
KC
11-15-2007 4:28 PM
Guys, you are great.
I have moved the field arbpl to the first field of the
table, and now it works.
Thank you very much for the quick help !