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

ZIFR0001 WMS 中型仓接口优化- outBound 输出类型 处理程序

 

NAST  进入输出控制  找到V1  交货单输出

 

 

 

 

 

 

 

 

第一步,输出类型里配置上IDOC输出的 处理程序和FORM

第二步,创建处理程序,程序名和FORM 名称和配置一致
报表      ZIFR0001

FORM frm_entry USING return_code screen_flag .
注意:这个FORM找不到所用处

第三步,FORM中写处理逻辑
*&---------------------------------------------------------------------*
*
*        MAIN PROGRAM
*
*----------------------------------------------------------------------*
FORM frm_entry USING return_code screen_flag .

*DATA IS_NAST  TYPE NAST.
*DATA CV_SUBRC TYPE SYST_SUBRC.



  CALL FUNCTION 'ZIFFM0001'
    EXPORTING
      is_nast  = nast
    IMPORTING
      cv_subrc = return_code.

ENDFORM .

 

 

ZIFR0001  主程序代码

*&---------------------------------------------------------------------*
*& Report ZIFR0001
*&---------------------------------------------------------------------*
*&
*&---------------------------------------------------------------------*
REPORT zifr0001.



*&---------------------------------------------------------------------*
* TABLES
*&---------------------------------------------------------------------*
TABLES:nast .
*&---------------------------------------------------------------------*
* GLOBAL DATA
*&---------------------------------------------------------------------*
DATA:gv_subrc LIKE sy-subrc       . " Return Code
DATA:gv_zywcj TYPE zmmt0018-zywcj .

*&---------------------------------------------------------------------*
*
*        MAIN PROGRAM
*
*----------------------------------------------------------------------*
FORM frm_entry USING return_code screen_flag .

*DATA IS_NAST  TYPE NAST.
*DATA CV_SUBRC TYPE SYST_SUBRC.



  CALL FUNCTION 'ZIFFM0001'
    EXPORTING
      is_nast  = nast
    IMPORTING
      cv_subrc = return_code.

ENDFORM .
View Code

 

函数模块             ZIFFM0001

FUNCTION ziffm0001.
*"----------------------------------------------------------------------
*"*"本地接口:
*"  IMPORTING
*"     VALUE(IS_NAST) TYPE  NAST
*"  EXPORTING
*"     VALUE(CV_SUBRC) TYPE  SY-SUBRC
*"----------------------------------------------------------------------

  DATA et_return   TYPE TABLE OF bapiret2.
  DATA et_pro_stru TYPE TABLE OF zif_pro_structure.
  DATA lt_bapiret2 TYPE TABLE OF bapiret2.
  DATA
    : lv_sec      TYPE f VALUE '0.1'
    , lv_mess          TYPE c LENGTH 80
    .

  "---------------------------------------------
  CLEAR cv_subrc.

  CALL FUNCTION 'ZIF_GET_BILLTYPE'
    EXPORTING
      is_nast     = is_nast
    TABLES
      et_return   = et_return
      et_pro_stru = et_pro_stru
    EXCEPTIONS
      btdet_error = 1.

  LOOP AT et_return INTO DATA(ls_return).
    IF ls_return-type CA 'AXE'.
      cv_subrc = 1.
    ENDIF.
  ENDLOOP.
  IF cv_subrc = 1.
    PERFORM frm_nast_update USING et_return.
    RETURN.
  ENDIF.

  "---------------------------------------------

  DELETE et_pro_stru WHERE kschl <> is_nast-kschl.
  IF et_pro_stru IS INITIAL .
    "cv_subrc = 1.
    lt_bapiret2 = VALUE #( ( id         = 'ZIF001'
                             number     = '001'
                             type       = 'E'
                             message_v1 = IS_NAST-OBJKY
                             message_v2 = ''
                             message_v3 = ''
                             message_v4 = ''  )
                          ).
    PERFORM frm_nast_update USING lt_bapiret2.
    RETURN.
  ENDIF.

  "---------------------------------------------

  LOOP AT et_pro_stru INTO DATA(ls_pro).
    CLEAR:gt_bapiret2[], gv_done.

    SELECT SINGLE zfunc_module
      INTO @DATA(lv_funcname)
      FROM zift0002
     WHERE zproid = @ls_pro-zproid .
    IF sy-subrc <> 0 OR lv_funcname IS INITIAL .
      "--- 个ZIFT0002未配置输出类型 &1 的处理函数

      "cv_subrc = 1.
      lt_bapiret2 = VALUE #( ( id         = 'ZIF001'
                               number     = '002'
                               type       = 'E'
                               message_v1 = ls_pro-zproid
                               message_v2 = ''
                               message_v3 = ''
                               message_v4 = ''  )  ).
      PERFORM frm_nast_update USING lt_bapiret2.
    ELSE.


      CALL FUNCTION 'ZIF_FUNC_CALL' STARTING NEW TASK is_nast-objky
        PERFORMING frm_function_recevie_data ON END OF TASK
        EXPORTING
          iv_funcname = lv_funcname
          iv_zproid   = ls_pro-zproid
          is_nast     = is_nast
        TABLES
          rt_bapiret2 = lt_bapiret2[].


