其他分享
首页 > 其他分享> > WMS函数组:交货单过帐(BAPI)

WMS函数组:交货单过帐(BAPI)

作者:互联网

FUNCTION ZRFC_WMS_DELIVERY_UPDATE.
*"----------------------------------------------------------------------

*"      'LE_MOB_DELIVERY_UPDATE' 更改批次

*"      'WS_DELIVERY_UPDATE' 过帐
*"*"Local interface:
*"  TABLES
*"      ITAB_HEADER STRUCTURE  ZVBKOK OPTIONAL
*"      ITAB_DETAIL STRUCTURE  ZVBPOK OPTIONAL
*"      ITAB_RETURN STRUCTURE  ZINTERFACE_RETURN OPTIONAL
*"      ET_LOG STRUCTURE  BAPIRET2 OPTIONAL
*"----------------------------------------------------------------------
DATA: VBPOK_TAB LIKE VBPOK OCCURS 0 WITH HEADER LINE,
        VBKOK_WA  LIKE VBKOK,
        IT_LIPS LIKE ITAB_DETAIL.
DATA:
         IPROT LIKE PROTT OCCURS 0 WITH HEADER LINE,
         ET_LOG1 LIKE BAPIRET2 OCCURS 0 WITH HEADER LINE.
DATA :
        ITAB_LIPS LIKE LIPS OCCURS 0 WITH HEADER LINE,
*        ITAB_LIPS1 like LIPS occurs 0 with header line,
        IP_WBSTK LIKE VBUK-WBSTK,
        IP_VBELN LIKE LIPS-VBELN.
DATA:
  I_ERROR_MESSAGES  LIKE  ARRANG_ERR .
*------------------CHA JWY_20170811
SORT ITAB_HEADER.
*------------------CHA JWY_20170811
LOOP AT ITAB_HEADER.
CLEAR VBKOK_WA.
    ITAB_RETURN-BILLNO = ITAB_HEADER-WMS_NO.
    ITAB_RETURN-SAPNO = ITAB_HEADER-VBELN.
MOVE ITAB_HEADER-VBELN TO IP_VBELN.
PERFORM F_ADD_ZERO USING IP_VBELN.
**** 检查单据是否被锁定-START
CALL FUNCTION 'ENQUEUE_EVVBLKE'
EXPORTING
        VBELN          = IP_VBELN
EXCEPTIONS
        FOREIGN_LOCK   = 01
        SYSTEM_FAILURE = 02.
IF SY-SUBRC > 0.
      ET_LOG-TYPE = 'E'.
      ET_LOG-ID = IP_VBELN.
      ET_LOG-MESSAGE = 'Object requested is currently locked by user'.
      ET_LOG-LOG_NO = IP_VBELN.
APPEND ET_LOG.
      ITAB_RETURN-SUBRC = -1.
      ITAB_RETURN-MSG = ET_LOG-MESSAGE.
APPEND ITAB_RETURN.
CONTINUE.
ENDIF.
**** 检查单据是否被锁定-END
**** 检查单据是否已经完成-START
CLEAR IP_WBSTK.
SELECT SINGLE WBSTK INTO IP_WBSTK FROM VBUK WHERE VBELN = IP_VBELN.
IF IP_WBSTK = 'C'.
      ET_LOG-TYPE = 'W'.
      ET_LOG-ID = IP_VBELN.
      ET_LOG-MESSAGE = '  已经过账!'.
CONCATENATE IP_VBELN  ET_LOG-MESSAGE INTO ET_LOG-MESSAGE.
APPEND ET_LOG.
      ITAB_RETURN-SUBRC = 0.
      ITAB_RETURN-MSG = ET_LOG-MESSAGE.
APPEND ITAB_RETURN.
CONTINUE.
ENDIF.
**** 检查单据是否已经完成-END
******注意原单的库位不更改
*LOOP AT ITAB_DETAIL.
*update LIPS set LGORT = ITAB_DETAIL-LGORT WHERE VBELN = IP_VBELN AND POSNR =  ITAB_DETAIL-POSNR.
****update LIPS set LGORT = '9131' WHERE VBELN = IP_VBELN AND POSNR =  ITAB_DETAIL-POSNR.
*ENDLOOP.
** 修改批次-START
DATA : IT_MARA LIKE MARA.
CLEAR ITAB_LIPS[].
SELECT * FROM  LIPS INTO TABLE ITAB_LIPS  WHERE VBELN = IP_VBELN.
IF SY-SUBRC > 0 .
      ET_LOG-TYPE = 'E'.
      ET_LOG-ID = IP_VBELN.
      ET_LOG-MESSAGE = ' 交货单不存在'.
CONCATENATE IP_VBELN ET_LOG-MESSAGE INTO ET_LOG-MESSAGE.
      ET_LOG-LOG_NO = IP_VBELN.
