其他分享
首页 > 其他分享> > WMS函数组:9.交货单过帐3(BDC)

WMS函数组:9.交货单过帐3(BDC)

作者:互联网

FUNCTION ZRFC_WMS_DELIVERY_UPDATE2.
*"----------------------------------------------------------------------
*"*"本地接口:
*"  IMPORTING
*"     VALUE(MODE) LIKE  APQI-PUTACTIVE DEFAULT 'N'
*"  TABLES
*"      ITAB_HEADER STRUCTURE  ZVBKOK OPTIONAL
*"      ITAB_DETAIL STRUCTURE  ZVBPOK OPTIONAL
*"      ITAB_RETURN STRUCTURE  ZINTERFACE_RETURN OPTIONAL
*"      ET_LOG STRUCTURE  BAPIRET2 OPTIONAL
*"----------------------------------------------------------------------



  DATA: IP_WBSTK      LIKE VBUK-WBSTK.
   DATA: T_LIPS LIKE LIPS OCCURS 0 WITH HEADER LINE.
   DATA: T_VTFA LIKE VTFA OCCURS 0 WITH HEADER LINE.

   DATA: ITAB_DETAIL2 LIKE ITAB_DETAIL OCCURS 0 WITH HEADER LINE.

   CHECK ITAB_HEADER[] IS NOT INITIAL.

  SORT ITAB_HEADER.
   DELETE ADJACENT DUPLICATES FROM ITAB_HEADER .





  LOOP AT ITAB_HEADER.



    PERFORM F_ADD_ZERO USING ITAB_HEADER-VBELN.

     ITAB_RETURN-BILLNO = ITAB_HEADER-WMS_NO.
    ITAB_RETURN-SAPNO = ITAB_HEADER-VBELN.
    ITAB_RETURN-SUBRC = '-1'.

*    **** 检查单据是否已经完成-START
     CLEAR IP_WBSTK.
    SELECT SINGLE WBSTK INTO IP_WBSTK FROM VBUK WHERE VBELN = ITAB_HEADER-VBELN..

     IF IP_WBSTK = 'C'.
      ITAB_RETURN-SUBRC = -1.
       ITAB_RETURN-MSG = '已经过账!'.
      APPEND ITAB_RETURN.
      DELETE ITAB_HEADER .
      CONTINUE.
    ENDIF.


***获取交货单子项目明细
    SELECT  VBELN POSNR MATNR SHKZG XCHPF UECHA LGORT
        WERKS LFIMG
       FROM   LIPS
    INTO CORRESPONDING FIELDS OF TABLE T_LIPS
     WHERE VBELN = ITAB_HEADER-VBELN.
***获取交货单子项目装箱明细
    SELECT  VBELV POSNV RFMNG
       FROM   VTFA
    INTO CORRESPONDING FIELDS OF TABLE T_VTFA
     WHERE VBELV = ITAB_HEADER-VBELN.
***已装箱明细不能更改数量,需要通知后手动更改
    LOOP AT T_LIPS.
      READ TABLE T_VTFA WITH KEY VBELV = T_LIPS-VBELN POSNV = T_LIPS-POSNR.
       IF SY-SUBRC = 0.
        CLEAR T_LIPS-XCHPF.
        MODIFY T_LIPS.
       ENDIF.
     ENDLOOP.

******* 公司间转储价检查

    DATA LP LIKE SY-SUBRC.
     DATA: ZLOG LIKE BAPIRET2 OCCURS 0 WITH HEADER LINE.
     CLEAR: LP , ZLOG[].

     CALL FUNCTION 'ZRFC_CHECK_ZPB2'
       EXPORTING
         IP_VBELN = ITAB_HEADER-VBELN
      IMPORTING
         EX_SUBRC = LP
       TABLES
         ET_LOG   = ZLOG
         LIPS     = T_LIPS.

     IF LP > 0.
      APPEND LINES OF ZLOG TO ET_LOG.
       ITAB_RETURN-SUBRC = -1.
       ITAB_RETURN-MSG = '公司间价格ZPB2不存在'.
      APPEND ITAB_RETURN.
      DELETE ITAB_HEADER .
      CONTINUE.
    ENDIF.



