Skip to Content

Below code logic is used to get the actual back-end documents line item status for SRM shopping carts.

In POWL, If you look at the header status of the shopping cart,most of them will be in “Approved” status and corresponding line item status will be “Follow-on Document Created”. If we want to get the actual status of the individual line items, then we need to open the shopping cart and check for actual status.

In most of the clients, you might be asked to develop a report or enhance BW reports to show this actual status like (Purchase Requisition Created, Purchase Order created, GR completed, Partial GR, Partial Invoice , Invoice completed).

In order to meet such requirement, I have developed this logic by copying standard code.

This logic can be put into a function module and can be re-used.

REPORT ysasi1.

DATA: lv_object_key         TYPE bbps_object_key,

      lv_val_cf_e           TYPE bbp_iv_value_e,

      i_sc_item             TYPE TABLE OF bbp_pds_sc_item_d,

      w_sc_item             TYPE bbp_pds_sc_item_d,

      i_sc_status           TYPE TABLE OF bbp_pds_status,

      w_sc_status           TYPE bbp_pds_status,

      ls_item               TYPE bbp_pds_sc_item_d,

      lt_item_pd            TYPE TABLE OF bbp_pds_item,

      ls_item_pd            TYPE bbp_pds_item,

      w_item_pd             TYPE bbp_pds_item,

      lt_messages           TYPE bbpt_pds_messages,

      es_status_description TYPE /sapsrm/s_status_info_desc,

      lt_item_history       TYPE TABLE OF bbp_pds_history,

      ls_item_history       TYPE bbp_pds_history,

      ls_item_history1      TYPE LINE OF /sapsrm/t_history,

      is_status             TYPE /sapsrm/s_status_info,

      lv_once               TYPE abap_bool,

      w_read_i_flags        TYPE bbps_detail_i_requested.

CONSTANTS: lc_objtype_storage TYPE crmd_orderadm_h-object_type VALUE ‘storage’,

           lc_x               TYPE c                           VALUE ‘X’,

           lc_bus2121001      TYPE swo_objtyp                  VALUE ‘BUS2121001’,

           lc_bus2121         TYPE swo_objtyp                  VALUE ‘BUS2121’.

FIELD-SYMBOLS:   <fs_item_history>    LIKE LINE OF lt_item_history.

PARAMETERS: p_sc TYPE crmd_orderadm_h-object_id DEFAULT ‘1001981426’ OBLIGATORY.

CALL FUNCTION ‘BBP_PD_SC_GETDETAIL’

  EXPORTING

*   I_GUID      = p_pguid

    i_object_id = p_sc

  TABLES

    e_item      = i_sc_item

    e_status    = i_sc_status.

* set flag to read ITEM & Message tab.

w_read_i_flags-item_tab     = lc_x.

w_read_i_flags-messages_tab = lc_x.

LOOP AT i_sc_item INTO w_sc_item.

  READ TABLE i_sc_status TRANSPORTING NO FIELDS

  WITH KEY p_guid = w_sc_item-guid

           inact  = space.

  IF sy-subrc = 0.

    CALL FUNCTION ‘BBP_PROCDOC_ITEM_GETDETAIL’

      EXPORTING

        i_guid         = w_sc_item-guid

        i_object_type  = lc_bus2121001

        i_read_i_flags = w_read_i_flags

      TABLES

        e_item         = lt_item_pd

        e_messages     = lt_messages.

    lv_object_key-h_object_type     =  lc_bus2121.

    lv_object_key-h_guid            =  w_sc_item-parent.

    lv_object_key-i_object_type     =  lc_bus2121001.

    lv_object_key-i_guid            =  w_sc_item-guid.

    CALL FUNCTION ‘BBP_PD_GETHISTORY’

      EXPORTING

        i_object_key                  = lv_object_key

      TABLES

        et_history                    = lt_item_history

      EXCEPTIONS

        incomplete_object_information = 1

        OTHERS                        = 2.

***********************************************************************************************************

*   Looping to get the PO quantity for checking against Confirmation & Invoice.

    LOOP AT lt_item_history INTO ls_item_history WHERE objtype = /sapsrm/if_pdo_obj_types_c=>gc_pdo_be_po

      OR objtype = /sapsrm/if_pdo_obj_types_c=>gc_pdo_be_po_item

      OR objtype = /sapsrm/if_pdo_obj_types_c=>gc_pdo_po

      OR objtype = /sapsrm/if_pdo_obj_types_c=>gc_pdo_po_item.

      ls_item-quantity   =  ls_item_history-quantity.

      ls_item-price      =  ls_item_history-value.

    ENDLOOP.

