Fluxo de trabalho: Obtenha o histórico de aprovação do pedido de compra (também PR e folha de entrada)

 (ABAP MM)

Olá,

Se você precisar obter o histórico de aprovação de documentos PO, PR e ES em tempo real, poderá usar as seguintes BAPIs:

BAPI_PO_GETRELINFO:  Para Pedidos de Compra;


BAPI_REQUISITION_GETRELINFO:  Para Requisições de Compra;


BAPI_ENTRYSHEET_GETRELINFO:  Para Folha de Registro de Serviços;


Eles fornecem os mesmos detalhes da guia Estratégia de lançamento:


Executando para o PO acima:




Você obtém uma tabela interna com RELEASE_FINAL (todos os códigos que precisam ser liberados) e a estrutura RELEASE_ALREADY_POSTED (todos os códigos que já foram postados).

Para simular o BAPI, criei um relatório simples que fornecerá o histórico de aprovações. Então no cenário abaixo:



Executando o programa você obtém:



E aqui está! Use-o, altere-o, adapte-o, etc... etc... etc... :levemente_smiling_face:Agora você pode obter o histórico dos documentos em qualquer lugar que precisar com base nos BAPIs mencionados...

*&---------------------------------------------------------------------*
*& 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.

Comentários

Postagens mais visitadas deste blog

Desenvolvendo Carreira em SAP: SAP Hana e SAP SAP S/4Hana