*      TRY .
*
*          CALL FUNCTION lv_funcname  IN UPDATE TASK
*            EXPORTING
*              is_nast               = is_nast
*              iv_zproid             = ls_pro-zproid
*            TABLES
*              et_return             = lt_bapiret2[]
*              .
*
*        CATCH cx_root INTO DATA(lr_exception).
*          "--- 输出类型 &1 处理函数调用异常:&2
*
*          cv_subrc = 1.
*          lt_bapiret2  = VALUE #( ( id        = 'ZIF001'
*                                   number     = '003'
*                                   type       = 'E'
*                                   message_v1 = is_nast-kappl
*                                   message_v2 = lr_exception->get_text( )
*                                   message_v3 = ''
*                                   message_v4 = ''   )
*
*                                  ( id        = 'ZIF001'
*                                   number     = '003'
*                                   type       = 'E'
*                                   message_v1 = is_nast-kappl
*                                   message_v2 = lv_funcname
*                                   message_v3 = ''
*                                   message_v4 = ''   )
*
*
*
*
*                                    ).
*
*      ENDTRY.


      WAIT FOR ASYNCHRONOUS TASKS UNTIL  gv_done = 'X'.

      LOOP AT gt_bapiret2 INTO gs_bapiret2.
        IF gs_bapiret2-type CA 'AXE'.
          cv_subrc = 1.
        ENDIF.
      ENDLOOP.

      PERFORM frm_nast_update USING gt_bapiret2.
    ENDIF.

  ENDLOOP.


  IF cv_subrc <> 1.
    cv_subrc = 0.
  ENDIF.

ENDFUNCTION.
View Code

 

 函数模块             ZIF_GET_BILLTYPE

FUNCTION ZIF_GET_BILLTYPE.
*"----------------------------------------------------------------------
*"*"本地接口:
*"  IMPORTING
*"     VALUE(IS_NAST) TYPE  NAST
*"     REFERENCE(IV_KSCHLX) TYPE  CHAR1 DEFAULT 'X'
*"  TABLES
*"      ET_RETURN STRUCTURE  BAPIRET2
*"      ET_PRO_STRU STRUCTURE  ZIF_PRO_STRUCTURE
*"  EXCEPTIONS
*"      BTDET_ERROR
*"----------------------------------------------------------------------
  DATA LS_EKKO TYPE EKKO.
  DATA LS_LIKP TYPE LIKP.
  DATA LS_VBAK TYPE VBAK.
  DATA LS_MKPF TYPE MKPF.
  DATA ES_RETURN LIKE LINE OF ET_RETURN.

  DEFINE RETURN_MES.
    CLEAR es_return.
    es_return-type = 'E'.
    es_return-id = 'ZIF001'.
    es_return-number = '001'.
    es_return-message_v1 = &1.
    es_return-message_v2 = &2.
    es_return-message_v3 = ''.
    es_return-message_v4 = ''.
    APPEND es_return TO et_return.
  END-OF-DEFINITION.


  CLEAR :LS_EKKO,LS_LIKP,LS_MKPF.
  CASE IS_NAST-KAPPL.
    WHEN 'EF'."采购订单
      SELECT SINGLE * INTO CORRESPONDING FIELDS OF LS_EKKO FROM EKKO WHERE EBELN = IS_NAST-OBJKY.
      IF SY-SUBRC <> 0 .
        RETURN_MES IS_NAST-OBJKY 'EKKO'.RETURN.
      ENDIF.
      PERFORM FRM_EKKO(SAPLZIFFG0001) TABLES ET_RETURN
                                             ET_PRO_STRU
                                      USING LS_EKKO-EBELN
                                            IS_NAST-KSCHL
                                            IV_KSCHLX.


    WHEN 'V2'."交货订单
      SELECT SINGLE * INTO CORRESPONDING FIELDS OF LS_LIKP FROM LIKP WHERE VBELN = IS_NAST-OBJKY.
      IF SY-SUBRC <> 0 .
        RETURN_MES IS_NAST-OBJKY 'LIKP'.RETURN.
      ENDIF.
      PERFORM FRM_LIKP(SAPLZIFFG0001) TABLES ET_RETURN
                                             ET_PRO_STRU
                                      USING LS_LIKP-VBELN
                                            IS_NAST-KSCHL
                                            IV_KSCHLX.
    WHEN 'V1'."销售订单
      SELECT SINGLE * INTO CORRESPONDING FIELDS OF LS_VBAK FROM VBAK WHERE VBELN = IS_NAST-OBJKY.
      IF SY-SUBRC <> 0 .
        RETURN_MES IS_NAST-OBJKY 'VBAK'.RETURN.
      ENDIF.
      PERFORM FRM_VBAK(SAPLZIFFG0001) TABLES ET_RETURN
                                             ET_PRO_STRU
                                       USING LS_VBAK-VBELN
                                             IS_NAST-KSCHL
                                             IV_KSCHLX.
    WHEN 'ME'."物料凭证
      SELECT SINGLE * INTO CORRESPONDING FIELDS OF LS_MKPF FROM MKPF WHERE MBLNR = IS_NAST-OBJKY+0(10) AND MJAHR = IS_NAST-OBJKY+10(4).
      IF SY-SUBRC <> 0 .
        RETURN_MES IS_NAST-OBJKY 'MKPF'.RETURN.
      ENDIF.
      PERFORM FRM_MKPF(SAPLZIFFG0001)  TABLES ET_RETURN
                                              ET_PRO_STRU
                                        USING LS_MKPF-MBLNR
                                              LS_MKPF-MJAHR
                                              IS_NAST-KSCHL
                                              IV_KSCHLX.
    WHEN OTHERS.
      CLEAR ES_RETURN.
      ES_RETURN-TYPE = 'E'.
      ES_RETURN-ID = 'ZIF001'.
      ES_RETURN-NUMBER = '000'.
      ES_RETURN-MESSAGE_V1 = 'IS_NAST-KAPPL:'.
      ES_RETURN-MESSAGE_V2 = IS_NAST-KAPPL.
      ES_RETURN-MESSAGE_V3 = ',未维护处理代码,在'.
      ES_RETURN-MESSAGE_V4 = 'ZIF_GET_BILLTYPE中'.
      APPEND ES_RETURN TO ET_RETURN.
      RETURN.
  ENDCASE.

