VL01N/VL02N/VL09 BAPI

1.VL01N

FUNCTION zfmsd_create_dn.
*"----------------------------------------------------------------------
*"*"本地接口:
*"  IMPORTING
*"     VALUE(SHIP_POINT) TYPE  BAPIDLVCREATEHEADER-SHIP_POINT OPTIONAL
*"     VALUE(DUE_DATE) TYPE  BAPIDLVCREATEHEADER-DUE_DATE OPTIONAL
*"     VALUE(IT_PARTNER_UPDATE) TYPE  SHP_PARTNER_UPDATE_T OPTIONAL
*"     VALUE(IS_ZLIKP) TYPE  ZSSD_ZLIKP OPTIONAL
*"     VALUE(IV_WADAT) TYPE  WADAT OPTIONAL
*"  EXPORTING
*"     VALUE(DELIVERY) TYPE  BAPISHPDELIVNUMB-DELIV_NUMB
*"     VALUE(NUM_DELIVERIES) TYPE  BAPIDLVCREATEHEADER-NUM_DELIVERIES
*"  TABLES
*"      SALES_ORDER_ITEMS STRUCTURE  BAPIDLVREFTOSALESORDER
*"      SERIAL_NUMBERS STRUCTURE  BAPIDLVSERIALNUMBER OPTIONAL
*"      EXTENSION_IN STRUCTURE  BAPIPAREX OPTIONAL
*"      DELIVERIES STRUCTURE  BAPISHPDELIVNUMB OPTIONAL
*"      CREATED_ITEMS STRUCTURE  BAPIDLVITEMCREATED OPTIONAL
*"      EXTENSION_OUT STRUCTURE  BAPIPAREX OPTIONAL
*"      RETURN STRUCTURE  BAPIRET2 OPTIONAL
*"      IT_BAPIADDR1 STRUCTURE  BAPIADDR1 OPTIONAL
*"      VBPOK_TAB STRUCTURE  VBPOK OPTIONAL
*"      IT_TEXTL STRUCTURE  TEXTL_GN
*"      IT_VBPOK STRUCTURE  VBPOK
*"----------------------------------------------------------------------
  DATA:vbkok_wa  TYPE vbkok,
       ls_zlikp  TYPE zlikp,
       prot      TYPE STANDARD TABLE OF prott,
       lt_items  TYPE TABLE OF bapidlvitemcreated,
       lt_items2 TYPE TABLE OF bapidlvreftosalesorder.
  DATA:lv_create(1),
       lv_create2(1).

  due_date = '99991231'.
  IF sales_order_items[] IS NOT INITIAL.
    SELECT * FROM vbap
      INTO TABLE @DATA(lt_vbap)
      FOR ALL ENTRIES IN @sales_order_items
      WHERE vbeln = @sales_order_items-ref_doc
        AND posnr = @sales_order_items-ref_item.
*    SELECT * FROM vbep
*      INTO TABLE @DATA(lt_vbep)
*      FOR ALL ENTRIES IN @sales_order_items
*      WHERE vbeln = @sales_order_items-ref_doc
*        AND posnr = @sales_order_items-ref_item..

    lt_items2 = sales_order_items[].
    WITH +i AS ( SELECT DISTINCT ref_doc,ref_item
                   FROM @lt_items2 AS k )
  SELECT i~ref_doc,i~ref_item,SUM( a~ordqty_bu ) AS ordqty_bu
    FROM +i AS i
    LEFT JOIN vbep AS a
      ON i~ref_doc EQ a~vbeln
     AND i~ref_item EQ a~posnr
   GROUP BY ref_doc,ref_item
    INTO TABLE @DATA(lt_vbep).
    IF lt_vbap[] IS NOT INITIAL.
      SELECT matnr, werks,disgr  FROM marc
        INTO TABLE @DATA(lt_marc)
        FOR ALL ENTRIES IN @lt_vbap
        WHERE matnr = @lt_vbap-matnr
          AND werks = @lt_vbap-werks.
      SELECT * FROM mard
        INTO TABLE @DATA(lt_mard)
        FOR ALL ENTRIES IN @lt_vbap
       WHERE matnr = @lt_vbap-matnr
         AND werks = @lt_vbap-werks
         AND lgort = @lt_vbap-lgort.
      SELECT * FROM mska
      INTO TABLE @DATA(lt_mska)
      FOR ALL ENTRIES IN @lt_vbap
     WHERE matnr = @lt_vbap-matnr
       AND werks = @lt_vbap-werks
       AND lgort = @lt_vbap-lgort
       AND vbeln = @lt_vbap-vbeln
       AND posnr = @lt_vbap-posnr.
    ENDIF.
  ENDIF.
  IF vbpok_tab[] IS NOT INITIAL.

  ENDIF.
  SORT lt_vbap BY vbeln posnr.
  SORT lt_vbep BY ref_doc ref_item.
  SORT lt_marc BY matnr werks.
  SORT lt_mard BY matnr werks lgort.
  SORT lt_mska BY matnr werks lgort vbeln posnr.
  LOOP AT sales_order_items.
    READ TABLE lt_vbap INTO DATA(ls_vbap) WITH KEY vbeln = sales_order_items-ref_doc
                                                   posnr = sales_order_items-ref_item
                                                   BINARY SEARCH.
    IF sy-subrc <> 0.
      return-type = 'E'.
      return-message = |{ '销售订单:' }{ sales_order_items-ref_doc }{ '行项目:' }{ sales_order_items-ref_item }{ '不存在!' }|.
      APPEND return.
    ENDIF.
