Skip to Content

Archived discussions are read-only. Learn more about SAP Q&A

Modify internal table and do calculation in Query

Hi experts,

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

DATABEGIN 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:


it_sum:

vbelnposnrfkimgvbtyp_n
90007086101
90007086110
90007088101
90007088110
90007089101
90007089110


it_vbfa:

vbelnposnrfkimgvbtyp_n
9000708600M
9000708600M
9000708800N
9000708800N
9000708900M
9000708900M


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!

Susan




Former Member
Not what you were looking for? View more on this topic or Ask a question