ENDFUNCTION.

FORM FRM_EKKO TABLES ET_RETURN  STRUCTURE BAPIRET2
                     ET_PRO_STRU STRUCTURE ZIF_PRO_STRUCTURE
                USING IV_EBELN      TYPE EBELN
                      IV_KSCHL      TYPE KSCHL
                      IV_FLAG       TYPE CHAR1.

  DATA ES_PRO_STRU LIKE LINE OF ET_PRO_STRU.
  DATA :BEGIN OF LS_EKKO,
          BUKRS   LIKE EKKO-BUKRS,
          EBELN   LIKE EKKO-EBELN,
          BSART   LIKE EKKO-BSART,
          RESWK   LIKE EKKO-RESWK,
          ZMDSQ   LIKE EKKO-ZZZMDSQ,
          ZWLMS   LIKE EKKO-ZZZWLMS,
          ZZZSHD  LIKE EKKO-ZZZZSHD,
          ZZQXDJH LIKE EKKO-ZZQXDJH,
          WERKS   LIKE EKPO-WERKS,
          VLFKZ   LIKE T001W-VLFKZ,
        END OF LS_EKKO.

  DATA LS_ZIFT0004 TYPE ZIFT0004.
  DATA LT_ZIFT0004 LIKE TABLE OF LS_ZIFT0004.

  DATA : R_BSART TYPE RANGE OF EKKO-BSART.

  R_BSART = VALUE #( ( SIGN = 'I' OPTION = 'EQ' LOW = 'Z008' HIGH = '' )
                     ( SIGN = 'I' OPTION = 'EQ' LOW = 'Z009' HIGH = '' ) ).

  SELECT SINGLE T~BUKRS
                T~EBELN
                T~BSART
                T~RESWK
                T~ZZZMDSQ AS ZMDSQ
                T~ZZZWLMS AS ZWLMS
                T~ZZZZSHD AS ZZZSHD
                T1~WERKS
                T~ZZQXDJH
                T2~VLFKZ INTO CORRESPONDING FIELDS OF LS_EKKO
     FROM EKKO AS T INNER JOIN EKPO AS T1 ON T~EBELN = T1~EBELN
    INNER JOIN T001W AS T2 ON T1~WERKS = T2~WERKS
    WHERE T~EBELN = IV_EBELN.

  SELECT * INTO CORRESPONDING FIELDS OF TABLE LT_ZIFT0004 FROM ZIFT0004 WHERE BSART = LS_EKKO-BSART." AND KSCHL = IV_KSCHL.
  IF SY-SUBRC <> 0.
    CLEAR ET_RETURN.
    ET_RETURN-TYPE = 'E'.
    ET_RETURN-ID = 'ZIF001'.
    ET_RETURN-NUMBER = '000'.
    ET_RETURN-MESSAGE_V1 = 'zift0004:'.
    ET_RETURN-MESSAGE_V2 = '没有配置任何流程编号检索规则'.
    ET_RETURN-MESSAGE_V3 = ''.
    ET_RETURN-MESSAGE_V4 = ''.
    APPEND ET_RETURN .
    RETURN.
  ENDIF.

  DATA LV_ZZSHD_VLFKZ TYPE T001W-VLFKZ."最终收货地点,工厂类别。
  DATA LS_ZIFT0002    TYPE ZIFT0002."前序订单类型。
  DATA LV_ZIF_B2B     TYPE ZMMT0085-PURREQNO."统采平台订单号。
  DATA LV_ZSJBM       TYPE ZSDT0014-ZSJBM."上级DC。
  DATA LV_LOCLB       TYPE WRF3-LOCLB."供货工厂.
  "-----------------------------------------------------------------
  DATA MT_RETURN   TYPE TABLE OF BAPIRET2 WITH HEADER LINE.
  DATA MT_PRO_STRU TYPE TABLE OF ZIF_PRO_STRUCTURE WITH HEADER LINE.
  "-----------------------------------------------------------------

  LOOP AT LT_ZIFT0004 INTO LS_ZIFT0004.
    "IV_FLAG <> 'X'时,此时是检查是否该单据号包含单据流程。IV_FLAG = 'X'时取满足IV_KSCHL的流程编号。
    IF IV_FLAG = 'X' AND LS_ZIFT0004-KSCHL <> IV_KSCHL.
      CONTINUE.
    ENDIF.

    "检查物流模式是否为空,9,不检查,1,为空,2,不为空
    IF LS_ZIFT0004-ZIFWLMS <> '9'.
      IF LS_ZIFT0004-ZIFWLMS = '1' AND LS_EKKO-ZWLMS IS NOT INITIAL.
        CONTINUE.
      ELSEIF LS_ZIFT0004-ZIFWLMS = '2' AND LS_EKKO-ZWLMS IS INITIAL.
        CONTINUE.
      ENDIF.
    ENDIF.
    "物流模式不为空时,检查物流模式
    IF LS_ZIFT0004-ZIFWLMS = '2' AND LS_ZIFT0004-ZZWLMS <> LS_EKKO-ZWLMS.
      CONTINUE.
    ENDIF.
    "检查行项目工厂类别,9,不检查,A,门店,B,配送中心DC.
    IF LS_ZIFT0004-VLFKZ <> '9' AND LS_ZIFT0004-VLFKZ <> LS_EKKO-VLFKZ.
      CONTINUE.
    ENDIF.
    "检查最终收货地点是否为空,9,不检查,1,为空,2,不为空。
    IF LS_ZIFT0004-ZZSHD <> '9' .
      IF LS_ZIFT0004-ZZSHD = '1' AND LS_EKKO-ZZZSHD IS NOT INITIAL.
        CONTINUE.
      ELSEIF LS_ZIFT0004-ZZSHD = '2' AND LS_EKKO-ZZZSHD IS INITIAL.
        CONTINUE.
      ENDIF.
    ENDIF.
    "最终收货地点不为空时,检查最终收货地点的工厂类别,9,不检查,A,门店,B,配送中心DC。
    IF LS_ZIFT0004-ZZSHD = '2' AND LS_ZIFT0004-VLFKZ1 <> '9' .
      CLEAR LV_ZZSHD_VLFKZ.
      SELECT SINGLE VLFKZ INTO LV_ZZSHD_VLFKZ FROM T001W WHERE WERKS = LS_EKKO-ZZZSHD AND VLFKZ = LS_ZIFT0004-VLFKZ1.
      IF SY-SUBRC <> 0.
        CONTINUE.
      ENDIF.
    ENDIF.
    "检查前序订单是否为空,9,不检查,1,为空,2,不为空。
    IF LS_ZIFT0004-ZIF_EBELN <> '9' .
      IF LS_ZIFT0004-ZIF_EBELN = '1' AND LS_EKKO-ZZQXDJH IS NOT INITIAL .
        CONTINUE.
      ELSEIF LS_ZIFT0004-ZIF_EBELN = '2' AND LS_EKKO-ZZQXDJH IS INITIAL.
        CONTINUE.
      ENDIF.
    ENDIF.
    "前序订单不为空时,检查前序订单的单据类型。
    IF LS_ZIFT0004-ZIF_EBELN = '2'.
      IF LS_ZIFT0004-ZPROID_V IS INITIAL.
        CONTINUE.
      ENDIF.
      CLEAR LS_ZIFT0002.
      SELECT SINGLE * INTO CORRESPONDING FIELDS OF LS_ZIFT0002  FROM ZIFT0002 WHERE ZPROID = LS_ZIFT0004-ZPROID_V.
      IF SY-SUBRC <> 0.
        CONTINUE.
      ENDIF.
      CASE LS_ZIFT0002-ZORDER_TYP.
        WHEN 1." 采购订单
          REFRESH: MT_RETURN,MT_PRO_STRU.
          PERFORM FRM_EKKO(SAPLZIFFG0001)
                 TABLES MT_RETURN
                        MT_PRO_STRU
                 USING LS_EKKO-ZZQXDJH
                       ''
                       ''.
          IF MT_PRO_STRU[] IS INITIAL.
            CONTINUE.
          ENDIF.
          LOOP AT MT_PRO_STRU WHERE ZPROID = LS_ZIFT0004-ZPROID_V.
            EXIT.
          ENDLOOP.
          IF SY-SUBRC <> 0.
            CONTINUE.
          ENDIF.
        WHEN 2."交货单
          REFRESH: MT_RETURN,MT_PRO_STRU.
          PERFORM FRM_LIKP(SAPLZIFFG0001)
                 TABLES MT_RETURN
                        MT_PRO_STRU
                 USING LS_EKKO-ZZQXDJH
                       ''
                       ''.
          IF MT_PRO_STRU[] IS INITIAL.
            CONTINUE.
          ENDIF.
          LOOP AT MT_PRO_STRU WHERE ZPROID = LS_ZIFT0004-ZPROID_V.
            EXIT.
          ENDLOOP.
          IF SY-SUBRC <> 0.
            CONTINUE.
          ENDIF.
        WHEN 3."销售订单、、、目前没有这种业务
          CONTINUE.
        WHEN 4."物料凭证、、、目前没有这种业务
          CONTINUE.
        WHEN OTHERS.
          CONTINUE.
      ENDCASE.
    ENDIF.
    "检查门店申请单号是否为空,9,不检查,1,为空,2,不为空。
    IF LS_ZIFT0004-ZIF_MDSQ <> '9' .
      IF LS_ZIFT0004-ZIF_MDSQ = '1' AND LS_EKKO-ZMDSQ IS NOT INITIAL .
        CONTINUE.
      ELSEIF LS_ZIFT0004-ZIF_MDSQ = '2' AND LS_EKKO-ZMDSQ IS INITIAL.
        CONTINUE.
      ENDIF.
    ENDIF.
    "检查是否B2B发送的订单,这里检查的是指统集采订单。ZMMT0085表中存在的单据。
    IF LS_ZIFT0004-ZIF_B2B  <> '9' AND LS_ZIFT0004-ZIF_MDSQ = 0.
      CLEAR LV_ZIF_B2B.
      SELECT SINGLE PURREQNO INTO  LV_ZIF_B2B FROM ZMMT0085 WHERE PURREQNO = LS_EKKO-ZMDSQ.
      IF SY-SUBRC = 0 .
        IF LS_ZIFT0004-ZIF_B2B = '2'.
          CONTINUE.
        ENDIF.
      ELSE.
        IF LS_ZIFT0004-ZIF_B2B = '1'.
          CONTINUE.
        ENDIF.
      ENDIF.
    ENDIF.

    "检查是否委托配送模式。这里检查的委托配送模式,是指是否瑞康门店的形式。
    IF LS_ZIFT0004-ZIF_WTPS <> '9'AND LS_ZIFT0004-ZZSHD = '2'.
      CLEAR :LV_ZSJBM,LV_LOCLB.
      IF LS_EKKO-BSART IN R_BSART.
        "Z008/Z009类型的订单直接判断行项目门店的编码是否委托配送的门店,此处委托配送的门店判断依据为上级DC和供货工厂是否一致
        SELECT SINGLE T1~ZSJBM T2~LOCLB INTO (LV_ZSJBM, LV_LOCLB)
          FROM T001W AS T INNER JOIN ZSDT0014 AS T1 ON T~WERKS = T1~LOCNR
         INNER JOIN WRF3 AS T2 ON T~KUNNR = T2~LOCNR
         WHERE T~WERKS = LS_EKKO-WERKS.
        IF LS_ZIFT0004-ZIF_WTPS = '1' AND LV_ZSJBM = LV_LOCLB.
          CONTINUE.
        ELSEIF LS_ZIFT0004-ZIF_WTPS = '2' AND LV_ZSJBM <> LV_LOCLB.
          CONTINUE.
        ENDIF.
      ELSE.
        SELECT SINGLE T1~ZSJBM T2~LOCLB INTO (LV_ZSJBM, LV_LOCLB)
          FROM T001W AS T INNER JOIN ZSDT0014 AS T1 ON T~WERKS = T1~LOCNR
         INNER JOIN WRF3 AS T2 ON T~KUNNR = T2~LOCNR
         WHERE T~WERKS = LS_EKKO-ZZZSHD.
        IF LS_ZIFT0004-ZIF_WTPS = '1' AND LV_ZSJBM = LV_LOCLB.
          CONTINUE.
        ELSEIF LS_ZIFT0004-ZIF_WTPS = '2' AND LV_ZSJBM <> LV_LOCLB.
          CONTINUE.
        ENDIF.
      ENDIF.


    ENDIF.
    "是否第三方物流。这里检查的第三方物流,不包括华为模式。
    IF LS_ZIFT0004-ZIF_3PL <> '9'.
      SELECT COUNT(*) FROM ZMMT0122 WHERE BUKRS = LS_EKKO-BUKRS.
      IF SY-SUBRC = 0 AND LS_ZIFT0004-ZIF_3PL = '2'.
        CONTINUE.
      ELSEIF SY-SUBRC <> 0 AND LS_ZIFT0004-ZIF_3PL = '1'.
        CONTINUE.
      ENDIF.
    ENDIF.

