Skip to Content
-3

My client has a requirement he wants to create a sales order in VA01

My client has a requirement he wants to create a sales order in VA01 and he wants its data to be copied to another sales order in which the sales document number should be incremented by 1 and customer reference number should be saved with an _ in the second order before saving the data. I am stuck at USEREXIT_SAVE_DOCUMENT_PREPARE . please guide

Add comment
10|10000 characters needed characters exceeded

  • Curious to know what could be the Objective for this sort of set up.

    Both these SOs and their corresponding Material,Delivery and Financial Documents will also be accounted to the same GL ?

    K.Kiran.

  • Get RSS Feed

4 Answers

  • Oct 10, 2017 at 09:41 PM

    What business process would this support and what value would this add to the business? What is the significance of this operation? Was this evaluated by a qualified SD consultant?

    Sorry but such requirement for custom ABAP development sounds rather capricious. As correctly pointed out, with the internal number range assignment it's impossible to guarantee exactly +1 number anyway. And I don't get why would anyone possibly need a duplicate order (some severely misunderstood intercompany scenario?). If someone can explain the actual business requirement (other than "he wants") then we might be able to propose a more adequate solution.

    Add comment
    10|10000 characters needed characters exceeded

  • Oct 14, 2017 at 02:36 AM

    Agree with Jelena Perfiljeva here. Expecting people to respond to this without a full explanation of the requirements is just plan lazy. Detail the full business process and scenarios, then we can help with more information.

    This is my motto at the moment - Just because you can possibly do something with code doesn't mean you should. It is our job as Senior SAP Consultants to guide and educate clients into making right decisions taking into account future flexibility, future support and maintenance. This would be a nightmare to support. Like Gerrit Beukema states getting the next number would be like winning the Lottery - you probably have more chance winning that than getting the next number in that range.

    So, if the client still does not get the message (and wants to proceed) the best way to do these sorts of things is through output as it creates a separate process (outside the current Sales order create step you are currently in). This will work. If you need a similar number then I would say you need to create the order with an External number Range however you won't know the number until AFTER you've created the first one!

    Add comment
    10|10000 characters needed characters exceeded

    • "This is my motto at the moment - Just because you can possibly do something with code doesn't mean you should. It is our job as Senior SAP Consultants to guide and educate clients into making right decisions taking into account future flexibility, future support and maintenance. This would be a nightmare to support."

      I bow down to Phil for those lines.Fully agree with you.

      K.Kiran.

  • Oct 05, 2017 at 11:33 PM

    With the way number ranges work, this seems to be an impossible requirement. Or at least really tricky to implement.

    Also, it would be better to create the second order in USEREXIT_SAVE_DOCUMENT using BAPI_SALESORDER_CREATEFROMDAT1 or BAPI_SALESORDER_CREATEFROMDAT2. Be careful to be able to distinguish the original and the copy order creation, if you mess up there you'd have an endless loop.

    Add comment
    10|10000 characters needed characters exceeded

    • Be careful to be able to distinguish the original and the copy order creation, if you mess up there you'd have an endless loop.

      To elaborate on that. You need to be able to know when you enter the user exit if it's a call that happened because of the call to the BAPI to create the subsequent order, otherwise you will create a subsequent order for the subsequent order, ad infinitum.

      You can do this is a number of ways:

      1. Use EXPORT TO and IMPORT FROM MEMORY;
      2. Set a static attribute on a class;
      3. Set a static attribute in the user exit;
      4. Pass a specific value to the BAPI;
      5. Check the call stack using FM SYSTEM_CALLSTACK;

      Note that whatever method you choose you will need test it all works when the user creates two orders in succession without leaving the transaction.

      I hope this gives you an idea how to stop the endless loop from happening.

  • Oct 10, 2017 at 01:25 PM
    -3
    IF sy-UNAME EQ 'myusernaME' AND T180-TRTYP EQ 'H'.
    data: lcount type vbeln,
          header type bapisdhD1,
          headerx type bapisdhD1x,
          return type table of bapiret2,
          it_order type table of bapisditm,
          it_orderx type table of bapisditmx,
          it_partner type table of bapiparnr,
          is_order type bapisditm,
          is_orderx type bapisditmx,
          is_partner type bapiparnr,
          item type matnr.
    
    header-doc_type = vbak-auart.            "Header for Bapi
    header-sales_org = vbak-vkorg.           "Header for Bapi
    header-distr_chan = vbak-vtweg.          "Header for Bapi
    header-sales_off = vbak-vkbur.           "Header for Bapi
    header-sales_grp = vbak-vkgrp.          "Header for Bapi
    header-division = vbak-spart.
    
                                     "Header for Bapi
    
    headerx-doc_type = 'X'.            "Header for Bapi
    headerx-sales_org = 'X'.           "Header for Bapi
    headerx-distr_chan = 'X'.          "Header for Bapi
    headerx-sales_off = 'X'.           "Header for Bapi
    headerx-sales_grp = 'X'.          "Header for Bapi
    headerx-division = 'X'.            "Header for Bapi
    
    
    
    *partner data ship-tp-party , sold-to-party
    is_partner-partn_role = 'AG'.
    is_partner-partn_numb = KUAGV-KUNNR.
    Append is_partner to it_partner.
    is_partner-partn_role = 'WE'.
    is_partner-partn_numb = KUWEV-KUNNR.
    append is_partner to it_partner.
    * order table to pass to bapi.
    
    
    
    IS_ORDER-ITM_NUMBER = VBAP-POSNR.
    IS_ORDER-MATERIAL = VBAP-MATNR.
    IS_ORDER-TARGET_QTY = VBAP-ZMENG.
    IS_ORDER-TARGET_QU = VBAP-ZIEME.
    IS_ORDER-PURCH_NO_C = VBKD-BSTKD.
    IS_ORDER-PURCH_DATE = VBKD-BSTDK.
    APPEND IS_ORDER TO IT_ORDER.
    
    IS_ORDERX-ITM_NUMBER = 'X'.
    IS_ORDERX-MATERIAL = 'X'.
    IS_ORDERX-TARGET_QTY = 'X'.
    IS_ORDERX-TARGET_QU = 'X'.
    IS_ORDERX-PURCH_NO_C = 'X'.
    IS_ORDERX-PURCH_DATE = 'X'.
    APPEND IS_ORDERX TO IT_ORDERX.
    
    
    
    CALL FUNCTION 'BAPI_SALESORDER_CREATEFROMDAT2'
      EXPORTing
    *   SALESDOCUMENTIN               =
       order_header_in               = HEADER
       ORDER_HEADER_INX              = HEADERX
    *   SENDER                        =
    *   BINARY_RELATIONSHIPTYPE       =
    *   INT_NUMBER_ASSIGNMENT         =
    *   BEHAVE_WHEN_ERROR             =
    *   LOGIC_SWITCH                  =
    *   TESTRUN                       =
    *   CONVERT                       = ' '
    * IMPORTING
    *   SALESDOCUMENT                 = lcount
      tables
       RETURN                        = return
       ORDER_ITEMS_IN                = IT_order
       ORDER_ITEMS_INX               = IT_ORDERX
       order_partners                = IT_partner
    *   ORDER_SCHEDULES_IN            =
    *   ORDER_SCHEDULES_INX           =
    *   ORDER_CONDITIONS_IN           =
    *   ORDER_CONDITIONS_INX          =
    *   ORDER_CFGS_REF                =
    *   ORDER_CFGS_INST               =
    *   ORDER_CFGS_PART_OF            =
    *   ORDER_CFGS_VALUE              =
    *   ORDER_CFGS_BLOB               =
    *   ORDER_CFGS_VK                 =
    *   ORDER_CFGS_REFINST            =
    *   ORDER_CCARD                   =
    *   ORDER_TEXT                    =
    *   ORDER_KEYS                    =
    *   EXTENSIONIN                   =
    *   PARTNERADDRESSES              =
    *   EXTENSIONEX                   =
    *   NFMETALLITMS                  =
    .
    endif.
    
    
    Add comment
    10|10000 characters needed characters exceeded