bapi BAPI_OUTB_DELIVERY_CHANGE 修改交货单中的序列号

 *&---------------------------------------------------------------------*
*& Report  ZTEST_DN_UPDATE_SERIAL_NO
*&
*&---------------------------------------------------------------------*
*&
*&
*&---------------------------------------------------------------------*

REPORT  ZTEST_DN_UPDATE_SERIAL_NO.
DATA: dn_header_data      LIKE bapiobdlvhdrchg,
      dn_header_control   LIKE bapiobdlvhdrctrlchg,
      dn_delivery         LIKE likp-vbeln,
      dn_return           LIKE bapiret2 OCCURS 0 WITH HEADER LINE,
      dn_item_data        LIKE TABLE OF bapiobdlvitemchg WITH HEADER LINE,
      dn_item_control     LIKE bapiobdlvitemctrlchg OCCURS 0 WITH HEADER LINE,
      dn_item_serial_no   LIKE TABLE OF bapidlvitmserno WITH HEADER LINE,
      dn_techn_control    LIKE BAPIDLVCONTROL."add by changgf 20110219
DATA: g_transaction_id LIKE arfctid,
      g_status_of_transaction(15).

START-OF-SELECTION.

*  CALL FUNCTION 'TRANSACTION_BEGIN'
*    IMPORTING
*      transaction_id = g_transaction_id.

  dn_header_data-deliv_numb = '0500029959'.
  dn_header_control-deliv_numb = '0500029959'.

  dn_item_serial_no-deliv_numb = '0500029959'.
  dn_item_serial_no-itm_number = '000010'.
  dn_item_serial_no-serialno = 'ZSD-MJM10'.
  append dn_item_serial_no.

  dn_item_serial_no-itm_number = '000010'.
  dn_item_serial_no-serialno = 'ZSD-MJM11'.
  append dn_item_serial_no.

  dn_item_serial_no-itm_number = '000010'.
  dn_item_serial_no-serialno = 'ZSD-MJM12'.
  append dn_item_serial_no.

  dn_item_serial_no-itm_number = '000010'.
  dn_item_serial_no-serialno = 'ZSD-MJM13'.
  append dn_item_serial_no.

  dn_item_serial_no-itm_number = '000010'.
  dn_item_serial_no-serialno = 'ZSD-MJM14'.
  append dn_item_serial_no.

  dn_item_serial_no-itm_number = '000010'.
  dn_item_serial_no-serialno = 'ZSD-MJM15'.
  append dn_item_serial_no.

  dn_item_serial_no-itm_number = '000010'.
  dn_item_serial_no-serialno = 'ZSD-MJM17'.
  append dn_item_serial_no.

  dn_item_serial_no-itm_number = '000010'.
  dn_item_serial_no-serialno = 'ZSD-MJM18'.
  append dn_item_serial_no.

  dn_item_serial_no-itm_number = '000010'.
  dn_item_serial_no-serialno = 'ZSD-SAFHOAGH15B'.
  append dn_item_serial_no.

  dn_item_serial_no-itm_number = '000010'.
  dn_item_serial_no-serialno = 'ZSD-MJM16'.
  append dn_item_serial_no.



  CALL FUNCTION 'BAPI_OUTB_DELIVERY_CHANGE'
    EXPORTING
      header_data    = dn_header_data
      header_control = dn_header_control
      delivery       = dn_delivery
    TABLES
      return         = dn_return
      item_serial_no = dn_item_serial_no.
  READ TABLE dn_return WITH KEY type = 'E'.
  IF sy-subrc <> 0.
*    CALL FUNCTION 'TRANSACTION_STATUS'
*      IMPORTING
*        status = g_status_of_transaction.

    IF g_status_of_transaction = 'COMMIT_WORK'.
      CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
        EXPORTING
          wait = 'X'.
    ELSE.
      CALL FUNCTION 'BAPI_TRANSACTION_ROLLBACK'.
    ENDIF.

*    CALL FUNCTION 'TRANSACTION_END'
*      EXPORTING
*        transaction_id = g_transaction_id
*      EXCEPTIONS
*        OTHERS         = 1.

  ENDIF.

  REFRESH dn_return.

  DELETE dn_item_serial_no WHERE serialno = 'ZSD-MJM10'.
  dn_item_serial_no-itm_number = '000010'.
  dn_item_serial_no-serialno = 'ZSD-SAFHOAGH16'.
  append dn_item_serial_no.

