title: `BAPI_PO_RELEASE` not returning success in sap
body: <p>I want to release purchase order according to po number. <code>BAPI_PO_RELEASE</code> standard function module returning success message on release.But on already released <code>po</code> number it shows Already released.</p>
  <p>Signature:</p>
  <ul>
  <li><p>import parameters</p>
  <p><code>IV_EBELN    TYPE      EKPO-EBELN.</code><br />
  <code>IV_FRGCO    TYPE      BAPIMMPARA-PO_REL_COD</code></p>
  </li>
  <li><p>export parameter</p>
  <p><code>ET_RETURN   TYPE      /WITS/MI_RETURN_TT'</code></p>
  </li>
  </ul>
  <p>Code:</p>
  <pre><code>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.
  
    
  
      &quot;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.
  
              &quot;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.
  
              &quot;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.
  
              &quot;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.
  
                 &quot;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.
  
                  &quot;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.
  
                 &quot;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.
  
                  &quot;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.
  
     &quot; MOVE ls_items-frgco TO lv_rel_code.
      IF lv_rel_code IS NOT INITIAL.
        &quot;*----------------------------------------------
        &quot;*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.
  
        &quot;************************************
  
       IF sy-subrc IS NOT INITIAL.
  
          &quot;* Implement suitable error handling here
  
        ELSE.
  
          CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
            EXPORTING
              wait = 'X'.
        ENDIF.
        &quot; read error msg from bapi
          LOOP AT lt_return INTO ls_return .&quot;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.
  </code></pre>