*    READ TABLE lt_vbep INTO DATA(ls_vbep) WITH  KEY vbeln = sales_order_items-ref_doc
*                                                    posnr = sales_order_items-ref_item
*                                                    BINARY SEARCH.
*    IF sy-subrc = 0.
*
*      IF ls_vbep-edatu > due_date.
*        return-type = 'E'.
*        return-message = |{ '创建日期:' }{ due_date }{ '小于计划交货日期' }{ ls_vbep-edatu }|.
*        APPEND return.
*      ENDIF.
*      IF ls_vbep-ordqty_bu < sales_order_items-dlv_qty.
*        return-type = 'E'.
*        return-message = |{ '行' }{ sales_order_items-ref_item }{ '剩余可交货数量:' }{ ls_vbep-ordqty_bu }{ '不满足交货数量' }{ sales_order_items-dlv_qty }|.
*        APPEND return.
*      ENDIF.
*    ENDIF.
    READ TABLE lt_vbep INTO DATA(ls_vbep) WITH  KEY ref_doc = sales_order_items-ref_doc
                                                    ref_item = sales_order_items-ref_item
                                                    BINARY SEARCH.
    IF ls_vbep-ordqty_bu < sales_order_items-dlv_qty.
      return-type = 'E'.
      return-message = |{ '' }{ sales_order_items-ref_item }{ '剩余可交货数量:' }{ ls_vbep-ordqty_bu }{ '不满足交货数量' }{ sales_order_items-dlv_qty }|.
      APPEND return.
    ENDIF.

  ENDLOOP.
  SORT return BY type message.
  DELETE ADJACENT DUPLICATES FROM return COMPARING ALL FIELDS.
  CHECK return IS INITIAL.

  lv_create = 'X'.
  EXPORT lv_create = lv_create TO MEMORY ID 'ZFMSD_CREATE_DN'."MV50AFZ1


  CALL FUNCTION 'BAPI_OUTB_DELIVERY_CREATE_SLS'
    EXPORTING
      ship_point        = ship_point
      due_date          = due_date
    IMPORTING
      delivery          = delivery
    TABLES
      sales_order_items = sales_order_items
*     SERIAL_NUMBERS    =
      extension_in      = extension_in
*     DELIVERIES        =
      created_items     = lt_items
*     EXTENSION_OUT     =
      return            = return.
ENDFUNCTION.

2.VL02N