**汇总数据 1.删除WMS附赠物料.2.将子项目汇总到母项目
    LOOP AT ITAB_DETAIL WHERE VBELN = ITAB_HEADER-VBELN.
      PERFORM F_ADD_ZERO USING ITAB_DETAIL-POSNR.
       READ TABLE T_LIPS WITH KEY
         VBELN = ITAB_DETAIL-VBELN
           POSNR = ITAB_DETAIL-POSNR.

      IF SY-SUBRC = 0.
        IF T_LIPS-UECHA IS NOT INITIAL.
           ITAB_DETAIL-POSNR = T_LIPS-UECHA.
         ENDIF.
         MOVE T_LIPS-WERKS TO  ITAB_DETAIL-MX02.
         COLLECT ITAB_DETAIL INTO ITAB_DETAIL2.
       ELSE.
         ITAB_RETURN-SUBRC = -1.
         ITAB_RETURN-MSG = '行项目在交货单中不存在'.
        APPEND ITAB_RETURN.
         DELETE ITAB_HEADER .
      ENDIF.


    ENDLOOP.



*1.删除WMS附赠物料和删除行项目为0的数据
    LOOP AT ITAB_DETAIL2 WHERE VBELN = ITAB_HEADER-VBELN.
      PERFORM F_ADD_ZERO USING ITAB_DETAIL-POSNR.


       READ TABLE T_LIPS WITH KEY
           VBELN = ITAB_DETAIL-VBELN
             UECHA = ITAB_DETAIL2-POSNR.
      IF SY-SUBRC = 0.
        IF  T_LIPS-SHKZG = 'X'. "退货,和无批次同样处理
          CLEAR T_LIPS-XCHPF.
        ENDIF.
         MOVE T_LIPS-XCHPF TO ITAB_DETAIL2-MX01.
      ENDIF.



      SELECT SINGLE MATNR INTO ITAB_DETAIL2-MX03 FROM ZSDA35
                  WHERE MATNR = T_LIPS-MATNR.

       MODIFY ITAB_DETAIL2.

    ENDLOOP.

*"2.不能存在为0的交货单过帐,删除
    LOOP AT ITAB_DETAIL2 WHERE VBELN = ITAB_HEADER-VBELN AND LGMNG = 0.
       ITAB_RETURN-SUBRC = -1.
       ITAB_RETURN-MSG = '存在交货为0的行项目'.
      APPEND ITAB_RETURN.
      DELETE ITAB_HEADER .
      EXIT.
    ENDLOOP.


*3.判读SAP中存在 参数中不存在的行项目
    LOOP AT T_LIPS .
       IF T_LIPS-UECHA IS NOT INITIAL.
         T_LIPS-POSNR = T_LIPS-UECHA.
       ENDIF.

       READ TABLE ITAB_DETAIL2 WITH KEY VBELN = T_LIPS-VBELN POSNR = T_LIPS-POSNR.
       IF SY-SUBRC > 0.
         ITAB_RETURN-SUBRC = -1.
         ITAB_RETURN-MSG = '交货单行项目不够!'.
        APPEND ITAB_RETURN.
         DELETE ITAB_HEADER .
        EXIT.
       ENDIF.

     ENDLOOP. "T_lips

   ENDLOOP. " ITAB_HEADER


  CLEAR ITAB_RETURN-MSG.
  CLEAR ITAB_RETURN-SUBRC.



   CHECK ITAB_DETAIL2[] IS NOT INITIAL.
  CHECK ITAB_HEADER[] IS NOT INITIAL.
  CLEAR ITAB_DETAIL.
*  MOVE ITAB_DETAIL2[] TO ITAB_DETAIL[].
*  CLEAR ITAB_DETAIL2[].



   DATA: LF_VALUE(20).
  DATA: LF_NAME(50).
  DATA: LF_INDEX(2).
  DATA: LS_MCHB LIKE MCHB.
   DATA: LS_INDEX TYPE I.



  DATA: MESSTAB LIKE  BDCMSGCOLL OCCURS 0 WITH HEADER LINE.
   DATA: ET_LOG2 LIKE  BAPIRET2 OCCURS 0 WITH HEADER LINE.
   DATA:I_ERROR_MESSAGES  LIKE  ARRANG_ERR.
   DATA:CTU      LIKE  APQI-PUTACTIVE,
*       MODE     LIKE  APQI-PUTACTIVE,
        UPDATE   LIKE  APQI-PUTACTIVE,
        GROUP    LIKE  APQI-GROUPID,
        USER     LIKE  APQI-USERID,
        KEEP     LIKE  APQI-QERASE,
        HOLDDATE LIKE  APQI-STARTDATE,
        NODATA   LIKE  APQI-PUTACTIVE.


   CTU = 'X'.
   KEEP = 'X'.
*  MODE = 'A'.
  UPDATE = 'L'.
  NODATA = '/'.

