(原創)BAPI 修改銷售訂單的方法 ‘BAPI_SALESORDER_CHANGE’

SAP騎士發表於2009-08-21
sap 標準程式中可以使用VA02來修改銷售訂單 change sales order,也可以在程式中呼叫BAPI來更改訂單(如物料編號material,訂購數量 order quantity等),用到的函式是 BAPI_SALESORDER_CHANGE.
sap bapi Explorer中的文件。



Method

SalesOrder.ChangeFromData

Change Sales Order

Functionality

You can use this method to change or delete sales orders.

You can change header, item, schedule line and configuration data.

In general, note that you should:

  • Only specify fields that should be changed
  • Select these fields by entering an X in the checkboxes
  • Enter a U in the UPDATEFLAG field
  • Always specify key fields when changing the data, including in the checkboxes
  • The configuration is an exception here. If this needs to be changed, you need to complete it again fully.
  • Maintain quantities and dates in the schedule line data
  • 修改訂單數量要用schedule_lines 這個引數
  • Possible UPDATEFLAGS:
  • U = change  flg值的三種不同意義
  • D = delete
  • I = add
  • Example

    1. Delete the whole order
    2. Delete order items
    3. Change the order
    4. Change the configuration

    Notes

    1. Minimum entry:

    You must enter the order number in the SALESDOCUMENT structure.
    You must always enter key fields for changes.
    You must always specify the update indicator in the ORDER_HEADER_INX.

    1. Commit control:

    The BAPI does not run a database Commit, which means that the application must trigger the Commit so that the changes are read to the database. To do this, use the BAPI_TRANSACTION_COMMIT BAPI.使用完了bapi記得要用commit提交

  •  

  • *****************************************************************************
    貼一段程式幫助編寫bapi
    * BAPI Logic for sales order creation
    *---------------------------------------------------------------
    * Header data
      PERFORM FILL_ORDER_HEADER_CHANGE  USING  ORDER_HEADER_IN
                                               ORDER_HEADER_INX
                                               LS_SORDER.

    * Partner
      PERFORM FILL_PARTNER_CHANGE       TABLES PARTNERCHANGES
                                               PT_ITEMS
                                        USING  LS_SORDER.

    * Items
      PERFORM FILL_ORDER_ITEM_CHANGE    TABLES ORDER_ITEMS_IN
                                               ORDER_ITEMS_INX
                                               PT_ITEMS.

    * Price condition
      IF PS_SORDER-MIG_FLG  = ' '.
      PERFORM FILL_CONDITIONS_CHANGE    TABLES CONDITIONS_IN
                                               CONDITIONS_INX
                                               PT_ITEMS
                                        USING  LS_SORDER.
      ELSE.
        CONDITIONS_IN[]  = PT_CONDTION[].
        CONDITIONS_INX[] = PT_CONDTIONX[].
      ENDIF.


      CALL FUNCTION 'BAPI_SALESORDER_CHANGE'
        EXPORTING
          SALESDOCUMENT    = LS_SORDER-VBELN
          ORDER_HEADER_IN  = ORDER_HEADER_IN     (抬頭資料)
          ORDER_HEADER_INX = ORDER_HEADER_INX
        TABLES
          RETURN           = PT_RETURN
          ORDER_ITEM_IN    = ORDER_ITEMS_IN
          ORDER_ITEM_INX   = ORDER_ITEMS_INX
          CONDITIONS_IN    = CONDITIONS_IN
          CONDITIONS_INX   = CONDITIONS_INX
          PARTNERCHANGES   = PARTNERCHANGES.   


      READ TABLE PT_RETURN WITH KEY TYPE    = 'S'
                                    ID      = 'V1'
                                    NUMBER  = '311'.


      IF SY-SUBRC EQ 0.
        CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
          EXPORTING
            WAIT = 'X'.
      ELSE.
        CALL FUNCTION 'BAPI_TRANSACTION_ROLLBACK'.
      ENDIF.

    **************************************************************

    更改訂單文字資訊的bapi

    lt_order_header_inx-updateflag = 'U'.
            APPEND lt_order_header_inx.

            CONDENSE gt_out-headtext.
            lt_order_text-doc_number = lt_salesdocument.
            lt_order_text-text_id = 'Z002'.
            lt_order_text-langu = 1.
            lt_order_text-text_line = gt_out-headtext.
            APPEND lt_order_text.

            CALL FUNCTION 'BAPI_SALESORDER_CHANGE'
              EXPORTING
                salesdocument    = lt_salesdocument
                order_header_inx = lt_order_header_inx
              TABLES
                return           = lt_return
                order_text       = lt_order_text.

            CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
              EXPORTING
                wait = 'X'.
    *****************************************************************************

    tcode對應的bapi

    Here is a list of the BAPIs which can be used instead of BDC for a transaction.

    Transaction  BAPI 
    MM01  BAPI_MATERIAL_SAVEDATA 
    MM02  BAPI_MATERIAL_SAVEDATA 
    VA01  BAPI_SALESORDER_CREATEFROMDAT2 
    VA02  BAPI_SALESORDER_CHANGE 
    ME21/ME21n  BAPI_PO_CREATE1 
    ME22/ME22n  BAPI_PO_CHANGE 
    ME51  BAPI_REQUISITION_CREATE 
    AS01  BAPI_FIXEDASSET_CREATE1 
    AS02  BAPI_FIXEDASSET_CHANGE 

     

     

     

    Transaction BAPI
    MM01 BAPI_MATERIAL_SAVEDATA
    MM02 BAPI_MATERIAL_SAVEDATA
    VA01 BAPI_SALESORDER_CREATEFROMDAT2
    VA02 BAPI_SALESORDER_CHANGE
    ME21/ME21n BAPI_PO_CREATE1
    ME22/ME22n BAPI_PO_CHANGE
    ME51 BAPI_REQUISITION_CREATE
    AS01 BAPI_FIXEDASSET_CREATE1
    AS02 BAPI_FIXEDASSET_CHANGE

    來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/17204926/viewspace-612853/,如需轉載,請註明出處,否則將追究法律責任。

    相關文章