‎2013 Apr 03 12:50 PM
Hi all,
First you should know I'm not a real ABAP programmer, but I'm trying to use some coding in order to improve the possibilities of using infosets for queries.
I need to make a report that contains information of stocks. When there is a one to many relation from table MBEW to table EBEW, the stockamount in EBEW gets summed in a COLLECT statement and then totaled with the amount (if available) of MBEW.
My problem is that inserting CLEAR instructions doesn't give the right result.
If the amount of MBEW-LKBUM is 0 and the amount of EBEW-LBKUM is > 0, the field TOTGEN contains the right amount, but if the next article has an amount in MBEW-LBKUM and EBEW-LBKUM is 0, the field TOTGEN keeps the last amount that in EBEW-LBKUM from the former article.
When I run a test, I can see that sy-tabix has value 5 in both lines.
Question is, how to get the right result, where sy-tabix does not contain its value and the field X_EBEW-LKBUM gets CLEAR.
I have tried CLEAR statements on various lines of the code, but it has no or the wrong effect.
The code I use is:
DATA: BEGIN OF x_ebew,
matnr TYPE ebew-matnr,
lbkum TYPE ebew-lbkum,
END OF x_ebew.
DATA: it_ebew LIKE SORTED TABLE OF x_ebew WITH HEADER LINE
WITH NON-UNIQUE KEY matnr.
SELECT matnr lbkum FROM ebew
INTO x_ebew
WHERE matnr = mbew-matnr
AND lbkum > 0.
COLLECT x_ebew INTO it_ebew.
ENDSELECT.
LOOP AT it_ebew INTO x_ebew.
TOTGEN = x_ebew-lbkum + mbew-lbkum.
ENDLOOP.
WRITE: / sy-subrc, SY-TABIX, TOTGEN, 'niet geleegd?' , it_ebew-lbkum , x_ebew-lbkum , mbew-lbkum .
In basis it works fine, untill the loop gets to the point where mbew-lbkum > 0 and x_ebew-lbkum = 0, and in the former line mbew-lbkum was 0 and x_ebew-lbkum > 0.
In that case the former and the last line have sy-tabix 5 and the amount in x_ebew-lbkum from the former line does not get cleared; it is taken in to the sum of every line that folllows.
I have tried CLEAR instructions in various places of my coding, but the result is not good as you can see in the image below.
Does anyone has any suggestion on how to get the right totals in TOTGEN?
I really appreciate any help!!! ;-D
Thanks in advance,
Joke
‎2013 Apr 03 1:20 PM
Hi,
just try like this.
* first get all the matnr
select matnr from mbew into table lt_mbew where ibkum gt 0.
if lt_mbew is not initial.
select matnr ibkum from ebew into table lt_ebew
for all entries in lt_mbew
where matnr = lt_mbew-matnr.
endif.
* now use the control break statements inside the loop
loop at lt_ebew into ls_ebew.
at end of matnr " use the required condition
sum.
" send it to another internal table
endat.
endloop.
Hope this works for you.
Regards,
Ramesh.
‎2013 Apr 03 1:39 PM
Hi Ramesh,
Thanks for your reaction.
However, looking at your example code it looks like the report will only show articles where the field mbew-lbkum is GT 0, and will not contain articles where mbew-lbkum EQ 0 but ebew-lbkum is GT 0.
I need a total of both fields captured in one line in the report, hence the COLLECT statement.
Does the sample code provide in this?
Regards,
Joke
‎2013 Apr 03 4:13 PM
Hi ,
Please use the below code and I hope it will solve your issue ,
data : v_matnr type ebew-matnr ,
v_lbkum type ebew-lbkum .
*-- Fetching the Data
refresh it_mbew[] .
Select matnr lbkum from mbew into table it_mbew where lkbum = 0 .
if not it_mbew[] is initial .
refresh it_ebew[] .
select matnr lbkum from ebew into table it_ebew
for all entries in it_ebew
where matnr = mbew-matnr
and lbkum gt 0 .
endif .
*-- Displaying the data
sort it_ebew[] by mtanr .
sort it_mbew[] by mtanr .
clear ebew .
loop at it_ebew .
v_matnr = it_ebew-matnr .
v_lbkum = v_lbkum + it_ebew-lbkum .
at end of matnr .
clear it_mbew .
read table it_mbew into mbew with key matnr = v_matnr .
TOTGEN = v_lbkum + it_mbew-lbkum.
WRITE: / sy-subrc, SY-TABIX, TOTGEN, 'niet geleegd?' , v_lbkum .
clear : v_lbkum , v_matnr.
endat .
clear it_ebew .
endloop .
Thanks
Mallikarjun