此博客为原创博客,都是个人工作经历所得,转载请注明出处

DN创建

 

1. 参考采购订单创建DN : 

BAPI_OUTB_DELIVERY_CREATE_STO
FUNCTION zmmfm0202.
*"----------------------------------------------------------------------
*"*"本地接口:
*"  EXPORTING
*"     REFERENCE(O_RETURN) TYPE  ZMMS0021
*"  TABLES
*"      IT_ITEM STRUCTURE  ZMMS0185
*"----------------------------------------------------------------------
  DATA:lt_stock_items TYPE TABLE OF bapidlvreftosto.
  DATA:ls_stock_items TYPE bapidlvreftosto.
  DATA:lt_created_items TYPE TABLE OF bapidlvitemcreated.
  DATA:ls_created_items TYPE bapidlvitemcreated.
  DATA:lv_delivery TYPE bapishpdelivnumb-deliv_numb.
  DATA:lv_vstel TYPE vstel.
  DATA:lv_ledat TYPE ledat.
  DATA:lt_return TYPE TABLE OF bapiret2.


  LOOP AT it_item INTO DATA(ls_item).
    ls_stock_items-ref_doc = ls_item-ebeln."参考凭证
    ls_stock_items-ref_item = ls_item-ebelp."参考项
    ls_stock_items-dlv_qty = ls_item-menge."数量
    ls_stock_items-sales_unit = ls_item-meins."数量单位
    APPEND ls_stock_items TO lt_stock_items.

    ls_created_items-ref_doc = ls_item-ebeln."参考凭证
    ls_created_items-ref_item = ls_item-ebelp."参考项
    ls_created_items-material = ls_item-matnr."物料编号
    ls_created_items-material_long = ls_item-matnr."物料编号
    ls_created_items-dlv_qty = ls_item-menge."数量
    ls_created_items-sales_unit = ls_item-meins."数量单位
    APPEND ls_created_items TO lt_created_items.
  ENDLOOP.

  CALL FUNCTION 'BAPI_OUTB_DELIVERY_CREATE_STO'
    EXPORTING
      ship_point        = lv_vstel
      due_date          = lv_ledat
    IMPORTING
      delivery          = lv_delivery
    TABLES
      stock_trans_items = lt_stock_items
      created_items     = lt_created_items
      return            = lt_return.

  DELETE lt_return WHERE type = 'E' AND id = 'BAPI' AND number = '001'.

  "20190628 需求
  READ TABLE lt_return INTO DATA(ls_return) WITH KEY id = 'VLBAPI'
                                                       number = '061'
                                                       type   = 'I'.
  IF sy-subrc = 0.
    o_return-message = ls_return-message.

    "创建失败
    CALL FUNCTION 'BAPI_TRANSACTION_ROLLBACK'.

    o_return-type = 'E'.
    CONCATENATE '交货单创建失败:' o_return-message INTO o_return-message.
  ELSE.
    LOOP AT lt_return INTO ls_return WHERE type = 'E'.
      CONCATENATE o_return-message ls_return-message INTO o_return-message SEPARATED BY '/'.
    ENDLOOP.

    IF sy-subrc = 0.

      "创建失败
      CALL FUNCTION 'BAPI_TRANSACTION_ROLLBACK'.

      o_return-type = 'E'.
      CONCATENATE '交货单创建失败:' o_return-message INTO o_return-message.

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

      o_return-zdjh = lv_delivery."交货单
      o_return-type = 'S'.
      o_return-message = '交货单创建成功'.

    ENDIF.
  ENDIF.
ENDFUNCTION.

2. 参考销售订单创建DN : 

BAPI_OUTB_DELIVERY_CREATE_SLS
FUNCTION zsdfm0032.
*"----------------------------------------------------------------------
*"*"本地接口:
*"  EXPORTING
*"     REFERENCE(O_RETURN) TYPE  ZMMS0021
*"  TABLES
*"      IT_ITEM STRUCTURE  ZSDS0011
*"----------------------------------------------------------------------
***********************************************
*     Program     :  参考SO创建DN 控制到行项目数量
*******************************************************************
*     Modified Recorder :
*     Date         C#NO        Author                Content
*     -----------  -------    ------------------     ---------------
*   修改日期    修改产生请求    修改人                修改内容描述
********************************************************************
  DATA:lv_delivery TYPE bapishpdelivnumb-deliv_numb,
       lv_num      TYPE bapidlvcreateheader-num_deliveries.
  DATA:lv_vstel  TYPE vstel.
  DATA:lv_ledat  TYPE ledat.
  DATA:lt_return TYPE TABLE OF bapiret2.


  DATA:lv_shippoint TYPE bapidlvcreateheader-ship_point,
       lv_duedate   TYPE bapidlvcreateheader-due_date.
  DATA:lt_so_items LIKE TABLE OF bapidlvreftosalesorder,
       ls_so_items LIKE bapidlvreftosalesorder.


  LOOP AT it_item INTO DATA(ls_item).
    ls_so_items-ref_doc  = ls_item-vbeln."参考凭证
    ls_so_items-ref_item = ls_item-posnr."参考项
    ls_so_items-dlv_qty  = ls_item-menge."数量
    ls_so_items-sales_unit = ls_item-meins."数量单位
    APPEND ls_so_items TO lt_so_items.
    CLEAR:ls_so_items.

    IF lv_vstel IS INITIAL.
      SELECT SINGLE vstel INTO lv_vstel
        FROM vbap
       WHERE vbeln = ls_item-vbeln
         AND posnr = ls_item-posnr.
    ENDIF.
  ENDLOOP.

  lv_shippoint = lv_vstel.
*---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  = 'A'
                                             OR type = 'E'
                                             OR type = 'X'.
    o_return-type  ='E'.
    CONCATENATE o_return-message ls_return-message INTO o_return-message SEPARATED BY '/'.
    EXIT.
  ENDLOOP.


  IF o_return-type  ='E'.
    "创建失败
    CALL FUNCTION 'BAPI_TRANSACTION_ROLLBACK'.
    CONCATENATE '交货单创建失败:' o_return-message INTO o_return-message.
  ELSE.
    "创建成功
    CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
      EXPORTING
        wait = 'X'.
    o_return-zdjh = lv_delivery."交货单
    o_return-type = 'S'.
    o_return-message = '交货单创建成功'.
  ENDIF.

ENDFUNCTION.

 

 
posted @ 2019-09-26 17:45  Rainystuday  阅读(451)  评论(0编辑  收藏  举报