其他分享
首页 > 其他分享> > 采购签核 RFC bapi_po_release

采购签核 RFC bapi_po_release

作者:互联网

FUNCTION zrfc_bpm_bapi_po_release.
*"----------------------------------------------------------------------
*"*"區域介面:
*"  IMPORTING
*"     VALUE(I_EBELN) TYPE  EKKO-EBELN
*"     VALUE(I_LANGUAGE) TYPE  SPRAS DEFAULT 'ZF'
*"  TABLES
*"      LT_RETURN STRUCTURE  BAPIRETURN OPTIONAL
*"----------------------------------------------------------------------

  TABLES:bapimmpara,t16fk,t16fv,bapireturn.

  TYPES: BEGIN OF ty_ekko,
           ebeln TYPE ebeln, "采购单
           frggr TYPE frggr, "核发群组
           frgsx TYPE frgsx, "核发策略
           frgzu TYPE frgzu, "核发指示码
           frgrl TYPE frgrl, "是否需要核发
         END OF ty_ekko.

  DATA: l_cod     LIKE bapimmpara-po_rel_cod,
        ls_return TYPE  bapireturn,
        ls_ekko   TYPE ty_ekko,
        l_len     TYPE i,
        e_frgzu   LIKE ekko-frgzu. "签核指示吗

  DO 8 TIMES.
    SELECT SINGLE ebeln frggr frgsx frgzu frgrl
      INTO ls_ekko
      FROM ekko
      WHERE ebeln = i_ebeln.

    IF sy-subrc = 0 AND ls_ekko-frgrl = 'X'.
      CONCATENATE ls_ekko-frgzu 'X' INTO ls_ekko-frgzu.
*      WRITE 'X' TO ls_ekko-frgzu+sy-fdpos(1).
      t16fk+7(8) = ls_ekko-frgzu.
      SELECT SINGLE * FROM t16fk WHERE frggr EQ ls_ekko-frggr
                                    AND frgsx EQ ls_ekko-frgsx
                                    AND frga1 EQ t16fk-frga1
                                    AND frga2 EQ t16fk-frga2
                                    AND frga3 EQ t16fk-frga3
                                    AND frga4 EQ t16fk-frga4
                                    AND frga5 EQ t16fk-frga5
                                    AND frga6 EQ t16fk-frga6
                                    AND frga7 EQ t16fk-frga7
                                    AND frga8 EQ t16fk-frga8.

      IF sy-subrc = 0.

        e_frgzu = ls_ekko-frgzu.

        REPLACE ALL OCCURRENCES OF  'X'  IN e_frgzu WITH '+'.

        l_len = strlen( e_frgzu ).
        l_len = l_len - 1.

        IF l_len >= 1 .
          e_frgzu = e_frgzu(l_len).
        ELSE.
          e_frgzu = ''.
        ENDIF.

        CONCATENATE e_frgzu 'X' INTO e_frgzu.

        t16fv+9(8) = e_frgzu.

        SELECT SINGLE * FROM t16fv WHERE frggr EQ ls_ekko-frggr
                                    AND frgsx EQ ls_ekko-frgsx
                                    AND frga1 EQ t16fv-frga1
                                    AND frga2 EQ t16fv-frga2
                                    AND frga3 EQ t16fv-frga3
                                    AND frga4 EQ t16fv-frga4
                                    AND frga5 EQ t16fv-frga5
                                    AND frga6 EQ t16fv-frga6
                                    AND frga7 EQ t16fv-frga7
                                    AND frga8 EQ t16fv-frga8.

        IF sy-subrc = 0.
          CALL FUNCTION 'BAPI_PO_RELEASE'
            EXPORTING
              purchaseorder          = i_ebeln
*             po_rel_code            = 'A3'
              po_rel_code            = t16fv-frgco
*             USE_EXCEPTIONS         = 'X'
*             NO_COMMIT              = ' '
*       IMPORTING
*             REL_STATUS_NEW         =
*             REL_INDICATOR_NEW      =
*             RET_CODE               =
            TABLES
              return                 = lt_return
            EXCEPTIONS
              authority_check_fail   = 1
              document_not_found     = 2
              enqueue_fail           = 3
              prerequisite_fail      = 4
              release_already_posted = 5
              responsibility_fail    = 6
              OTHERS                 = 7.
          IF lt_return[] IS INITIAL.
            "提交
            CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
              EXPORTING
                wait = 'X'.

            "解锁
            CALL FUNCTION 'DEQUEUE_ALL'
              EXPORTING
                _synchron = 'X'.

          ELSE.
            "回滚
            CALL FUNCTION 'BAPI_TRANSACTION_ROLLBACK'.
            EXIT.
          ENDIF.
        ENDIF.
      ENDIF.
    ELSEIF  ls_ekko-frgrl = '' OR sy-subrc <> 0.
      EXIT.
    ENDIF.
  ENDDO.

  "采购单核发检查
  SELECT SINGLE ebeln frggr frgsx frgzu frgrl
   INTO ls_ekko
   FROM ekko
   WHERE ebeln = i_ebeln.

  IF  lt_return[] IS INITIAL AND sy-subrc = 0 AND  ls_ekko-frgrl = 'X'.
    "采购单核发错误提示
    ls_return-type = 'E'.
    ls_return-code = 'ME192'.
    ls_return-message = 'E'.

    SELECT SINGLE text
        INTO ls_return-message
        FROM t100
        WHERE arbgb = 'ME'
        AND   msgnr = '192'
        AND  sprsl = i_language.

    APPEND ls_return TO lt_return.CLEAR:ls_return.
  ELSEIF sy-subrc <> 0.
    "采购单不存在
    ls_return-type = 'E'.
    ls_return-code = 'MN351'.
    ls_return-message = 'E'.

    SELECT SINGLE text
        INTO ls_return-message
        FROM t100
        WHERE arbgb = 'MN'
        AND   msgnr = '351'
        AND  sprsl = i_language.

    APPEND ls_return TO lt_return.CLEAR:ls_return.
  ENDIF.

ENDFUNCTION.

 

 

 

标签:签核,bapi,return,t16fv,RFC,ls,EQ,frgzu,ekko
来源: https://www.cnblogs.com/Brokenshelltao/p/16359777.html