DN create

 

1. The reference to a purchase order creation 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." Number 
    ls_stock_items-sales_unit = ls_item-Meins. " Number of Units 
    the APPEND ls_stock_items the TO lt_stock_items. 

    Ls_created_items -ref_doc = ls_item-ebeln. " Reference Document 
    ls_created_items-ref_item = ls_item-ebelp. " Reference entry 
    ls_created_items = ls_item-MATNR-Material's. " Material number 
    ls_created_items-material_long = ls_item-MATNR. " material number 
    ls_created_items-dlv_qty = ls_item-Menge. " quantity 
    ls_created_items-sales_unit = ls_item-Meins. " number of units 
    APPEND ls_created_items the 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 is = 0 . 

      " Failed to create 
      the CALL  FUNCTION  ' BAPI_TRANSACTION_ROLLBACK ' . 

      O_return The -type = ' E ' .
       CONCATENATE  ' delivery creation failed: ' o_return the Message- INTO o_return- . The Message 

    ELSE .
       " Successfully created 
      the CALL  FUNCTION  ' BAPI_TRANSACTION_COMMIT ' 
        EXPORTING 
          the wait = ' X- ' . 

      o_return= lv_delivery -zdjh. " Delivery 
      o_return-of the type = ' S ' . 
      o_return -message = ' Delivery create success ' . 

    ENDIF .
   ENDIF .
 endFunction .

2. Refer to the sales order creation DN: 

BAPI_OUTB_DELIVERY_CREATE_SLS
FUNCTION zsdfm0032.
 * "--------------------------------------------- ------------------------- 
* "*" local Interface: 
* "EXPORTING 
* " the REFERENCE (O_RETURN) the TYPE ZMMS0021 
* "TABLES 
* " IT_ITEM STRUCTURE ZSDS0011 
* "----------------------------------------------- ----------------------- 
* ************************************************************ ******************** 
*      program: Creating reference SO DN control the number of line items 
* ************************************************************ ************************************************* 
*      Modified Recorder:
*     Date         C#NO        Author                Content
*      ----------- ------- ------------------ ------------- - 
*    modified date modify a request to modify people edit the description 
* ************************************ ******************************* 
  the DATA : lv_delivery the TYPE bapishpdelivnumb- deliv_numb, 
       LV_NUM       the TYPE bapidlvcreateheader- num_deliveries.
   the DATA : lv_vstel   the TYPE vstel .
   the DATA : lv_ledat   the TYPE Ledat.
   the DATA : lt_return the TYPE  TABLE  OF . bapiret2 


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


  LOOP  the AT it_item the INTO  the DATA . (ls_item) 
    ls_so_items . -ref_doc = ls_item-vbeln " Reference Document 
    ls_so_items-ref_item = ls_item-posnr. " reference term 
    ls_so_items-dlv_qty = ls_item-Menge. " number 
    ls_so_items-sales_unit = ls_item-Meins. " number of units
    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.
     " Successfully created 
    the CALL  FUNCTION  ' BAPI_TRANSACTION_COMMIT ' 
      EXPORTING 
        the wait = ' the X- ' . 
    O_return -zdjh = lv_delivery. " Delivery 
    o_return-of the type = ' S ' . 
    O_return -message = ' Delivery create success ' .
   ENDIF . 

EndFunction .

 

 

Guess you like

Origin www.cnblogs.com/rainysblog/p/11593368.html