***    "是否华为模式。
***    IF ls_zift0004-zif_hw3pl <> '9'.
***      SELECT COUNT(*) FROM zmmt0151 WHERE bukrs = ls_ekko-bukrs.
***      IF sy-subrc = 0 .
***        IF ls_zift0004-zif_hw3pl = '2'.
***          CONTINUE.
***        ENDIF.
***      ELSE.
***        IF ls_zift0004-zif_hw3pl = '1'.
***          CONTINUE.
***        ENDIF.
***      ENDIF.
***    ENDIF.

    CLEAR ES_PRO_STRU.
    ES_PRO_STRU-ZPROID = LS_ZIFT0004-ZPROID.
    ES_PRO_STRU-KSCHL = LS_ZIFT0004-KSCHL.
    ES_PRO_STRU-DATYPE = LS_ZIFT0004-DATYPE.
    APPEND ES_PRO_STRU TO ET_PRO_STRU.

  ENDLOOP.
ENDFORM.

FORM FRM_LIKP TABLES ET_RETURN STRUCTURE BAPIRET2
                      ET_PRO_STRU STRUCTURE ZIF_PRO_STRUCTURE
                USING IV_VBELN     TYPE      VBELN
                      IV_KSCHL     TYPE      KSCHL
                      IV_FLAG      TYPE      CHAR1.
  DATA ES_PRO_STRU LIKE LINE OF ET_PRO_STRU.
  DATA:BEGIN OF LS_LIKP,
         LFART LIKE LIKP-LFART,
         WBSTK LIKE LIKP-WBSTK,
         VGBEL LIKE LIPS-VGBEL,
         VGTYP LIKE LIPS-VGTYP,
       END OF LS_LIKP.
  DATA LT_LIKP LIKE TABLE OF LS_LIKP.

  DATA LS_ZIFT0005 TYPE ZIFT0005.
  DATA LT_ZIFT0005 LIKE TABLE OF LS_ZIFT0005.

  "-----------------------------------------------------------------
  DATA MT_RETURN   TYPE TABLE OF BAPIRET2 WITH HEADER LINE.
  DATA MT_PRO_STRU TYPE TABLE OF ZIF_PRO_STRUCTURE WITH HEADER LINE.
  "-----------------------------------------------------------------

  SELECT DISTINCT
        T~LFART
        T~WBSTK
        T1~VGTYP
        T1~VGBEL INTO CORRESPONDING FIELDS OF TABLE LT_LIKP
    FROM LIKP AS T
    INNER JOIN LIPS AS T1 ON T~VBELN = T1~VBELN
  WHERE T~VBELN = IV_VBELN.

  SELECT * INTO CORRESPONDING FIELDS OF TABLE LT_ZIFT0005 FROM ZIFT0005.
  IF SY-SUBRC <> 0.
    CLEAR ET_RETURN.
    ET_RETURN-TYPE = 'E'.
    ET_RETURN-ID = 'ZIF001'.
    ET_RETURN-NUMBER = '000'.
    ET_RETURN-MESSAGE_V1 = 'ZIFT0005:'.
    ET_RETURN-MESSAGE_V2 = '没有配置任何流程编号检索规则'.
    ET_RETURN-MESSAGE_V3 = ''.
    ET_RETURN-MESSAGE_V4 = ''.
    APPEND ET_RETURN .
    RETURN.
  ENDIF.

  LOOP AT LT_LIKP INTO LS_LIKP.
    LOOP AT LT_ZIFT0005 INTO LS_ZIFT0005 WHERE LFART = LS_LIKP-LFART.
      "IV_FLAG <> 'X'时,此时是检查是否该单据号包含单据流程。IV_FLAG = 'X'时取满足IV_KSCHL的流程编号。
      IF IV_FLAG = 'X' AND LS_ZIFT0005-KSCHL <> IV_KSCHL.
        CONTINUE.
      ENDIF.
      "参考订单类型
      IF LS_ZIFT0005-VGTYP <> LS_LIKP-VGTYP.
        CONTINUE.
      ENDIF.
      "参考订单流程编号
      IF LS_LIKP-VGBEL IS INITIAL.
        CONTINUE.
      ELSE.
        CASE LS_ZIFT0005-VGTYP.
          WHEN 'C' OR 'H'."销售订单/销售退货订单
            REFRESH: MT_RETURN,MT_PRO_STRU.
            PERFORM FRM_VBAK(SAPLZIFFG0001)
                   TABLES MT_RETURN
                          MT_PRO_STRU
                   USING LS_LIKP-VGBEL
                         ''
                         ''.
            IF MT_PRO_STRU[] IS INITIAL.
              CONTINUE.
            ENDIF.
            LOOP AT MT_PRO_STRU WHERE ZPROID = LS_ZIFT0005-ZPROID_V.
              EXIT.
            ENDLOOP.
            IF SY-SUBRC <> 0.
              CONTINUE.
            ENDIF.
          WHEN 'V'."采购订单
            REFRESH: MT_RETURN,MT_PRO_STRU.
            PERFORM FRM_EKKO(SAPLZIFFG0001)
                   TABLES MT_RETURN
                          MT_PRO_STRU
                   USING LS_LIKP-VGBEL
                         ''
                         ''.
            IF MT_PRO_STRU[] IS INITIAL.
              CONTINUE.
            ENDIF.
            LOOP AT MT_PRO_STRU WHERE ZPROID = LS_ZIFT0005-ZPROID_V.
              EXIT.
            ENDLOOP.
            IF SY-SUBRC <> 0.
              CONTINUE.
            ENDIF.
          WHEN OTHERS.
            CONTINUE.
        ENDCASE.
      ENDIF.

      CLEAR ES_PRO_STRU.
      ES_PRO_STRU-ZPROID = LS_ZIFT0005-ZPROID.
      ES_PRO_STRU-KSCHL = LS_ZIFT0005-KSCHL.
      ES_PRO_STRU-DATYPE = LS_ZIFT0005-DATYPE.
      APPEND ES_PRO_STRU TO ET_PRO_STRU.
    ENDLOOP.
  ENDLOOP.
