`BAPI_PO_RELEASE` 没有在 sap 中返回成功

`BAPI_PO_RELEASE` not returning success in sap

我想根据采购单号下达采购订单。 BAPI_PO_RELEASE 标准功能模块在已发布 release.But 上返回成功消息 po 显示已发布的编号。

签名:

代码:

FUNCTION /WITS/MI_PO_RELEASE.


    TYPES: BEGIN OF t_ekpo,
           ebeln TYPE EKPO-EBELN,
    END OF t_ekpo.

    DATA: lt_ponumber TYPE TABLE OF t_ekpo,
          ls_ponumber TYPE          t_ekpo.

    DATA: ls_ret       TYPE          /wits/ma_return.


    DATA lv_po         TYPE   bapimmpara-po_number.
    DATA lv_rel_code   TYPE   bapimmpara-po_rel_cod.
    DATA lv_rel_status TYPE   bapimmpara-rel_status.
    DATA lv_rel_indic  TYPE   bapimmpara-po_rel_ind.
    DATA lv_ret_code   TYPE   sy-subrc.
    DATA lt_return     TYPE TABLE OF bapireturn.
    DATA ls_return     TYPE          bapireturn.
    DATA lt_return1    TYPE STANDARD TABLE OF bapireturn.
    DATA lt_curr_rel   TYPE STANDARD TABLE OF bapirlcopo.
    DATA ls_curr_rel   TYPE          bapirlcopo.
    DATA ls_rel_done   TYPE          bapirlcopo.


    MOVE IV_EBELN TO ls_ponumber.
    CLEAR: lv_rel_code.

  

    "MOVE IV_FRGCO TO lv_rel_code.

         REFRESH:  lt_return.
         CLEAR:  lv_po.

         MOVE ls_ponumber-ebeln TO lv_po.

         CALL FUNCTION 'BAPI_PO_GETRELINFO'
               EXPORTING
                    purchaseorder = lv_po
               IMPORTING
                    release_already_posted = ls_rel_done
               TABLES
                    release_final          = lt_curr_rel
                    return                 = lt_return.


       READ TABLE lt_return INTO ls_return WITH KEY type = 'E'.
      IF sy-subrc NE 0.
           READ TABLE lt_curr_rel INTO ls_curr_rel WITH KEY po_number = lv_po.
                  IF ls_curr_rel-rel_code8 IS NOT INITIAL.
                        IF ls_rel_done-rel_code8 IS INITIAL.
                             lv_rel_code = ls_curr_rel-rel_code8.
                        ENDIF.
                  ENDIF.

            "for code 7
                 IF ls_curr_rel-rel_code7 IS NOT INITIAL.
                     IF ls_rel_done-rel_code7 IS INITIAL.
                          lv_rel_code = ls_curr_rel-rel_code7.
                     ENDIF.
                ENDIF.

            "for code 6
                IF ls_curr_rel-rel_code6 IS NOT INITIAL.
                  IF ls_rel_done-rel_code6 IS INITIAL.
                    lv_rel_code = ls_curr_rel-rel_code6.
                  ENDIF.
                ENDIF.

            "for code 5
                IF ls_curr_rel-rel_code5 IS NOT INITIAL.
                  IF ls_rel_done-rel_code5 IS INITIAL.
                    lv_rel_code = ls_curr_rel-rel_code5.
                  ENDIF.
                ENDIF.

               "for code 4
               IF ls_curr_rel-rel_code4 IS NOT INITIAL.
                 IF ls_rel_done-rel_code4 IS INITIAL.
                   lv_rel_code = ls_curr_rel-rel_code4.
                 ENDIF.
               ENDIF.

                "for code 3
                IF ls_curr_rel-rel_code3 IS NOT INITIAL.
                  IF ls_rel_done-rel_code3 IS INITIAL.
                    lv_rel_code = ls_curr_rel-rel_code3.
                  ENDIF.
                ENDIF.

               "for code 2
               IF ls_curr_rel-rel_code2 IS NOT INITIAL.
                 IF ls_rel_done-rel_code2 IS INITIAL.
                   lv_rel_code = ls_curr_rel-rel_code2.
                 ENDIF.
               ENDIF.

                "for code 1
                IF ls_curr_rel-rel_code1 IS NOT INITIAL.
                  IF ls_rel_done-rel_code1 IS INITIAL.
                    lv_rel_code = ls_curr_rel-rel_code1.
                  ENDIF.
                ENDIF.

    ELSE.

              LOOP AT lt_return INTO ls_return WHERE type = 'E'.
                 MOVE ls_return-message TO et_return-message.
                 APPEND et_return.
                 CLEAR: ls_return, et_return.
               ENDLOOP.

   ENDIF.

   " MOVE ls_items-frgco TO lv_rel_code.
    IF lv_rel_code IS NOT INITIAL.
      "*----------------------------------------------
      "*Call the bapi to release the purcahse order

       CALL FUNCTION 'BAPI_PO_RELEASE'
        EXPORTING
          purchaseorder          = lv_po
          po_rel_code            = lv_rel_code
          use_exceptions         = 'X'
          no_commit              = ' '
        IMPORTING
          rel_status_new         = lv_rel_status
          rel_indicator_new      = lv_rel_indic
          ret_code               = lv_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 sy-subrc IS NOT INITIAL.

        "* Implement suitable error handling here

      ELSE.

        CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
          EXPORTING
            wait = 'X'.
      ENDIF.
      " read error msg from bapi
        LOOP AT lt_return INTO ls_return ."WHERE type = 'E' .

        MOVE lv_po                TO ls_ret-ebeln.
        MOVE ls_return-message    TO ls_ret-message.

        APPEND ls_ret  TO et_return.
        CLEAR: ls_ret,ls_return.
       ENDLOOP.
  ELSE.

      MOVE lv_po                     TO ls_ret-ebeln.
      MOVE 'Release already done'    TO ls_ret-message.

      APPEND ls_ret TO et_return.
      CLEAR: ls_ret,ls_return.

   ENDIF.

ENDFUNCTION.

如果您想为已发布的采购订单发送另一条消息,则需要以不同的方式处理异常'release_already_posted'。

在标准 BAPI 中,如果您尝试发布已经发布的 PO,则不会成功。