Skip to Content
Technical Articles

Workflow: Get PO(also PR and Entry Sheet) Approval History

Hello,

If you need to get the Approval history for PO, PR and ES documents in realtime, you could use the following BAPIs:

BAPI_PO_GETRELINFO: For Purchase Orders;

BAPI_REQUISITION_GETRELINFO: For Purchase Requisitions;

BAPI_ENTRYSHEET_GETRELINFO: For Service Entry Sheet;

They give you the same details as the Release Strategy tab:

Executing for the PO above:

You get a internal table with RELEASE_FINAL (all the codes that needs to get released) and the structure RELEASE_ALREADY_POSTED (all the codes that are already posted).

To simulate the BAPI, i’ve created a simple report that will give you the Approval history. So on the scenario below:

Running the program you get:

And here it is! Use it, change it, adapt it, etc… etc… etc… 🙂 Now you can get the documents history anywhere you need based on the BAPIs mentioned…

*&---------------------------------------------------------------------*
*& Report  ZPOWF_HISTORY
*& For Linkedin :) by José Sequeira http://bit.ly/2PbRleX
*&---------------------------------------------------------------------*

report  zpowf_history.

include <icon>.
*--------------------------------------------------------------------*
"Declaring...
*--------------------------------------------------------------------*
types: begin of ty_out,
        relcode   type frgco,
        descript  type frgct,
        icon      type icon_d,
       end of ty_out.

data: gr_table    type ref to cl_salv_table.

data: lr_columns  type ref to cl_salv_columns_table,
      lr_column   type ref to cl_salv_column_table.

data: lt_final    type table of bapirlcopo,
      lt_out      type table of ty_out,
      ls_out      type ty_out,
      ls_posted   type bapirlcopo,
      ls_final    type bapirlcopo.

"Selecting PO
*--------------------------------------------------------------------*
parameters: p_ebeln type ebeln.
*--------------------------------------------------------------------*
start-of-selection.

  "Getting stuff ready...(You could do the same for PR and Entry Sheet, searching with BAPI_*_GETRELINFO...
  call function 'BAPI_PO_GETRELINFO'
    exporting
      purchaseorder                = p_ebeln
*   PO_REL_CODE                  = "You could also just check one Rel Code, not the complete PO
   importing
     release_already_posted       = ls_posted
   tables
     release_final                = lt_final.
  if lt_final[] is initial.
    message 'PO not found...' type 'S' display like 'E'.
  else.
*--------------------------------------------------------------------*
    "Preparing data... You could automate the check below in some many
    " ways, just doing like that for DEMO purposes...
*--------------------------------------------------------------------*
    read table lt_final into ls_final index 1.
    if ls_final-rel_code1 is not initial.
      ls_out-relcode  = ls_final-rel_code1.
      ls_out-descript = ls_final-rel_cd_tx1.
      if ls_posted-rel_code1 is not initial.
        ls_out-icon = icon_okay.
      else.
        ls_out-icon = icon_warning.
      endif.
      append ls_out to lt_out.
    endif.
    if ls_final-rel_code2 is not initial.
      ls_out-relcode  = ls_final-rel_code2.
      ls_out-descript = ls_final-rel_cd_tx2.
      if ls_posted-rel_code2 is not initial.
        ls_out-icon = icon_okay.
      else.
        ls_out-icon = icon_warning.
      endif.
      append ls_out to lt_out.
    endif.
    if ls_final-rel_code3 is not initial.
      ls_out-relcode  = ls_final-rel_code3.
      ls_out-descript = ls_final-rel_cd_tx3.
      if ls_posted-rel_code3 is not initial.
        ls_out-icon = icon_okay.
      else.
        ls_out-icon = icon_warning.
      endif.
      append ls_out to lt_out.
    endif.
    if ls_final-rel_code4 is not initial.
      ls_out-relcode  = ls_final-rel_code4.
      ls_out-descript = ls_final-rel_cd_tx4.
      if ls_posted-rel_code4 is not initial.
        ls_out-icon = icon_okay.
      else.
        ls_out-icon = icon_warning.
      endif.
      append ls_out to lt_out.
    endif.
    if ls_final-rel_code5 is not initial.
      ls_out-relcode  = ls_final-rel_code5.
      ls_out-descript = ls_final-rel_cd_tx5.
      if ls_posted-rel_code5 is not initial.
        ls_out-icon = icon_okay.
      else.
        ls_out-icon = icon_warning.
      endif.
      append ls_out to lt_out.
    endif.
    if ls_final-rel_code6 is not initial.
      ls_out-relcode  = ls_final-rel_code6.
      ls_out-descript = ls_final-rel_cd_tx6.
      if ls_posted-rel_code6 is not initial.
        ls_out-icon = icon_okay.
      else.
        ls_out-icon = icon_warning.
      endif.
      append ls_out to lt_out.
    endif.
    if ls_final-rel_code7 is not initial.
      ls_out-relcode  = ls_final-rel_code7.
      ls_out-descript = ls_final-rel_cd_tx7.
      if ls_posted-rel_code7 is not initial.
        ls_out-icon = icon_okay.
      else.
        ls_out-icon = icon_warning.
      endif.
      append ls_out to lt_out.
    endif.
    if ls_final-rel_code8 is not initial.
      ls_out-relcode  = ls_final-rel_code8.
      ls_out-descript = ls_final-rel_cd_tx8.
      if ls_posted-rel_code8 is not initial.
        ls_out-icon = icon_okay.
      else.
        ls_out-icon = icon_warning.
      endif.
      append ls_out to lt_out.
    endif.
*--------------------------------------------------------------------*
    "Showing simple ALV...
    cl_salv_table=>factory( importing r_salv_table = gr_table changing t_table = lt_out ).
    lr_columns = gr_table->get_columns( ).
    lr_columns->set_optimize( 'X' ).
    lr_column ?= lr_columns->get_column( 'ICON' ).
    lr_column->set_icon( if_salv_c_bool_sap=>true ).
    lr_column->set_long_text( 'ICON' ).
    gr_table->display( ).
  endif.

You could check out the video here.

Enjoy, regards.

Be the first to leave a comment
You must be Logged on to comment or reply to a post.