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: 

VAPMA, VBAP, VBUP

Former Member
0 Kudos

Hi Everyone,

I'm developing a program where it get open sales order but it slowly running.

Here's my algorithm

1. use VAPMA for select S/O number by material code.

2. get S/O Items from VBAP into t_vbap

3. get open sales order from VBUP into t_vbup

4. Delete t_vbap intems that's not found in t_vbup

5. get D/O from VBFA into t_vbfa

6. LOOP AT t_vbap, each round LOOP AT t_vbfa for sum Qty. in D/O

Could you give me some advice or some FM that return me with open sales order?

Here's my code:

FORM get_open_sales_order.

DATA : back TYPE P VALUE 0 DECIMALS 3,

subtract TYPE P VALUE 0 DECIMALS 3,

do_qty LIKE vbfa-rfmng,

t_tmp_back_ord LIKE t_vbap_vbep OCCURS 0 WITH HEADER LINE.

*--> Index Table

CHECK NOT t_marc[] IS INITIAL.

SELECT * INTO TABLE t_vapma FROM vapma

FOR ALL ENTRIES IN t_marc

WHERE matnr = t_marc-matnr

AND werks = p_werks

AND ( vbeln LIKE '21%' OR " Sales Order

vbeln LIKE '25%' OR " Exchange

vbeln LIKE '26%' ).

CHECK NOT t_vapma[] IS INITIAL.

*--> Sales Document: Item Data

SELECT vbapvbeln vbapposnr vbap~matnr

vbapkwmeng vbapkbmeng vbapklmeng vbapspart

INTO TABLE t_vbap FROM vbap

FOR ALL ENTRIES IN t_vapma

WHERE

vbeln = t_vapma-vbeln AND

posnr = t_vapma-posnr AND

fixmg NE 'X'. " fixed date and qty isn't cal in v_ra

CHECK NOT t_vbap[] IS INITIAL.

  • Select Back Order only

CHECK NOT t_vbap[] IS INITIAL.

SELECT vbupvbeln vbupposnr

INTO TABLE t_vbup FROM vbup

FOR ALL ENTRIES IN t_vbap

WHERE

vbeln = t_vbap-vbeln AND

posnr = t_vbap-posnr AND

vbup~rfsta NE 'C' AND

vbup~rfgsa NE 'C' AND

vbup~lfsta NE 'C' AND

vbup~lfgsa NE 'C' AND

vbup~absta NE 'C'.

CHECK NOT t_vbup[] IS INITIAL.

  • S/O is not Back Order will be deleted

SORT t_vbap BY vbeln posnr.

SORT t_vbup BY vbeln posnr.

LOOP AT t_vbap.

READ TABLE t_vbup WITH KEY vbeln = t_vbap-vbeln

posnr = t_vbap-posnr

BINARY SEARCH.

IF sy-subrc <> 0.

DELETE t_vbap.

ENDIF.

ENDLOOP.

*-- summary qty in D/O

CHECK NOT t_vbap[] IS INITIAL.

SELECT vbfavbelv vbfaposnv vbfavbtyp_n vbfarfmng

vbfamatnr vbfavbeln vbfa~posnn

INTO TABLE t_vbfa FROM vbfa

FOR ALL ENTRIES IN t_vbap

WHERE vbfa~vbtyp_n EQ 'J' "D/O

AND vbfa~rfmng GT 0

AND vbfa~vbelv EQ t_vbap-vbeln

AND vbfa~posnv EQ t_vbap-posnr.

IF t_vbfa[] IS INITIAL.

CLEAR: t_vbap, t_vbap[].

EXIT.

ENDIF.

SORT: t_marc BY werks matnr.

LOOP AT t_vbap.

CLEAR: subtract.

READ TABLE t_marc WITH KEY matnr = t_vbap-matnr.

IF sy-subrc <> 0.

DELETE t_vbap.

CONTINUE.

ELSE.

CLEAR : t_vbfa, do_qty.

LOOP AT t_vbfa WHERE vbelv = t_vbap-vbeln

AND posnv = t_vbap-posnr.

IF t_vbfa-vbtyp_n EQ 'J'. " d/o

do_qty = do_qty + t_vbfa-rfmng.

ENDIF.

ENDLOOP.

t_oso1-spart = t_vbap-spart.

t_oso1-matnr = t_vbap-matnr.

t_oso1-back = t_oso-back.

COLLECT t_oso1.

ENDIF.

ENDLOOP.

DELETE t_oso WHERE back EQ 0.

ENDFORM.

Thanks in advance.

Regards,

Tiwa Noitawee

3 REPLIES 3

Former Member
0 Kudos

Check BAPISDORDER_GETDETAILEDLIST...

Reward points if helpful...

0 Kudos

Hi Tanuja Bollavar.

Thanks for your reply.

I have tried to use the FM but I don't understand the Importing parameters that FM needed.

Could you give me some example code?

Thank you.

Regards,

Tiwa Noitawee

Former Member
0 Kudos

Hi Tiwa,

If any FM does not solve your problem, use following tips to tune this program.

You can tune the following code as here query on the VAPMA will cause the issue at it will select all the sales orders for a material.

Here you can do following things:

1) Add sales org, Sales document type, transaction group, Distribution channel and Division on the selection screen. If possible make all of them mandatory. In the above list there can be only issue with transaction group so check with functional consultant for this.

2) If possible, report can also be run for specific Sold to Parties which will again reduce amount of data selected.

Once you add above fields, query on the VAPMA table will work faster.

3) in query on VBAP, you are selecting fields from VBAP only hence no need to use VBAP~vbeln

4) Query on VBUP, here do not use the NE operators. NE operators are always caluse of slow performance hence always avoid using them. Instead create a range like r_gbstk and add A, B to it and use the same range. Or here you can use the query as below:

  • Select Back Order only

CHECK NOT t_vbap[] IS INITIAL.

SELECT vbeln posnr ( also select all the fields in that are use for NE operation )

INTO TABLE t_vbup FROM vbup

FOR ALL ENTRIES IN t_vbap

WHERE

vbeln = t_vbap-vbeln AND

posnr = t_vbap-posnr.

And then delete from the internal table t_vbup where gbstk NE 'C'.

This will give the same result as you have now but will improve performance.

5) About VBFA query - just change the sequence of fields in the where conditions. Arrange them as per the primary key combination of VBFA table.

The above things will definitely improve the performance.

Reward if helpful.

Regards,

Shahu