*   Checking if the follow on documents that were created went into ‘ERROR IN PROCESS’ status.

    LOOP AT lt_item_history INTO ls_item_history WHERE status = ‘I1019’.

    ENDLOOP.

    IF sy-subrc = 0.

      es_status_description-status_description = text-058.

    ENDIF.

    READ TABLE lt_item_pd INTO ls_item_pd INDEX 1.

*   Checking if the Purchase Order created was Incomplete

    IF es_status_description-status_description IS INITIAL.

      LOOP AT lt_item_history INTO ls_item_history WHERE objtype = /sapsrm/if_pdo_obj_types_c=>gc_pdo_be_po

        OR objtype = /sapsrm/if_pdo_obj_types_c=>gc_pdo_be_po_item

        OR objtype = /sapsrm/if_pdo_obj_types_c=>gc_pdo_po

        OR objtype = /sapsrm/if_pdo_obj_types_c=>gc_pdo_po_item.

      ENDLOOP.

      IF sy-subrc = 0.

        IF ls_item_history-status = ‘I1009’.

          es_status_description-status_description = text-061.

        ENDIF.

      ENDIF.

    ENDIF.

*************************************************************************************************************

*  The below logic for checking partial or complete Confirmation & Invoice has been taken from SRM 5.0 system

*  FM – BBP_PDH_SEARCH_SC_SUBLIST

*  SUBROUTINE – sc_item_history_status_get TABLES

*  New text elements 058,059,060 were added.

*************************************************************************************************************

*   Checking whether Invoice is Complete or Partial.

    IF es_status_description-status_description IS INITIAL.

      CLEAR ls_item-quan_iv_e.

      CLEAR ls_item-val_iv_e.

      LOOP AT lt_item_history INTO ls_item_history WHERE objtype = /sapsrm/if_pdo_obj_types_c=>gc_pdo_invoice

        OR objtype = /sapsrm/if_pdo_obj_types_c=>gc_pdo_invoice_item

        OR objtype = /sapsrm/if_pdo_obj_types_c=>gc_pdo_be_iv_lo

        OR objtype = /sapsrm/if_pdo_obj_types_c=>gc_pdo_be_iv_lo_item.

        “status should be either ‘Transfer in Process’ or ‘Approved’ or ‘Posted in backend’

        IF ls_item_history-status EQ ‘I1017’ OR ls_item_history-status EQ ‘I1022’  OR ls_item_history-status EQ ‘I1018’ .

          IF ls_item_history-subtype EQ /sapsrm/if_pdo_obj_types_c=>gc_subtype_iv.

            ls_item-quan_iv_e  = ls_item-quan_iv_e + ls_item_history-quantity.

            ls_item-val_iv_e   = ls_item-val_iv_e  + ls_item_history-value.

          ELSEIF ls_item_history-subtype EQ /sapsrm/if_pdo_obj_types_c=>gc_subtype_cm.

            ls_item-quan_iv_e  = ls_item-quan_iv_e – abs( ls_item_history-quantity ).

            ls_item-val_iv_e   = ls_item-val_iv_e  – abs( ls_item_history-value ).

          ELSE.

            IF ls_item_history-dcind EQ ‘H’.

              ls_item-quan_iv_e  = ls_item-quan_iv_e – abs( ls_item_history-quantity ).

              ls_item-val_iv_e   = ls_item-val_iv_e  – abs( ls_item_history-value ).

            ELSE.

              ls_item-quan_iv_e  = ls_item-quan_iv_e + ls_item_history-quantity.

              ls_item-val_iv_e   = ls_item-val_iv_e  + ls_item_history-value.

            ENDIF.

          ENDIF.

        ELSEIF ls_item_history-subtype EQ /sapsrm/if_pdo_obj_types_c=>gc_subtype_iv.

          ls_item-quan_iv_e  = ls_item-quan_iv_e + ls_item_history-quantity.

          ls_item-val_iv_e   = ls_item-val_iv_e  + ls_item_history-value.

        ELSEIF ls_item_history-subtype EQ /sapsrm/if_pdo_obj_types_c=>gc_subtype_cm.

          ls_item-quan_iv_e  = ls_item-quan_iv_e – abs( ls_item_history-quantity ).

          ls_item-val_iv_e   = ls_item-val_iv_e  – abs( ls_item_history-value ).

        ENDIF.

      ENDLOOP.

      IF sy-subrc = 0.

        IF ls_item_pd-itm_type EQ /sapsrm/if_pdo_constants_gen_c=>gc_ptype_limit.

          IF ls_item-val_iv_e = 0.

            “invoices were cancelled with credit memo. So, discard invoice/credit memos from history

            DELETE lt_item_history WHERE objtype = /sapsrm/if_pdo_obj_types_c=>gc_pdo_invoice

               OR objtype = /sapsrm/if_pdo_obj_types_c=>gc_pdo_invoice_item

               OR objtype = /sapsrm/if_pdo_obj_types_c=>gc_pdo_be_iv_lo

               OR objtype = /sapsrm/if_pdo_obj_types_c=>gc_pdo_be_iv_lo_item.

          ELSEIF ls_item_pd-final_inv EQ abap_true OR ( ls_item-val_iv_e GE ls_item-price ).

            es_status_description-status_description = text-065.

          ELSE.

            es_status_description-status_description = text-060.

          ENDIF.

        ELSE.

          IF ls_item-quan_iv_e LT ls_item-quantity AND

           ls_item-quan_iv_e NE 0.

            es_status_description-status_description = text-060.

          ELSEIF ls_item-quan_iv_e GE ls_item-quantity.

            es_status_description-status_description = text-065.

          ELSEIF ls_item-quan_iv_e = 0 AND ls_item-val_iv_e = 0 AND ls_item-quantity > 0.

            “invoices were cancelled with credit memo. So, discard invoice/credit memos from history

            DELETE lt_item_history WHERE objtype = /sapsrm/if_pdo_obj_types_c=>gc_pdo_invoice

               OR objtype = /sapsrm/if_pdo_obj_types_c=>gc_pdo_invoice_item

               OR objtype = /sapsrm/if_pdo_obj_types_c=>gc_pdo_be_iv_lo

               OR objtype = /sapsrm/if_pdo_obj_types_c=>gc_pdo_be_iv_lo_item.

          ENDIF.

        ENDIF.

      ENDIF.

    ENDIF.

