09-17-2008 7:22 AM
Hi All,
I need to use something like this appearing below ....but SUM is not allowed with FOR ALL ENTRIES ......Whats the efficient ALTERNATIVE ???
SELECT sum( menge ) INTO TABLE imseg
FROM mseg
FOR ALL ENTRIES IN iresb
WHERE matnr = iresb-matnr
AND bwart = '281'
AND aufpl = iresb-aufpl
AND aplzl = iresb-aplzl.
Any help will be rewarded & appreciated ...
Regards
Jaman
09-17-2008 7:56 AM
Hi,
First Fetch the records into a internal table and then Loop into it and sum inside the loop into a variable.
Regards
Karthik D
09-17-2008 7:56 AM
Hi,
First Fetch the records into a internal table and then Loop into it and sum inside the loop into a variable.
Regards
Karthik D
09-17-2008 10:36 AM
Hi Karthik,
Thanx a ton....
How about the below approach .....its allowed & working fine ....also simplifying my work..
SELECT matnr menge rsnum rspos
INTO (ws-matnr, ws-menge, ws-rsnum, ws-rspos)
FROM mseg
FOR ALL ENTRIES IN iresb
WHERE matnr = iresb-matnr
AND bwart = mvtyp1
AND rsnum = iresb-rsnum
AND rspos = iresb-rspos.
imseg2-matnr = ws-matnr.
imseg2-menge = ws-menge.
imseg2-rsnum = ws-rsnum.
imseg2-rspos = ws-rspos.
COLLECT imseg2.
ENDSELECT.
09-17-2008 10:36 AM
10-17-2008 11:25 AM
You can define RANGES :
ranges : r_blnr for mkpf-mblnr.
loop at lt_blnr.
r_blnr-sign = 'I'.
r_blnr-option = 'EQ'.
r_blnr-low = lt_blnr-mblnr.
append r_blnr.
endloop.
select sum( menge ) into top_menge from mseg
where mblnr in r_blnr.
03-25-2022 7:44 AM
SUM inside the loop will slow your program because when you have thousands off entry then in loop your sum query will hit database thousands time...
So best approach is define select ranges and put your document number on that internal table and pass it on where with (IN) clause in your select sum query and get your result in your sum internal table and in loop-endloop you can use read statement for sum internal table.