ENDFORM.

FORM FRM_VBAK TABLES ET_RETURN STRUCTURE BAPIRET2
                     ET_PRO_STRU STRUCTURE ZIF_PRO_STRUCTURE
                USING IV_VBELN  TYPE      VBELN
                      IV_KSCHL     TYPE      KSCHL
                      IV_FLAG   TYPE      CHAR1.

  DATA ES_PRO_STRU LIKE LINE OF ET_PRO_STRU.
  DATA :BEGIN OF LS_VBAK,
          VBELN LIKE VBAK-VBELN,
          AUART LIKE VBAK-AUART,
          BSTNK LIKE VBAK-BSTNK,
          KUNNR LIKE VBAK-KUNNR,
        END OF LS_VBAK.

  DATA LS_ZIFT0007 TYPE ZIFT0007.
  DATA LT_ZIFT0007 LIKE TABLE OF LS_ZIFT0007.

  SELECT SINGLE * INTO CORRESPONDING FIELDS OF LS_VBAK FROM VBAK WHERE VBELN = IV_VBELN.

  SELECT * INTO CORRESPONDING FIELDS OF TABLE LT_ZIFT0007 FROM ZIFT0007.
  IF SY-SUBRC <> 0.
    CLEAR ET_RETURN.
    ET_RETURN-TYPE = 'E'.
    ET_RETURN-ID = 'ZIF001'.
    ET_RETURN-NUMBER = '000'.
    ET_RETURN-MESSAGE_V1 = 'ZIFT0007:'.
    ET_RETURN-MESSAGE_V2 = '没有配置任何流程编号检索规则'.
    ET_RETURN-MESSAGE_V3 = ''.
    ET_RETURN-MESSAGE_V4 = ''.
    APPEND ET_RETURN .
    RETURN.
  ENDIF.

  LOOP AT LT_ZIFT0007 INTO LS_ZIFT0007.
    "IV_FLAG <> 'X'时,此时是检查是否该单据号包含单据流程。IV_FLAG = 'X'时取满足IV_KSCHL的流程编号。
    IF IV_FLAG = 'X' AND LS_ZIFT0007-KSCHL <> IV_KSCHL.
      CONTINUE.
    ENDIF.
    "销售订单类型检查
    IF LS_ZIFT0007-ZIF_AUART <> LS_VBAK-AUART..
      CONTINUE.
    ENDIF.
    "客户参考单号是否为空检查。9,不检查,1,是,2,否。
    IF LS_ZIFT0007-ZIF_BSTNK <> '9'.
      IF LS_ZIFT0007-ZIF_BSTNK = '1' AND LS_VBAK-BSTNK IS NOT INITIAL.
        CONTINUE.
      ENDIF.

      IF LS_ZIFT0007-ZIF_BSTNK = '2' AND LS_VBAK-BSTNK IS  INITIAL.
        CONTINUE.
      ENDIF.
    ENDIF.
    "是否未上线连锁门店请货,一期为东升门店请货,9.不检查,1,是,2,否。
    "zsdt0014表检查ZPOSL系统类型为东升门店。
    IF LS_ZIFT0007-ZIF_DSQH <> '9'.
      IF LS_ZIFT0007-ZIF_DSQH  = '1' .
        SELECT COUNT(*) FROM VBPA AS A WHERE VBELN = IV_VBELN  AND PARVW = 'WE'
           AND EXISTS ( SELECT LOCNR FROM ZSDT0014 WHERE LOCNR = A~KUNNR AND ZPOSL = '604' ).
        IF SY-SUBRC <> 0.
          CONTINUE.
        ENDIF.
      ELSEIF LS_ZIFT0007-ZIF_DSQH = '2'.
        SELECT COUNT(*) FROM VBPA AS A WHERE VBELN = LS_VBAK-VBELN  AND PARVW = 'WE'
           AND EXISTS ( SELECT LOCNR FROM ZSDT0014 WHERE LOCNR = A~KUNNR AND ZPOSL = '604' ).
        IF SY-SUBRC = 0.
          CONTINUE.
        ENDIF.
      ENDIF.
    ENDIF.

    "是否统采平台发送的订单,统采平台发送的订单都会在SAP中ZMMT0085表存储。
    IF LS_ZIFT0007-ZIF_B2B <> '9'.
      IF LS_ZIFT0007-ZIF_B2B = 1 AND LS_VBAK-BSTNK IS INITIAL.
        CONTINUE.
      ELSEIF LS_ZIFT0007-ZIF_B2B = '1' AND LS_VBAK-BSTNK IS NOT INITIAL.
        SELECT COUNT(*) FROM ZMMT0085 WHERE PURREQNO = LS_VBAK-BSTNK AND BILLTYPE = 'SO'.
        IF SY-SUBRC <> 0.
          CONTINUE.
        ENDIF.
      ELSEIF  LS_ZIFT0007-ZIF_B2B = '2'.
        SELECT COUNT(*) FROM ZMMT0085 WHERE PURREQNO = LS_VBAK-BSTNK AND BILLTYPE = 'SO'.
        IF SY-SUBRC = 0.
          CONTINUE.
        ENDIF.
      ENDIF.
    ENDIF.
    CLEAR ES_PRO_STRU.
    ES_PRO_STRU-ZPROID = LS_ZIFT0007-ZPROID.
    ES_PRO_STRU-KSCHL  = LS_ZIFT0007-KSCHL.
    ES_PRO_STRU-DATYPE = LS_ZIFT0007-DATYPE.
    APPEND ES_PRO_STRU TO ET_PRO_STRU.
  ENDLOOP.

