We can help. Together we learn....

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'
EXPORTING
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)
TABLES
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.

Benefits:

1) We do not need to hit multiple tables to get the open orders.

2) The performance is improved drastically.

10 comments:

  1. Biswa on June 22, 2011 at 10:56 PM

    Nice Blog.. Raju.. really helpful.. We might need this in our project when we do performance optimization

     
  2. Raju on June 23, 2011 at 12:03 AM

    Thanks Biswa.. :)

     
  3. Chinu on June 23, 2011 at 12:34 AM

    It's a real good one. Thanks Raju.

     
  4. Raju on June 26, 2011 at 9:57 PM

    Thanks Bhai.. glad that you all had a look at it.. [:)]

     
  5. pranshu gupta on November 23, 2012 at 12:50 PM

    i tried that but its going into dump


    data:
    t_vbmtv type table of svbmtv_trvog.

    call function 'SD_SELECT_SALES_DOCUMENTS'
    exporting
    iv_trvog = '0'
    * IV_BSTKD = IV_BSTKD
    * IV_ZPAVW = IV_ZPAVW
    iv_vboff = 'X'
    * IV_VBALL = IV_VBALL
    tables
    t_vbmtv = t_vbmtv
    * LVBMTV = LVBMTV
    * I_VKORG_RT = I_VKORG_RT
    * I_VTWEG_RT = I_VTWEG_RT
    * I_SPART_RT = I_SPART_RT
    * I_MATNR_RT = I_MATNR_RT
    * I_KUNNR1_RT = I_KUNNR1_RT
    * I_VKBUR_RT = I_VKBUR_RT
    * I_VKGRP_RT = I_VKGRP_RT
    * I_AUART_RT = I_AUART_RT
    * I_ERNAM_RT = I_ERNAM_RT
    * I_VBELN_RT = I_VBELN_RT
    * I_AUDAT_RT = I_AUDAT_RT
    * I_WERKS_RT = I_WERKS_RT
    * I_ZPERS_RT = I_ZPERS_RT
    * I_DATAB_RT = I_DATAB_RT
    * I_ERDAT_RT = I_ERDAT_RT

     
  6. pranshu gupta on November 23, 2012 at 1:02 PM

    please tell me why it is going into dump i need it urgently

     
  7. Raju on November 23, 2012 at 1:56 PM This comment has been removed by the author.  
  8. Raju on November 23, 2012 at 2:15 PM

    Hi Pranshu - I checked, there is no issue in data declaration.

    Can you please provide the details of the dump?

    Do you have huge volume of open orders in your system. In that case, the internal table may overflow. Can you please put some restriction in the FM, with date or /and order type or/and material or/and plant.

    Please let me know if this helps.

    Raju

     
  9. Ubaldo Vega on November 11, 2013 at 7:27 AM

    Hi, I tried to use it in SAP R/3 4.7 and that function does not exist... in what SAP version are you using 'SD_SELECT_SALES_DOCUMENTS'?

     
  10. Raju on November 11, 2013 at 10:14 AM

    @ Ubaldo Vega .. We are ECC 6.0..

     

Categories