I am working on a report...where I need to get the document number from table BKPF and then I need to get the line item data from table BSEG such as Net amount, then I need to sum up the net amount of one header and need to display it. ...
My scenario is like this:
doc # itemNet amount
123 1 10
123 2 9
123 3 11
124 1 13
So the output should be:
doc # Net amount
123 30
124 13
and for this I have written the following code:
&----
*& Report ZFI_PAYMENT *
*& *
&----
*& *
*& *
&----
REPORT ZFI_PAYMENT .
data : v_nebtr(15).
data: begin of it_bkpf occurs 0,
belnr like bkpf-belnr,
end of it_bkpf.
data: begin of it_bseg occurs 0,
belnr like bseg-belnr,
nebtr like bseg-nebtr,
end of it_bseg.
data : begin of it_fin occurs 0,
belnr like bseg-belnr,
nebtr like bseg-nebtr,
end of it_fin.
select belnr into table it_bkpf
from bkpf
where blart eq 'SA'.
select belnr nebtr into table it_bseg
from bseg.
loop at it_bkpf.
read table it_bseg with key belnr = it_bkpf-belnr.
if sy-subrc eq 0.
ADD it_bseg-nebtr to v_nebtr.
else.
move it_bseg-nebtr to it_fin-nebtr.
move it_bseg-belnr to it_fin-belnr.
append it_fin.
clear it_fin.
endif.
it_bseg-nebtr = v_nebtr.
endloop.
loop at it_fin.
write: /1 it_fin-nebtr,
/20 it_fin-belnr.
endloop.
But I think I am doing some part wrong ..as I am not getting the desired result and my iternal table it_fin is not returning anything,so can please tell where I am doing it wrong.
Thanks,
Rajeev !!!