ENDFORM.

FORM FRM_MKPF TABLES  ET_RETURN STRUCTURE BAPIRET2
                      ET_PRO_STRU STRUCTURE ZIF_PRO_STRUCTURE
                USING IV_MBLNR  TYPE  MBLNR
                      IV_MJAHR  TYPE  MJAHR
                      IV_KSCHL  TYPE  KSCHL
                      IV_FLAG   TYPE  CHAR1.

  DATA ES_PRO_STRU TYPE ZIF_PRO_STRUCTURE.

  "-----------------------------------------------------------------
  DATA MT_RETURN   TYPE TABLE OF BAPIRET2 WITH HEADER LINE.
  DATA MT_PRO_STRU TYPE TABLE OF ZIF_PRO_STRUCTURE WITH HEADER LINE.
  "-----------------------------------------------------------------

  DATA :BEGIN OF LS_MKPF,
          MBLNR    LIKE MKPF-MBLNR,
          MJAHR    LIKE MKPF-MJAHR,
          BWART    LIKE MSEG-BWART,
          EBELN    LIKE MSEG-EBELN,
          VBELN_IM LIKE MSEG-VBELN_IM,
        END OF LS_MKPF.
  DATA LS_ZIFT0006 TYPE ZIFT0006.
  DATA LT_ZIFT0006 LIKE TABLE OF LS_ZIFT0006.
  DATA LT_MKPF LIKE TABLE OF LS_MKPF.

  SELECT DISTINCT MKPF~MBLNR MKPF~MJAHR MSEG~BWART MSEG~EBELN MSEG~VBELN_IM INTO CORRESPONDING FIELDS OF TABLE LT_MKPF FROM MKPF AS MKPF
    INNER JOIN MSEG AS MSEG ON MKPF~MBLNR = MSEG~MBLNR AND MKPF~MJAHR = MSEG~MJAHR
   WHERE MKPF~MBLNR = IV_MBLNR
     AND MKPF~MJAHR = IV_MJAHR.

  SELECT * INTO CORRESPONDING FIELDS OF TABLE LT_ZIFT0006 FROM ZIFT0006.
  IF SY-SUBRC <> 0.
    CLEAR ET_RETURN.
    ET_RETURN-TYPE = 'E'.
    ET_RETURN-ID = 'ZIF001'.
    ET_RETURN-NUMBER = '000'.
    ET_RETURN-MESSAGE_V1 = 'ZIFT0006:'.
    ET_RETURN-MESSAGE_V2 = '没有配置任何流程编号检索规则'.
    ET_RETURN-MESSAGE_V3 = ''.
    ET_RETURN-MESSAGE_V4 = ''.
    APPEND ET_RETURN .
    RETURN.
  ENDIF.

  LOOP AT LT_MKPF INTO LS_MKPF.
    LOOP AT  LT_ZIFT0006 INTO LS_ZIFT0006.
      "IV_FLAG <> 'X'时,此时是检查是否该单据号包含单据流程。IV_FLAG = 'X'时取满足IV_KSCHL的流程编号。
      IF IV_FLAG = 'X' AND LS_ZIFT0006-KSCHL <> IV_KSCHL.
        CONTINUE.
      ENDIF.

      "移动类型
      IF  LS_ZIFT0006-BWART IS NOT INITIAL AND LS_ZIFT0006-BWART NS LS_MKPF-BWART.
        CONTINUE.
      ENDIF.

      "采购订单是否为空
      IF LS_ZIFT0006-ZIF_EKKO <> '9'.
        IF LS_ZIFT0006-ZIF_EKKO = '1' AND LS_MKPF-EBELN IS NOT INITIAL.
          CONTINUE.
        ENDIF.
        IF LS_ZIFT0006-ZIF_EKKO = '2' AND LS_MKPF-EBELN IS INITIAL.
          CONTINUE.
        ENDIF.
      ENDIF.

      "物料凭证上的采购订单不为空,判断采购订单是否满足配置中的采购订单流程编号。
      IF LS_ZIFT0006-ZIF_EKKO = '2'.
        REFRESH: MT_RETURN,MT_PRO_STRU.
        PERFORM FRM_EKKO(SAPLZIFFG0001)
               TABLES MT_RETURN
                      MT_PRO_STRU
               USING LS_MKPF-EBELN
                     ''
                     ''.
        IF MT_PRO_STRU[] IS INITIAL.
          CONTINUE.
        ENDIF.
        LOOP AT MT_PRO_STRU WHERE ZPROID = LS_ZIFT0006-ZIF_EKKO_PROID.
          EXIT.
        ENDLOOP.
        IF SY-SUBRC <> 0.
          CONTINUE.
        ENDIF.
      ENDIF.

      "参考单据是否为空
      IF LS_ZIFT0006-ZIF_VGBEL <> '9'.
        IF LS_ZIFT0006-ZIF_VGBEL = '1' AND LS_MKPF-VBELN_IM IS NOT INITIAL.
          CONTINUE.
        ENDIF.
        IF LS_ZIFT0006-ZIF_VGBEL = '2' AND LS_MKPF-VBELN_IM IS INITIAL.
          CONTINUE.
        ENDIF.
      ENDIF.

      "物料凭证上的采购订单不为空,判断采购订单是否满足配置中的采购订单流程编号。
      IF LS_ZIFT0006-ZIF_VGBEL = '2'.
        REFRESH: MT_RETURN,MT_PRO_STRU.
        PERFORM FRM_LIKP(SAPLZIFFG0001)
               TABLES MT_RETURN
                      MT_PRO_STRU
               USING LS_MKPF-VBELN_IM
                     ''
                     ''.
        IF MT_PRO_STRU[] IS INITIAL.
          CONTINUE.
        ENDIF.
        LOOP AT MT_PRO_STRU WHERE ZPROID = LS_ZIFT0006-ZPROID_PRE.
          EXIT.
        ENDLOOP.
        IF SY-SUBRC <> 0.
          CONTINUE.
        ENDIF.
      ENDIF.
      CLEAR ES_PRO_STRU.
      ES_PRO_STRU-ZPROID = LS_ZIFT0006-ZPROID.
      ES_PRO_STRU-KSCHL = LS_ZIFT0006-KSCHL.
      ES_PRO_STRU-DATYPE = LS_ZIFT0006-DATYPE.
      APPEND ES_PRO_STRU TO ET_PRO_STRU.
    ENDLOOP.
  ENDLOOP.