**录屏改数据


  LOOP AT ITAB_HEADER.
     PERFORM BDC_NODATA      USING NODATA.
     PERFORM OPEN_GROUP       USING GROUP USER KEEP HOLDDATE CTU.

    PERFORM BDC_DYNPRO      USING 'SAPMV50A' '4004'.
     PERFORM BDC_FIELD       USING 'BDC_CURSOR'  'LIKP-VBELN'.
     PERFORM BDC_FIELD       USING 'BDC_OKCODE'  '/00'.
     PERFORM BDC_FIELD       USING 'LIKP-VBELN'  ITAB_HEADER-VBELN.
     PERFORM BDC_DYNPRO      USING 'SAPMV50A' '1000'.

     LOOP AT ITAB_DETAIL2 INTO ITAB_DETAIL WHERE VBELN = ITAB_HEADER-VBELN.

      PERFORM BDC_FIELD       USING 'BDC_OKCODE'  '=POPO_T'.
       PERFORM BDC_DYNPRO      USING 'SAPMV50A' '0111'.
       PERFORM BDC_FIELD       USING 'BDC_CURSOR'  'RV50A-POSNR'.
       PERFORM BDC_FIELD       USING 'BDC_OKCODE'  '=WEIT'.
       MOVE ITAB_DETAIL-POSNR TO LF_VALUE.
       SHIFT LF_VALUE LEFT DELETING LEADING SPACE.
       PERFORM BDC_FIELD       USING 'RV50A-POSNR'  LF_VALUE.

      PERFORM BDC_DYNPRO      USING 'SAPMV50A' '1000'.
       IF ITAB_DETAIL-MX01 = 'X' .
        PERFORM BDC_FIELD       USING 'BDC_OKCODE'  '=CHSP_T'.
         PERFORM BDC_DYNPRO      USING 'SAPMV50A' '3000'.
         PERFORM BDC_FIELD       USING 'BDC_OKCODE'  '=MKAL_T'.
         PERFORM BDC_DYNPRO      USING 'SAPMV50A' '3000'.
         PERFORM BDC_FIELD       USING 'BDC_OKCODE'  '=POLO_T'.
         PERFORM BDC_DYNPRO      USING 'SAPMV50A' '3000'.
         PERFORM BDC_FIELD       USING 'BDC_OKCODE'  '=BACK_T'.

         PERFORM BDC_DYNPRO      USING 'SAPMV50A' '1000'.
         PERFORM BDC_FIELD       USING 'RV50A-LIPS_SELKZ(01)'  'X'.
         PERFORM BDC_FIELD       USING 'BDC_OKCODE'  '=CHSP_T'.
*    PERFORM BDC_DYNPRO      USING 'SAPMV50A' '1000'.
       ENDIF.



       MOVE ITAB_DETAIL-LGMNG TO LF_VALUE.
       SHIFT LF_VALUE LEFT DELETING LEADING SPACE.
       PERFORM BDC_FIELD       USING 'LIPSD-G_LFIMG(01)'  LF_VALUE.