APPEND ET_LOG.
      ITAB_RETURN-SUBRC = -1.
      ITAB_RETURN-MSG = ET_LOG-MESSAGE.
APPEND ITAB_RETURN.
CONTINUE.
ENDIF.
*------------------CHA JWY_20170811
SORT ITAB_LIPS.
*------------------CHA JWY_20170811
LOOP AT ITAB_LIPS.
IF ITAB_LIPS-LGORT IS INITIAL.
CLEAR IT_LIPS.
READ  TABLE ITAB_DETAIL INTO IT_LIPS WITH KEY VBELN = IP_VBELN  POSNR = ITAB_LIPS-POSNR.
IF SY-SUBRC EQ 0.
          ITAB_LIPS-LGORT = IT_LIPS-LGORT.
MODIFY ITAB_LIPS.
MODIFY LIPS FROM ITAB_LIPS.
ENDIF.
ENDIF.
CLEAR: IT_MARA,IT_LIPS.
SELECT SINGLE * INTO IT_MARA FROM MARA WHERE MATNR = ITAB_LIPS-MATNR.
IF IT_MARA-XCHPF = 'X'. "查看此物料是否需要进行批次管理
READ  TABLE ITAB_DETAIL INTO IT_LIPS WITH KEY VBELN = IP_VBELN  POSNR = ITAB_LIPS-POSNR.
IF SY-SUBRC EQ 0.
          ITAB_LIPS-CHARG = IT_LIPS-CHARG.
MODIFY ITAB_LIPS.
ENDIF.
ENDIF.
ENDLOOP.
CALL FUNCTION 'LE_MOB_DELIVERY_UPDATE'
EXPORTING
        DO_COMMIT                = 'X'
TABLES
        T_DELIVERY_ITEMS         = ITAB_LIPS
        PROT                     = IPROT
EXCEPTIONS
        CONVERSION_OVERFLOW      = 1
        ESSENTIAL_DATA_MISSING   = 2
        ERROR                    = 3
        NOTHING_TO_UPDATE        = 4
        LOCK_AFTER_UPDATE_FAILED = 5
        ERROR_IN_DELIVERY_UPDATE = 6
OTHERS                   = 7.
IF SY-SUBRC = 0 .
      ET_LOG-TYPE = 'I'.
      ET_LOG-ID = IP_VBELN.
      ET_LOG-MESSAGE = ' 批次修改成功'.
CONCATENATE IP_VBELN ET_LOG-MESSAGE  INTO ET_LOG-MESSAGE.
      ET_LOG-LOG_NO = IP_VBELN.
APPEND ET_LOG.
ENDIF.
*** 修改批次-END
    VBKOK_WA-VBELN_VL = IP_VBELN.
    VBKOK_WA-KOMUE = 'X'.
    VBKOK_WA-WABUC = 'X'.
    VBKOK_WA-WADAT_IST = ITAB_HEADER-WADAT_IST.
CLEAR : VBPOK_TAB,VBPOK_TAB[].
*-------------CHA JWY_20170811
SORT ITAB_DETAIL.
*-------------CHA JWY_20170811
LOOP AT ITAB_DETAIL WHERE VBELN = IP_VBELN.
READ TABLE ITAB_LIPS WITH KEY POSNR = ITAB_DETAIL-POSNR.
CHECK SY-SUBRC = 0.
CLEAR VBPOK_TAB.
      VBPOK_TAB-VBELN_VL = ITAB_DETAIL-VBELN.
      VBPOK_TAB-POSNR_VL =  ITAB_DETAIL-POSNR.
      VBPOK_TAB-VBELN = ITAB_DETAIL-VBELN.
      VBPOK_TAB-POSNN = ITAB_DETAIL-POSNR.
      VBPOK_TAB-CHARG = ITAB_DETAIL-CHARG.
      VBPOK_TAB-LIANP =  'X'.
*      READ TABLE  ITAB_LIPS WITH KEY VBELN = ITAB_DETAIL-VBELN  POSNR = ITAB_DETAIL-POSNR .
*      IF SY-SUBRC  = 0.
*        IF ITAB_DETAIL-LGMNG > ITAB_LIPS-LFIMG.
*          ITAB_DETAIL-LGMNG =  ITAB_LIPS-LFIMG.
*        ENDIF.
*      ENDIF.
      VBPOK_TAB-LGMNG = ITAB_DETAIL-LGMNG.
      VBPOK_TAB-LGPLA = ITAB_DETAIL-LGORT.
*        IF VBPOK_TAB-LGMNG = '0'.
*          CLEAR VBPOK_TAB-CHARG.
*          VBPOK_TAB-LIPS_DEL = 'X'. "删除单据,此处操作危险,转人工操作
*        ENDIF.
APPEND VBPOK_TAB.
ENDLOOP.
CLEAR:IPROT[].
IF VBPOK_TAB[] IS NOT INITIAL.
CALL FUNCTION 'WS_DELIVERY_UPDATE'
EXPORTING
          VBKOK_WA       = VBKOK_WA