CALL FUNCTION 'SERIAL_INTTAB_REFRESH'
      EXPORTING
        objects_status_refresh = 'E'.

  CALL FUNCTION 'BAPI_OUTB_DELIVERY_CHANGE'
    EXPORTING
      header_data    = dn_header_data
      header_control = dn_header_control
      delivery       = dn_delivery
    TABLES
      return         = dn_return
      item_serial_no = dn_item_serial_no.
  READ TABLE dn_return WITH KEY type = 'E'.
  IF sy-subrc <> 0.
*    CALL FUNCTION 'TRANSACTION_STATUS'
*      IMPORTING
*        status = g_status_of_transaction.

    IF g_status_of_transaction = 'COMMIT_WORK'.
      CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
        EXPORTING
          wait = 'X'.
    ELSE.
      CALL FUNCTION 'BAPI_TRANSACTION_ROLLBACK'.
    ENDIF.

*    CALL FUNCTION 'TRANSACTION_END'
*      EXPORTING
*        transaction_id = g_transaction_id
*      EXCEPTIONS
*        OTHERS         = 1.

  ENDIF.




END-OF-SELECTION.

 

 

上面的测试程序主要是为了解决RF扫描序列号到交货单中时,如果中途发现扫描错误,再次扫描更正数据后执行BAPI时会报错,报序列号被其它的ITEM占用。后来是以下的函数解决了问题。

 

CALL FUNCTION 'SERIAL_INTTAB_REFRESH'
      EXPORTING
        objects_status_refresh = 'E'.

 

 

 GOOGLE 搜索:WS_DELIVERY_UPDATE_2 SERIAL

 

https://forums.sdn.sap.com/thread.jspa?threadID=1397725

 

To update serial nos to delivery in RF use the following FM L_SER_WS_DELIVERY_UPDATE.

Use as follows:-

<code class="jive-code jive-java">    CALL FUNCTION <span style="color: rgb(0, 0, 128);">'SERIAL_INTTAB_REFRESH'</span>
      EXPORTING
        objects_status_refresh = <span style="color: rgb(0, 0, 128);">'E'</span>.
 
    CALL FUNCTION <span style="color: rgb(0, 0, 128);">'L_SER_WS_DELIVERY_UPDATE'</span>
      EXPORTING
        vbkok_wa                 = y_wa_vbkok
        synchron                 = <span style="color: rgb(0, 0, 128);">'X'</span>
        commit                   = <span style="color: rgb(0, 0, 128);">' '</span>
        delivery                 = y_p_vbel
        nicht_sperren            = <span style="color: rgb(0, 0, 128);">'X'</span>
        if_get_delivery_buffered = <span style="color: rgb(0, 0, 128);">' '</span>
        if_error_messages_send_0 = <span style="color: rgb(0, 0, 128);">'X'</span>
        it_sernr_update          = y_li_sernr
      EXCEPTIONS
        error_message            = 1
        OTHERS                   = 2.
 
    CASE sy-subrc.
      WHEN 0.
        COMMIT WORK.
      WHEN OTHERS.
 
        MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
                WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
</code>

 

Internally it is just making a call to 'WS_DELIVERY_UPDATE_2'
So try using the FM WS_DELIVERY_UPDATE_2

 

https://forums.sme.sap.com/message.jspa?messageID=8847913

BAPI_OUTB_DELIVERY_CHANGE / WS_DELIVERY_UPDATE

BAPI_OUTB_DELIVERY_CHANGE & L_SER_WS_DELIVERY_UPDATE

这两个FUNCTION,一个会做序列号的检查,后面一个不会做检查,直接保存进去

 

CALL FUNCTION 'WS_DELIVERY_UPDATE'
                EXPORTING
                 vbkok_wa                           = w_vbkok_wa
*                COMMIT                             = 'X'
                 delivery                           = v_delivery
                 if_database_update                 = '1'
                 if_error_messages_send_0           = 'X'
                 it_sernr_update                    = t_sernr_update

 

 

 http://sap.ittoolbox.com/groups/technical-functional/sap-dev/serial-number-in-handling-unit-308912

I am trying to add serial numbers to items in a handling unit in an outbound delivery (Sales Order) calling 1. SERIAL_INTTAB_REFRESH, 2. SERNR_ADD_TO_HU and 3. SERIAL_LISTE_POST_HU. I don't get errors but the serial number does not get added to the HU.

 

http://forums.sdn.sap.com/thread.jspa?threadID=576174

https://forums.sme.sap.com/thread.jspa?threadID=1779645&tstart=0

 

WS_DELIVERY_UPDATE_2

你可能感兴趣的:(bapi BAPI_OUTB_DELIVERY_CHANGE 修改交货单中的序列号)