参考销售订单创建内向交货单BAPI_OUTB_DELIVERY_CREATE_SLS

Posted 想发财的小夏

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了参考销售订单创建内向交货单BAPI_OUTB_DELIVERY_CREATE_SLS相关的知识,希望对你有一定的参考价值。

FUNCTION zfmsdXXX.
*"----------------------------------------------------------------------
*"*"本地接口:
*"  EXPORTING
*"     REFERENCE(EV_TYPE) TYPE  BAPI_MTYPE
*"     REFERENCE(EV_MSG) TYPE  BAPI_MSG
*"  TABLES
*"      IT_TABLE STRUCTURE  ZSSD016
*"----------------------------------------------------------------------

  DATA:lv_delivery  TYPE bapishpdelivnumb-deliv_numb,
       lv_num       TYPE bapidlvcreateheader-num_deliveries,
       lt_return    TYPE TABLE OF bapiret2,
       lv_shippoint TYPE bapidlvcreateheader-ship_point,
       lv_duedate   TYPE bapidlvcreateheader-due_date,
       lt_so_items  LIKE TABLE OF bapidlvreftosalesorder,
       ls_so_items  LIKE bapidlvreftosalesorder,
       lv_msg       TYPE bapi_msg.

  DEFINE return_msg.

    ev_type = &1.
    ev_msg  = &2.

  IF ev_type NE 'S'.
    RETURN.
  ENDIF.

  END-OF-DEFINITION.

  CLEAR:lv_msg.

  IF it_table[] IS NOT INITIAL.

    SELECT vbeln,posnr,zieme
      FROM vbap
      INTO TABLE @DATA(lt_vbap)
       FOR ALL ENTRIES IN @it_table
     WHERE vbeln = @it_table-vbeln_va
       AND posnr = @it_table-posnr_va.

  ENDIF.

  LOOP AT it_table INTO DATA(ls_table).

    ls_so_items-ref_doc  = ls_table-vbeln_va."参考凭证
    ls_so_items-ref_item = ls_table-posnr_va."参考凭证行
    ls_so_items-dlv_qty  = ls_table-qty."数量
    ls_so_items-sales_unit = ls_table-uom."数量单位

    IF ls_table-uom IS INITIAL.
      READ TABLE lt_vbap INTO DATA(ls_vbap) WITH KEY vbeln = ls_table-vbeln_va posnr = ls_table-posnr_va.
      IF sy-subrc = 0.
        ls_so_items-sales_unit = ls_vbap-zieme."数量单位
      ENDIF.
    ENDIF.

    APPEND ls_so_items TO lt_so_items.
    CLEAR:ls_so_items.

    IF lv_shippoint IS INITIAL.
      SELECT SINGLE vstel
        INTO lv_shippoint
        FROM vbap
       WHERE vbeln = ls_table-vbeln_va
         AND posnr = ls_table-posnr_va.
    ENDIF.

  ENDLOOP.

*---Call BAPI Function
  CALL FUNCTION 'BAPI_OUTB_DELIVERY_CREATE_SLS'
    EXPORTING
      ship_point        = lv_shippoint
      due_date          = sy-datum
    IMPORTING
      delivery          = lv_delivery
      num_deliveries    = lv_num
    TABLES
      sales_order_items = lt_so_items
      return            = lt_return.

  LOOP AT lt_return INTO DATA(ls_return) WHERE type  CA 'AEX'.
    IF lv_msg IS INITIAL.
      lv_msg = ls_return-message.
    ELSE.
      lv_msg = | { lv_msg } { ';' } { ls_return-message } |.
    ENDIF.
  ENDLOOP.

  IF sy-subrc EQ 0.
    "创建失败
    CALL FUNCTION 'BAPI_TRANSACTION_ROLLBACK'.
    return_msg 'E' lv_msg.

  ELSE.

    "创建成功
    CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
      EXPORTING
        wait = 'X'.

    return_msg 'S' '创建成功'.

    LOOP AT it_table ASSIGNING FIELD-SYMBOL(<fs>).
      <fs>-vbeln_vl = lv_delivery.
      <fs>-posnr_vl = <fs>-posnr_va.
    ENDLOOP.

  ENDIF.

ENDFUNCTION.

以上是关于参考销售订单创建内向交货单BAPI_OUTB_DELIVERY_CREATE_SLS的主要内容,如果未能解决你的问题,请参考以下文章

sap冲销销售订单后如何生成新的销售单

sap系统中,一张销售订单做了三张交货单,现要对其中一张交货单做退货,如何配置实现。

SAP-PS笔记项目交货之基于销售订单VL01N交货

SAP-PS笔记项目交货之基于销售订单VL01N交货

SAP SD如何将销售订单其它ITEM加入到一个已创建好的交货单里

销售订单交货计划