COMMIT         = 'X'
          SYNCHRON       = 'X'
          DELIVERY       = IP_VBELN
          UPDATE_PICKING = 'X'
TABLES
          VBPOK_TAB      = VBPOK_TAB
          PROT           = IPROT
*        VBSUPCON_TAB = it_VB
*        IT_VERPO_SERNR = it_se
*        IT_PACKING = it_wm
*        IT_PACKING_SERNR = it_nr
*        IT_REPACK = it_pk
*        IT_HANDLING_UNITS = it_hu
*        IT_OBJECTS = it_pr
*        ET_CREATED_HUS =  it_kp
*        TVPOD_TAB = it_tv
EXCEPTIONS
          ERROR_MESSAGE  = 1           "INS_HP_136357
OTHERS         = 2.          "INS_HP_136357
ENDIF.
*    IF SY-SUBRC = 0 .
*    ELSE.
*      ET_LOG-TYPE = 'E'.
*      ET_LOG-ID = IP_VBELN.
*      ET_LOG-MESSAGE = ' 过账错误,请检查数据来源!'.
*      CONCATENATE IP_VBELN ET_LOG-MESSAGE  INTO ET_LOG-MESSAGE.
*      ET_LOG-LOG_NO = IP_VBELN.
*      APPEND ET_LOG.
*
*      ITAB_RETURN-MSG = ET_LOG-MESSAGE.
*      ITAB_RETURN-SUBRC = SY-SUBRC.
*      APPEND ITAB_RETURN.
*
*
*      LOOP AT iPROT.
*        CLEAR I_ERROR_MESSAGES.
*        I_ERROR_MESSAGES-MSGID  = iPROT-MSGID.
*        I_ERROR_MESSAGES-MSGTY  = iPROT-MSGTY.
*        I_ERROR_MESSAGES-MSGNO  = iPROT-MSGNO.
*        I_ERROR_MESSAGES-MSGV1  = iPROT-MSGV1.
*        I_ERROR_MESSAGES-MSGV2  = iPROT-MSGV2.
*        I_ERROR_MESSAGES-MSGV3  = iPROT-MSGV3.
*        I_ERROR_MESSAGES-MSGV4  = iPROT-MSGV4.
*
*        CALL FUNCTION 'MM_ARRANG_GET_MESSAGE_TEXT'
*          EXPORTING
*            I_ERROR_MESSAGES = I_ERROR_MESSAGES
*            I_LANGU          = SY-LANGU
*          IMPORTING
*            E_TEXT           = ET_LOG-MESSAGE
*          EXCEPTIONS
*            PARAMETER_ERROR  = 1
*            OTHERS           = 2.
*
*        ET_LOG-TYPE = iPROT-MSGTY.
*        ET_LOG-ID = iPROT-MSGID.
*        ET_LOG-NUMBER = iPROT-MSGNO.
*        ET_LOG-MESSAGE_V1 = iPROT-MSGV1.
*        ET_LOG-MESSAGE_V2 = iPROT-MSGV2.
*        ET_LOG-MESSAGE_V3 = iPROT-MSGV3.
*        ET_LOG-MESSAGE_V4 = iPROT-MSGV4.
*        ET_LOG-LOG_NO = iPROT-VBELN.
*        APPEND ET_LOG.
*      ENDLOOP.
*    ENDIF.
CLEAR IP_WBSTK.
SELECT SINGLE WBSTK INTO IP_WBSTK FROM VBUK WHERE VBELN = IP_VBELN.
*****查找数据库,是否过帐成功
    ET_LOG-ID = IP_VBELN.
IF IP_WBSTK = 'C'. "过帐成功
      ITAB_RETURN-SUBRC = 0.
      ET_LOG-TYPE = 'W'.
      ET_LOG-MESSAGE = ' 恭喜,过账成功!'.
ELSE. "过帐失败
      ITAB_RETURN-SUBRC = -1.
      ET_LOG-TYPE = 'E'.
      ET_LOG-MESSAGE = ' 过账失败!'.
ENDIF.
CONCATENATE IP_VBELN ET_LOG-MESSAGE  INTO ET_LOG-MESSAGE.
APPEND ET_LOG.
    ITAB_RETURN-MSG = ET_LOG-MESSAGE.
APPEND ITAB_RETURN.
WAIT UP TO 1 SECONDS.
ENDLOOP.
ENDFUNCTION.

标签:BAPI,LOG,VBELN,WMS,IP,ITAB,LIPS,交货单,ET
来源: https://www.cnblogs.com/twttafku/p/14344399.html