*      PERFORM BDC_FIELD       USING 'LIPS-LGORT(01)'  ITAB_DETAIL-LGORT.

       IF ITAB_DETAIL-MX01 = 'X' .


         IF ITAB_DETAIL-MX03 IS INITIAL.
           PERFORM BDC_DYNPRO      USING 'SAPMV50A' '3000'.
           PERFORM BDC_FIELD       USING 'BDC_OKCODE'  '=CHFD_T'.
         ENDIF.
         PERFORM BDC_DYNPRO      USING 'SAPMV50A' '3000'.
         PERFORM BDC_FIELD       USING 'BDC_OKCODE'  '=BACK_T'.

         IF ITAB_DETAIL-MX03 IS NOT INITIAL. "扣版业务

          LS_INDEX = 0.
           SELECT
             MATNR
             WERKS
             LGORT
             CHARG
             CLABS
             INTO CORRESPONDING FIELDS OF  LS_MCHB
             FROM MCHB
             WHERE MATNR = ITAB_DETAIL-MX03
               AND WERKS = ITAB_DETAIL-MX02
               AND LGORT = ITAB_DETAIL-LGORT
               AND CLABS > 0.
             CHECK ITAB_DETAIL-LGMNG > 0.
             LS_INDEX = LS_INDEX + 1.
             MOVE LS_INDEX TO LF_INDEX.
             PERFORM F_ADD_ZERO USING LF_INDEX.


             CONCATENATE 'LIPS-CHARG(' LF_INDEX ')' INTO LF_NAME.
             PERFORM BDC_FIELD  USING LF_NAME LS_MCHB-CHARG.
             CONCATENATE 'LIPS-LFIMG(' LF_INDEX ')' INTO LF_NAME.

             IF LS_MCHB-CLABS >= ITAB_DETAIL-LGMNG.

               MOVE ITAB_DETAIL-LGMNG TO LF_VALUE.
               SHIFT LF_VALUE LEFT DELETING LEADING SPACE.
               PERFORM BDC_FIELD  USING LF_NAME  LF_VALUE.
               ITAB_DETAIL-LGMNG = 0.

             ELSE.

               ITAB_DETAIL-LGMNG = ITAB_DETAIL-LGMNG -  LS_MCHB-CLABS.
               MOVE LS_MCHB-CLABS TO LF_VALUE.
               SHIFT LF_VALUE LEFT DELETING LEADING SPACE.
               PERFORM BDC_FIELD  USING LF_NAME  LF_VALUE.

             ENDIF.

             CLEAR LS_MCHB.
           ENDSELECT.

         ENDIF.


         PERFORM BDC_DYNPRO      USING 'SAPMV50A' '1000'.
       ENDIF.

       CLEAR ITAB_DETAIL.
     ENDLOOP. "itab_deatil




     PERFORM BDC_FIELD       USING 'BDC_OKCODE'  '=WABU_T'.


     CLEAR MESSTAB[].

    PERFORM BDC_TRANSACTION TABLES MESSTAB
    USING 'VL02N'
          CTU
          MODE
          UPDATE.
     PERFORM CLOSE_GROUP USING     CTU.

    CLEAR ET_LOG2.
     ITAB_RETURN-SUBRC = 0.
    LOOP AT MESSTAB. "WHERE MSGTYP = 'E'.
*      SUBRC = -1.
       CLEAR    :  I_ERROR_MESSAGES.
       I_ERROR_MESSAGES-MSGID  = MESSTAB-MSGID.
       I_ERROR_MESSAGES-MSGTY  = MESSTAB-MSGTYP.
       I_ERROR_MESSAGES-MSGNO  = MESSTAB-MSGNR.
       I_ERROR_MESSAGES-MSGV1  = MESSTAB-MSGV1.
       I_ERROR_MESSAGES-MSGV2  = MESSTAB-MSGV2.
       I_ERROR_MESSAGES-MSGV3  = MESSTAB-MSGV3.
       I_ERROR_MESSAGES-MSGV4  = MESSTAB-MSGV4.
       ET_LOG2-TYPE             = MESSTAB-MSGTYP.
      ET_LOG2-ID               = MESSTAB-MSGID.
       ET_LOG2-NUMBER           = MESSTAB-MSGNR.
       MOVE ITAB_HEADER-VBELN TO ET_LOG2-MESSAGE_V1 .
       CALL FUNCTION 'MM_ARRANG_GET_MESSAGE_TEXT'
         EXPORTING
           I_ERROR_MESSAGES = I_ERROR_MESSAGES
           I_LANGU          = SY-LANGU
         IMPORTING
           E_TEXT           = ET_LOG2-MESSAGE
         EXCEPTIONS
           PARAMETER_ERROR  = 1
           OTHERS           = 2.

      IF MESSTAB-MSGTYP = 'E'.
         ITAB_RETURN-SUBRC = -1.
         WRITE / ET_LOG-MESSAGE.

       ENDIF.

       APPEND ET_LOG2 TO ET_LOG.
       CLEAR:ET_LOG2[],ET_LOG2..
    ENDLOOP. " messagetab

     ITAB_RETURN-BILLNO = ITAB_HEADER-WMS_NO.
    ITAB_RETURN-SAPNO = ITAB_HEADER-VBELN.


    SELECT SINGLE WBSTK INTO IP_WBSTK FROM VBUK WHERE VBELN = ITAB_HEADER-VBELN..

     IF IP_WBSTK = 'C'.
      ITAB_RETURN-SUBRC = 0.
      ITAB_RETURN-MSG = '过帐完成!'.
    ELSE.
       ITAB_RETURN-SUBRC = -1.
       ITAB_RETURN-MSG = '过帐失败!'.
    ENDIF.



     APPEND ITAB_RETURN.

  ENDLOOP. "itab_header



*  INCLUDE BDCRECXY.


*  INCLUDE ZRPT_FUN.

ENDFUNCTION.

标签:ITAB,BDC,HEADER,WMS,VBELN,PERFORM,交货单,USING
来源: https://www.cnblogs.com/twttafku/p/14315980.html