*   Checking whether Confirmation is Complete or Partial.

    IF es_status_description-status_description IS INITIAL.

      CLEAR ls_item-quan_cf_e.

      CLEAR lv_val_cf_e.

      LOOP AT lt_item_history INTO ls_item_history WHERE objtype = /sapsrm/if_pdo_obj_types_c=>gc_pdo_grse

        OR objtype = /sapsrm/if_pdo_obj_types_c=>gc_pdo_grse_item

        OR objtype = /sapsrm/if_pdo_obj_types_c=>gc_pdo_be_gr

        OR objtype = /sapsrm/if_pdo_obj_types_c=>gc_pdo_be_gr_item.

        “status should be either ‘Approved’ or ‘Posted in backend’

        IF ls_item_history-status EQ ‘I1017’ OR ls_item_history-status EQ ‘I1022’ OR ls_item_history-status EQ ‘I1018’ .

          IF ls_item_history-subtype EQ /sapsrm/if_pdo_obj_types_c=>gc_subtype_cf.

            ls_item-quan_cf_e  = ls_item-quan_cf_e + ls_item_history-quantity.

            lv_val_cf_e        = lv_val_cf_e       + ls_item_history-value.

          ELSEIF ls_item_history-subtype EQ /sapsrm/if_pdo_obj_types_c=>gc_subtype_ca OR

                 ls_item_history-subtype EQ /sapsrm/if_pdo_obj_types_c=>gc_subtype_rt.

            ls_item-quan_cf_e  = ls_item-quan_cf_e – abs( ls_item_history-quantity ).

            lv_val_cf_e        = lv_val_cf_e       – abs( ls_item_history-value ).

          ELSE.

            IF ls_item_history-dcind EQ ‘H’.

              ls_item-quan_cf_e  = ls_item-quan_cf_e – abs( ls_item_history-quantity ).

              lv_val_cf_e        = lv_val_cf_e       – abs( ls_item_history-value ).

            ELSE.

              ls_item-quan_cf_e  = ls_item-quan_cf_e + ls_item_history-quantity.

              lv_val_cf_e        = lv_val_cf_e       + ls_item_history-value.

            ENDIF.

          ENDIF.

        ELSEIF ls_item_history-subtype EQ /sapsrm/if_pdo_obj_types_c=>gc_subtype_cf.

          IF lv_once EQ abap_false.

            LOOP AT lt_item_history INTO ls_item_history1 WHERE objtype = /sapsrm/if_pdo_obj_types_c=>gc_pdo_be_se.

              IF ls_item_history1-dcind EQ ‘S’.

                ls_item-quan_cf_e  = ls_item-quan_cf_e + ls_item_history1-quantity.

                lv_val_cf_e        = lv_val_cf_e       + ls_item_history1-value.

              ELSE.

                ls_item-quan_cf_e  = ls_item-quan_cf_e – abs( ls_item_history1-quantity ).

                lv_val_cf_e        = lv_val_cf_e       – abs( ls_item_history1-value ).

              ENDIF.

            ENDLOOP.

            IF sy-subrc NE 0.

              ls_item-quan_cf_e  = ls_item-quan_cf_e + ls_item_history-quantity.

              lv_val_cf_e        = lv_val_cf_e       + ls_item_history-value.

            ENDIF.

            lv_once = abap_true.

          ENDIF.

        ELSEIF ls_item_history-subtype EQ /sapsrm/if_pdo_obj_types_c=>gc_subtype_ca OR

               ls_item_history-subtype EQ /sapsrm/if_pdo_obj_types_c=>gc_subtype_rt.

          ls_item-quan_cf_e  = ls_item-quan_cf_e – abs( ls_item_history-quantity ).

          lv_val_cf_e        = lv_val_cf_e       – abs( ls_item_history-value ).

        ENDIF.

      ENDLOOP.

      IF sy-subrc = 0.

        IF ls_item_pd-itm_type EQ /sapsrm/if_pdo_constants_gen_c=>gc_ptype_limit.

          IF lv_val_cf_e = 0.

            “goods receives were cancelled. So, discard confirmations/cancellations from history

            DELETE lt_item_history WHERE objtype = /sapsrm/if_pdo_obj_types_c=>gc_pdo_grse

                OR objtype = /sapsrm/if_pdo_obj_types_c=>gc_pdo_grse_item

                OR objtype = /sapsrm/if_pdo_obj_types_c=>gc_pdo_be_gr

                OR objtype = /sapsrm/if_pdo_obj_types_c=>gc_pdo_be_gr_item.

          ELSEIF ls_item_pd-final_entry EQ abap_true OR ( lv_val_cf_e GE ls_item-price ).

            es_status_description-status_description = text-064.

          ELSE.

            es_status_description-status_description = text-059.

          ENDIF.

        ELSE.

          IF ls_item-quan_cf_e LT ls_item-quantity AND

           ls_item-quan_cf_e NE 0.

            es_status_description-status_description = text-059.

          ELSEIF ls_item-quan_cf_e GE ls_item-quantity.

            es_status_description-status_description = text-064.

          ELSEIF ls_item-quan_cf_e = 0 AND lv_val_cf_e = 0 AND ls_item-quantity > 0.

            “goods receives were cancelled. So, discard confirmations/cancellations from history

            DELETE lt_item_history WHERE objtype = /sapsrm/if_pdo_obj_types_c=>gc_pdo_grse

                OR objtype = /sapsrm/if_pdo_obj_types_c=>gc_pdo_grse_item

                OR objtype = /sapsrm/if_pdo_obj_types_c=>gc_pdo_be_gr

                OR objtype = /sapsrm/if_pdo_obj_types_c=>gc_pdo_be_gr_item.

          ENDIF.

        ENDIF.

      ENDIF.

    ENDIF.