交货单日期字段更改

 交货单更新:

  DATA:LV_ERROR TYPE C,
       LS_ZLIKP TYPE ZLIKP.

  "修改交货单标准字段
  IF DELIVERY IS NOT INITIAL.
    CALL FUNCTION 'BAPI_OUTB_DELIVERY_CHANGE'
      EXPORTING
        HEADER_DATA             = HEADER_DATA
        HEADER_CONTROL          = HEADER_CONTROL
        DELIVERY                = DELIVERY
        TECHN_CONTROL           = TECHN_CONTROL
        HEADER_DATA_SPL         = HEADER_DATA_SPL
        HEADER_CONTROL_SPL      = HEADER_CONTROL_SPL
        SENDER_SYSTEM           = SENDER_SYSTEM
      TABLES
        HEADER_PARTNER          = HEADER_PARTNER
        HEADER_PARTNER_ADDR     = HEADER_PARTNER_ADDR
        HEADER_DEADLINES        = HEADER_DEADLINES
        ITEM_DATA               = ITEM_DATA
        ITEM_CONTROL            = ITEM_CONTROL
        ITEM_SERIAL_NO          = ITEM_SERIAL_NO
        SUPPLIER_CONS_DATA      = SUPPLIER_CONS_DATA
        EXTENSION1              = EXTENSION1
        EXTENSION2              = EXTENSION2
        RETURN                  = RETURN
        TOKENREFERENCE          = TOKENREFERENCE
        ITEM_DATA_SPL           = ITEM_DATA_SPL
        COLLECTIVE_CHANGE_ITEMS = COLLECTIVE_CHANGE_ITEMS
        NEW_ITEM_DATA           = NEW_ITEM_DATA
        NEW_ITEM_DATA_SPL       = NEW_ITEM_DATA_SPL
        NEW_ITEM_ORG            = NEW_ITEM_ORG
        ITEM_DATA_DOCU_BATCH    = ITEM_DATA_DOCU_BATCH
        CWM_ITEM_DATA           = CWM_ITEM_DATA.
  ENDIF.

  CLEAR LV_ERROR.
  LOOP AT RETURN INTO DATA(LS_RETURN) WHERE TYPE CA 'AEX'.
    LV_ERROR = 'X'.
    EXIT.
  ENDLOOP.


  IF IS_ZLIKP IS NOT INITIAL.
    IF IS_ZLIKP-VBELN IS INITIAL.
      CLEAR LS_RETURN.
      LS_RETURN-TYPE       = 'E'.
      LS_RETURN-ID         = 'V1'.
      LS_RETURN-NUMBER     = '899'.
      LS_RETURN-MESSAGE    = '交货抬头增强字段无交货单号'.
      APPEND LS_RETURN TO RETURN.
      LV_ERROR = 'X'.
    ENDIF.
  ENDIF.

  IF LV_ERROR IS INITIAL.
    IF IS_ZLIKP IS NOT INITIAL.
      CLEAR LS_ZLIKP.
      MOVE-CORRESPONDING IS_ZLIKP TO LS_ZLIKP.
      MODIFY ZLIKP FROM LS_ZLIKP.
    ENDIF.
  ENDIF.
    "交货日期字段更新
        DATA:ls_header         TYPE bapiobdlvhdrchg,
             ls_header_control TYPE bapiobdlvhdrctrlchg,
             lv_dn             TYPE bapiobdlvhdrchg-deliv_numb,
             ls_time           TYPE bapidlvdeadln,
             lt_time           TYPE TABLE OF bapidlvdeadln,
             lt_return_2       TYPE TABLE OF bapiret2.

        ls_header-deliv_numb = delivery.
        ls_header_control-deliv_numb = delivery.
        lv_dn = delivery.

        ls_time-deliv_numb = delivery.
        ls_time-timetype = 'WSHDRWADAT'.
        ls_time-timestamp_utc = iv_wadat && '000000'.
        APPEND ls_time TO lt_time.

        CALL FUNCTION 'BAPI_OUTB_DELIVERY_CHANGE'
          EXPORTING
            header_data      = ls_header
            header_control   = ls_header_control
            delivery         = lv_dn
          TABLES
            header_deadlines = lt_time
            return           = lt_return_2.

交货单过账:

 L_HEADER_DATA-DELIV_NUMB         = PV_VBELD.
  L_HEADER_CONTROL-DELIV_NUMB  = PV_VBELD.
  L_HEADER_CONTROL-POST_GI_FLG   = 'X'.
  L_HEADER_CONTROL-VOLUME_FLG  = 'X'.

 "外向交货单发货过账
  CALL FUNCTION ' BAPI_OUTB_DELIVERY_CONFIRM_DEC '
    EXPORTING
       HEADER_DATA             = L_HEADER_DATA
       HEADER_CONTROL       = L_HEADER_CONTROL
       DELIVERY                       = PV_VBELD
    TABLES
*     iT_HEADER_PARTNER      =
*     iT_HEADER_PARTNER_ADDR =
*     iT_HEADER_DEADLINES    =
*     iT_ITEM_DATA           =
*     iT_ITEM_CONTROL        =
*     iT_ITEM_CODING_BLOCK   =
       RETURN              = LT_RETURN_BAPI.

交货单过账冲销:

