Many times, we need to extract all open sales orders (or quotations/inquiries etc) till date for some particular material and plant combination in the system and do some manipulation and show some report. Since we have material and plant in hand, so as suggested by SAP notes we go to table VAPMA (Sales Index: Order Items by Material) to get the orders and then we hit VBUK (Sales Document: Header Status and Administrative Data) table or VBAKUK (Sales Document Header and Status Data) view and then to VBUP and VBAP to get the open orders (i.e. those orders whose status is not complete).
Usually in actual production box, the order line item table has millions of records and if we try to hit this table VAPMA without all the keys (with just Material and Plant), it will severely hit the performance of the program.
SD_SELECT_SALES_DOCUMENTS is a standard SAP function module to list all orders/quotations/inquiries etc. It returns all type of orders. Standard SAP transactions VA05N / VA15N / VA25N / VA35N / VA45N uses this FM to show the list of Sales Orders / Inquiries / Quotations / Schedule Agreements / Contracts respectively.
Instead of hitting the tables VAPMA –> VBUK/VBAKUK –> VBUP and then VBAP, using SAP standard function module SD_SELECT_SALES_DOCUMENTS is the better alternative.
Using this FM, in our current project, we improved the performance of one of our interface from 36 hours total run time to just 450 second in the Quality system which had over 68 million sales order line items in VBAP table.
This FM can be used for Orders, Inquiries, Quotations, Contract etc.
CALL FUNCTION ‘SD_SELECT_SALES_DOCUMENTS’
iv_trvog = ‘0’ (0/1/2/3/4 for orders/inquiry/quotation/sch agreement/contract)
iv_vboff = ‘X’ (X for Open Orders, for all Orders send IV_VBOFF blank)
t_vbmtv = i_final_orders (This table returns the Orders)
i_vkorg_rt = i_vkorg
i_auart_rt = r_orders_type
i_matnr_rt = s_matnr
i_werks_rt = s_werks.
1) We do not need to hit multiple tables to get the open orders.
2) The performance is improved drastically.Benefits:
Upadate: The usage of the above FM makes ABAPer’s life easier. But, FM also has lots of selects internally (which are performance intensive), which can be avoided by creating a wrapper FM or writing some optimized selects. This would have positive impact in the performance.
Of late, I have stopped using this FM and starting building my own code by leveraging the logic provided in the FM. Using the FM alone was not performance effective in long run.
If you liked this post, you might want to check our other post on ABAP Programming good practice.
If you want to get updates about our new tweaks and tricks, please subscribe. We respect your privacy and take protecting it seriously.
If you liked it, please share it. Thank you very much for your time!!
Image source : www.aspgw.com