**************************************************************************************************************

*   If there was no Partial Confirmation or Invoice Created then Check for the other possible documents.

*   This includes even the complete Confirmation and Complete Invoice.

    IF es_status_description-status_description IS INITIAL.

      SORT lt_item_history BY display_level DESCENDING.

      READ TABLE lt_item_history INDEX 1 ASSIGNING <fs_item_history>.

      IF <fs_item_history> IS ASSIGNED.

        MOVE-CORRESPONDING is_status TO es_status_description.

        es_status_description-langu = sy-langu.

        CASE <fs_item_history>-objtype.

* purchase requisition

          WHEN /sapsrm/if_pdo_obj_types_c=>gc_pdo_be_pr

            OR /sapsrm/if_pdo_obj_types_c=>gc_pdo_be_pr_item.

            es_status_description-status_description = text-051.

* reservation

          WHEN /sapsrm/if_pdo_obj_types_c=>gc_pdo_be_rs

            OR /sapsrm/if_pdo_obj_types_c=>gc_pdo_be_rs_item.

            es_status_description-status_description = text-050.

* Confirmation

          WHEN /sapsrm/if_pdo_obj_types_c=>gc_pdo_grse

            OR /sapsrm/if_pdo_obj_types_c=>gc_pdo_grse_item

            OR /sapsrm/if_pdo_obj_types_c=>gc_pdo_be_gr

            OR /sapsrm/if_pdo_obj_types_c=>gc_pdo_be_gr_item.

            es_status_description-status_description = text-053.