FUNCTION ZFM_SD_REVERSE_GOODS_ISSUE .
*"----------------------------------------------------------------------
*"*"本地接口:
*"  IMPORTING
*"     VALUE(I_VBELN) LIKE  LIKP-VBELN
*"     VALUE(I_BUDAT) LIKE  SY-DATLO
*"     VALUE(I_COUNT) LIKE  SY-MSGNO OPTIONAL
*"     VALUE(I_MBLNR) LIKE  MKPF-MBLNR OPTIONAL
*"     VALUE(I_TCODE) LIKE  SY-TCODE OPTIONAL
*"     VALUE(I_VBTYP) LIKE  LIKP-VBTYP OPTIONAL
*"     VALUE(I_MBLPO) LIKE  MSEG-ZEILE OPTIONAL
*"     VALUE(I_MJAHR) LIKE  MSEG-MJAHR OPTIONAL
*"     VALUE(I_POSNR) LIKE  LIPS-POSNR OPTIONAL
*"     VALUE(I_SIMULATE) TYPE  CHAR1 DEFAULT SPACE
*"     VALUE(I_SPE_BUDAT_UHR) TYPE  WAUHR OPTIONAL
*"     VALUE(I_SPE_BUDAT_ZONE) TYPE  TZNZONE OPTIONAL
*"     VALUE(I_SPE_MDNUM_EWM) TYPE  /SPE/MDNUM_EWM OPTIONAL
*"     VALUE(I_SPE_LOGSYS) TYPE  /SPE/_LOGSYS_MD OPTIONAL
*"     VALUE(I_SPE_CONFIRM_CENTRAL) TYPE  XFLAG DEFAULT SPACE
*"     VALUE(I_SPE_BILLING_REVERSAL) TYPE  CHAR1 DEFAULT SPACE
*"     VALUE(I_PGR_FLG) TYPE  CHAR1 OPTIONAL
*"     VALUE(I_BLDAT) LIKE  MKPF-BLDAT OPTIONAL
*"     VALUE(I_OIB_BLTIME) LIKE  SY-UZEIT OPTIONAL
*"     VALUE(I_OIKIMPORT) LIKE  ROIKIMPORT STRUCTURE  ROIKIMPORT
*"       OPTIONAL
*"  EXPORTING
*"     VALUE(ES_EMKPF) TYPE  EMKPF
*"  TABLES
*"      T_MESG STRUCTURE  MESG
*"      T_VBAPF STRUCTURE  VBAPF OPTIONAL
*"      T_VBFA STRUCTURE  VBFAVB OPTIONAL
*"      T_OIA11 STRUCTURE  OIA11 OPTIONAL
*"  EXCEPTIONS
*"      ERROR_REVERSE_GOODS_ISSUE
*"----------------------------------------------------------------------
  DATA:LS_MESG TYPE MESG.

  CALL FUNCTION 'WS_REVERSE_GOODS_ISSUE'
    EXPORTING
      I_VBELN                   = I_VBELN
      I_BUDAT                   = I_BUDAT
      I_COUNT                   = I_COUNT
      I_MBLNR                   = I_MBLNR
      I_TCODE                   = I_TCODE
      I_VBTYP                   = I_VBTYP
      I_MBLPO                   = I_MBLPO
      I_MJAHR                   = I_MJAHR
      I_POSNR                   = I_POSNR
      I_SIMULATE                = I_SIMULATE
      I_SPE_BUDAT_UHR           = I_SPE_BUDAT_UHR
      I_SPE_BUDAT_ZONE          = I_SPE_BUDAT_ZONE
      I_SPE_MDNUM_EWM           = I_SPE_MDNUM_EWM
      I_SPE_LOGSYS              = I_SPE_LOGSYS
      I_SPE_CONFIRM_CENTRAL     = I_SPE_CONFIRM_CENTRAL
      I_SPE_BILLING_REVERSAL    = I_SPE_BILLING_REVERSAL
      I_PGR_FLG                 = I_PGR_FLG
    IMPORTING
      ES_EMKPF                  = ES_EMKPF
    TABLES
      T_MESG                    = T_MESG
      T_VBAPF                   = T_VBAPF
      T_VBFA                    = T_VBFA
    EXCEPTIONS
      ERROR_REVERSE_GOODS_ISSUE = 1
      OTHERS                    = 2.
  IF SY-SUBRC <> 0.
    CLEAR LS_MESG.
    LS_MESG-ZEILE = ''.
    LS_MESG-MSGTY = 'E'.
    LS_MESG-TEXT = 'ERROR_REVERSE_GOODS_ISSUE'.
    LS_MESG-ARBGB = SY-MSGID.
    LS_MESG-TXTNR = SY-MSGNO.
    LS_MESG-MSGV1 = SY-MSGV1.
    LS_MESG-MSGV2 = SY-MSGV2.
    LS_MESG-MSGV3 = SY-MSGV3.
    LS_MESG-MSGV4 = SY-MSGV4.
    APPEND LS_MESG TO T_MESG.
  ENDIF.

ENDFUNCTION.

 

posted @ 2024-08-13 17:02  阿胖的阿多  阅读(49)  评论(0编辑  收藏  举报