Modify internal table and do calculation in Query
My task is to create a sales order report via query to show sales order qty, delivery and billing qty. And I run into problem with getting the billing qty.
VBAK and VBAP are my main tables and I add VBFA as alias table to in order to find the billings. I create an additional field "fkimg". I can not just sum up the billing qty as there could be cancelled billing. So my intention is when vbfa-vbtyp_n = 'N' (cancelled billing), I shall take vbrp-fkimg (billing qty) as negative qty and then sum up the billing qty.
I define 3 internal tables it_vbfa, it_sum and wa_sum with same table structure, like below
DATA: BEGIN OF it_vbfa OCCURS 0,
vbeln TYPE vbeln,
posnr TYPE posnr,
fkimg TYPE fkimg,
vbtyp_n TYPE vbtyp_n,
END OF it_vbfa.
And I pull data it_vbfa and it_sum :
select vbeln posnr fkimg from vbrp into corresponding fields of table it_sum
where AUBEL = vbap-vbeln and AUPOS = vbap-posnr.
select * from vbfa into corresponding fields of table it_vbfa
where vbelv = vbak-vbeln and ( vbtyp_n = 'M' or vbtyp_n = 'N').
and I get the data into these two tables like this:
I wanted to merge them into one table and then do the calculation and sum as said above, but I do not know how to do it.
Your direction would be very much appreciated!