* Invoice

          WHEN /sapsrm/if_pdo_obj_types_c=>gc_pdo_invoice

           OR /sapsrm/if_pdo_obj_types_c=>gc_pdo_invoice_item

           OR /sapsrm/if_pdo_obj_types_c=>gc_pdo_be_iv_lo

           OR /sapsrm/if_pdo_obj_types_c=>gc_pdo_be_iv_lo_item  .

            es_status_description-status_description = text-054.

* Bid Invitation

          WHEN /sapsrm/if_pdo_obj_types_c=>gc_pdo_biddingdoc

           OR /sapsrm/if_pdo_obj_types_c=>gc_pdo_biddoc_item

           OR /sapsrm/if_pdo_obj_types_c=>gc_pdo_quot_item

           OR /sapsrm/if_pdo_obj_types_c=>gc_pdo_quotation  .

            es_status_description-status_description = text-055.

* Auction

          WHEN /sapsrm/if_pdo_obj_types_c=>gc_pdo_auction

           OR /sapsrm/if_pdo_obj_types_c=>gc_pdo_auction_item.

            es_status_description-status_description = text-056.

* Contract

          WHEN /sapsrm/if_pdo_obj_types_c=>gc_pdo_contract

           OR /sapsrm/if_pdo_obj_types_c=>gc_pdo_contract_item

           OR /sapsrm/if_pdo_obj_types_c=>gc_pdo_be_ctr_item.

            es_status_description-status_description = text-057.

* when a limit item is included along with the service, RFx is created

* for the service but the limit item status should be blank.

* Here, bus type will be always BUS2121001.

          WHEN ‘BUS2121001’.

            CLEAR es_status_description-status_description.

* Withdrawal

          WHEN lc_objtype_storage.

            es_status_description-status_description = text-062.

*  hopefully the rest are purchase orders

          WHEN OTHERS.

            CLEAR ls_item_history.

            es_status_description-status_description = text-052.

* we need to check if any purchase order is in deleted state out of the list of backend POs, if so set the status to purchase order deleted

            LOOP AT lt_item_history INTO ls_item_history WHERE objtype = /sapsrm/if_pdo_obj_types_c=>gc_pdo_be_po

                                                         AND   status EQ ‘I1040’.

              es_status_description-status_description = text-066.

              EXIT.

            ENDLOOP.

        ENDCASE.

      ENDIF.

    ENDIF.

    WRITE: /’Status:’, es_status_description-status_description.

    CLEAR: es_status_description.

  ELSE.

    WRITE: /’Item Status other than I1113′.

  ENDIF.

ENDLOOP.

To report this post you need to login first.

4 Comments

You must be Logged on to comment or reply to a post.

  1. johnson george

    Hi Sasikant,

    We have a similar requirement as you had posted in one of the discussions.

    We need to enable the Add button for Contract for the limit SC for the Product Cat in ECS scenario.

    Can you please help me out , how you achieved it?

    It would be of great help if there is any document of any sort.

    Please mail it to me @ johny.g9@gmail.com.

    Thanks

    Johnson George

    (0) 
  2. Andreas Brinkmann

    Dear Sasikant,

    nice coding there. Can you provide Information about the text elements you used ? I guess u made up some Z-messageclass or something ?

    Best regards

    Andy

    (0) 
    1. SASIKANTH SM Post author

      Hi Andy, This code is copy from standard method /SAPSRM/IF_PDO_DO_STATUS~GET_STATUS_TEXT. Please refer this class method for text elements. Regards, Sasi

      (0) 
      1. Andreas Brinkmann

        Hi Sasikant,

        thanks for your reply, i found it by myself but forgot to update the Information here.

        Anyway, your post was very very helpful. Thanks again.

        Regards, Andy

        (0) 

Leave a Reply