Application Development Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 

get the remaining qty in PO

Former Member
0 Kudos

Hi experts,

I use the following code to get the remaining qty in PO:

SELECT ERFMG from MSEG into wa_qty where  EBELN = PO_NUMBER AND EBELP = PO_ITEM AND MATNR = ARTICLENO .
      QUANTITY = QUANTITY - wa_qty.
ENDSELECT.

But it's very slow.How to optimize it?

thanks.

1 ACCEPTED SOLUTION

kesavadas_thekkillath
Active Contributor

i think table MDUB will help you , it holds the cumulated values for each PO line item.

There will be two quantity fields ( just subtract it )

If you are using mseg or ekbe use movement types for quantity calculation , some entries might be reversed after posting.

4 REPLIES 4

rvinod1982
Contributor
0 Kudos

Hi,

Instead of using SELECT ENDSELECT use SELECT INTO TABLE.


TYPES: BEGIN OF TY_QTY,
             ERFMG TYPE ERFMG,
             END OF TY_QTY.

DATA : IT_QTY TYPE TABLE OF TY_QTY,
            WA_QTY TYPE TY_QTY,
            QUANTITY TYPE ERFMG.

SELECT ERFMG from MSEG into table it_qty where  EBELN = PO_NUMBER AND EBELP = PO_ITEM AND MATNR = ARTICLENO .

LOOP AT IT_QTY INTO WA_QTY.
      QUANTITY = QUANTITY - wa_qty-erfmg.
ENDLOOP.

jj
Active Contributor

You can get this value from database View:MDBS

Former Member
0 Kudos

Hi,

Use table EKBE instead of MSEG.

Select ebeln ebelp belnr buzei menge
from ekbe
where ebeln = <po_number>
and     ebelp = <po_lineitem>
and     vgabe = '1'.

Deduct the Quantity(MENGE) of previous query from Purchase order line item quantity to get balance quantity.

Regards

Vinod

kesavadas_thekkillath
Active Contributor

i think table MDUB will help you , it holds the cumulated values for each PO line item.

There will be two quantity fields ( just subtract it )

If you are using mseg or ekbe use movement types for quantity calculation , some entries might be reversed after posting.