ENDFORM.
View Code

 

 函数模块             ZIF_FUNC_CALL

FUNCTION zif_func_call.
*"----------------------------------------------------------------------
*"*"本地接口:
*"  IMPORTING
*"     VALUE(IV_FUNCNAME) TYPE  RS38L_FNAM
*"     VALUE(IV_ZPROID) TYPE  ZPROID
*"     VALUE(IS_NAST) TYPE  NAST
*"  TABLES
*"      RT_BAPIRET2 STRUCTURE  BAPIRET2
*"----------------------------------------------------------------------


  TRY .

      CALL FUNCTION iv_funcname  "in update task
        EXPORTING
          is_nast   = is_nast
          iv_zproid = iv_zproid
        TABLES
          et_return = rt_bapiret2[].

      COMMIT WORK AND WAIT .
    CATCH cx_root INTO DATA(lr_exception).
      "--- 输出类型 &1 处理函数调用异常:&2

      rt_bapiret2  = VALUE #(  id         = 'ZIF001'
                               number     = '003'
                               type       = 'E'
                               message_v1 = is_nast-kappl
                               message_v2 = lr_exception->get_text( )
                               message_v3 = ''
                               message_v4 = ''    ).

      APPEND rt_bapiret2 .

  ENDTRY.



ENDFUNCTION.
View Code

 

posted @ 2019-09-22 11:25  Rainystuday  阅读(308)  评论(0编辑  收藏  举报