cancel
Showing results for 
Search instead for 
Did you mean: 

SRM Shopping Cart Multiple Line Items - Approvers get clubbed

Former Member
0 Kudos
497

Hi Experts,

We are in SRM 7.02 and working on Process Controlled workflow, using BRF.

Custom Workflow for Shopping Cart is based on Account Assignment Category and approval limit.

We are using decision type 3 for the approval process. When it is a Non Catalog item, first step is buyer and second step is Finance Approval.

To implement this workflow, Custom BADI of /SAPSRM/BD_WF_RESP_RESOLVER and classes (ZCL_IM_WF_RR_MANAGER_BUYER and ZCL_IM_WF_RR_MANAGER_APPROVER) have been implemented. Workflow works fine when there is one line item is ordered.

However, when there are more than one line item is ordered, Finance approvers at different levels are getting clubbed together.

Example: Ideally this should happen.

Item 1 - Level 1 - Buyer 1

Level 2 - Approver 1

Item 2 - Level 1 - Buyer 1

Level 2 - Approver 2

In reality below is displayed.

Item 1 - Level 1 - Buyer 1

Level 2 - Approver 1, Approver 2

Item 2 - Level 1 - Buyer 1

Level 2 - Approver 1, Approver 2

I would really appreciate if you could suggest/share your inputs on this. I have already debugged the issue and in debugging I was able to see both approvers correctly on different rows.

However, the same is not getting reflected when Shopping Cart is being ordered/checked.

I have used the responsible resolver badi and the methods area to item map and get approvers by area guid.

I am finding Approvers/buyers in method /SAPSRM/IF_EX_WF_RESP_RESOLVER~GET_APPROVERS_BY_AREA_GUID.

Below is my code for methods /SAPSRM/IF_EX_WF_RESP_RESOLVER~GET_APPROVERS_BY_AREA_GUID and /SAPSRM/IF_EX_WF_RESP_RESOLVER~GET_AREA_TO_ITEM_MAP respectively.

Code -  GET_AREA_TO_ITEM_MAP

METHOD /SAPSRM/IF_EX_WF_RESP_RESOLVER~GET_AREA_TO_ITEM_MAP.

*----------------------------------------------------------------------*

* This implementation returns the manager of the document owners

*----------------------------------------------------------------------*

  TYPES: BEGIN OF TY_LS_ITEM_PGRP_MAP,

           PURCH_GRP_ID TYPE HROBJID,

           ITEM_GUID    TYPE BBP_GUID,

         END OF TY_LS_ITEM_PGRP_MAP.

  DATA LO_WF_PDO_SC        TYPE REF TO /SAPSRM/IF_WF_PDO_SC.

  DATA LO_PDO_SC           TYPE REF TO /SAPSRM/IF_PDO_BO_SC.

  DATA LS_HEADER           TYPE BBP_PDS_SC_HEADER_D.

  DATA LT_HEADER_GUID      TYPE BBPT_GUID.

  DATA LS_HEADER_GUID      TYPE BBP_GUID_TAB.

  DATA LT_ITEM_GUID        TYPE /SAPSRM/T_PDO_HIER_GUID_LIST.

  DATA LR_ITEM_GUID        TYPE REF TO /SAPSRM/S_PDO_HIER_GUID_LIST.

  DATA LT_ORGDATA          TYPE BBPT_PDS_ORG.

  DATA LR_ORGDATA          TYPE REF TO BBP_PDS_ORG.

  DATA LT_ITEM_TO_PGRP_MAP TYPE STANDARD TABLE OF TY_LS_ITEM_PGRP_MAP.

  DATA LS_ITEM_TO_PGRP_MAP TYPE TY_LS_ITEM_PGRP_MAP.

  DATA LR_ITEM_TO_PGRP_MAP TYPE REF TO TY_LS_ITEM_PGRP_MAP.

  DATA LO_AREA             TYPE REF TO /SAPSRM/IF_WF_AREA.

  DATA LS_AREA_TO_ITEM_MAP TYPE /SAPSRM/S_WF_ITEM_TO_AREA.

  DATA LX_PDO_EX           TYPE REF TO CX_STATIC_CHECK.

  DATA LT_ITEM             TYPE BBPT_PD_SC_ITEM_D.

  DATA LS_ITEM             TYPE BBP_PDS_SC_ITEM_D.

  DATA LT_DOCUMENT_RESPONSIBLE  TYPE /SAPSRM/T_WF_APPROVER.

*  DATA LO_AREA                  TYPE REF TO /SAPSRM/IF_WF_AREA.

*  DATA LS_AREA_TO_ITEM_MAP      TYPE /SAPSRM/S_WF_ITEM_TO_AREA.

  DATA : LI_ITEM  TYPE STANDARD TABLE OF BBP_PDS_SC_ITEM_D,

         LWA_ITEM TYPE BBP_PDS_SC_ITEM_D.

* Input checks

  ASSERT ID /SAPSRM/WF_CFG CONDITION ( NOT IS_DOCUMENT IS INITIAL ).

  IF IS_DOCUMENT IS INITIAL.

    RAISE EXCEPTION TYPE /SAPSRM/CX_WF_ABORT.

  ENDIF.

* Determine document owner and his manager

  LT_DOCUMENT_RESPONSIBLE = GET_DOCUMENT_RESPONSIBLE(

    IV_DOCUMENT_GUID        = IS_DOCUMENT-DOCUMENT_GUID

    IV_DOCUMENT_TYPE        = IS_DOCUMENT-DOCUMENT_TYPE

    ).

* Create responsibility area

      LO_AREA = /SAPSRM/CL_WF_AREA=>/SAPSRM/IF_WF_AREA~CREATE_INSTANCE(

        IV_AREA_TYPE         = /SAPSRM/IF_WF_PROCESS_C=>GC_AREA_TYPE_MANAGER "LC_RESPONSIBLECLASS "'ZCL_IM_WF_AREA_APPROVER' "

        IV_LEADING_OBJECT_ID = LT_DOCUMENT_RESPONSIBLE

        ).

* All items are assigned to a single area

      LS_AREA_TO_ITEM_MAP-AREA_GUID = LO_AREA->GET_GUID( ).

* Return responsibility area GUID ... w/o item assignment (nil GUID)

      LS_AREA_TO_ITEM_MAP-ITEM_GUID = /SAPSRM/IF_WF_PROCESS_C=>GC_NIL_GUID.

      APPEND LS_AREA_TO_ITEM_MAP TO RT_ITEM_TO_AREA_MAP.

ENDMETHOD.

Code - GET_APPROVERS_BY_AREA_GUID

METHOD /SAPSRM/IF_EX_WF_RESP_RESOLVER~GET_APPROVERS_BY_AREA_GUID.

  TYPES : BEGIN OF LT_JEST,

            OBJNR TYPE CRM_JEST-OBJNR,

            STAT  TYPE CRM_JEST-STAT,

            INACT TYPE CRM_JEST-INACT,

          END OF LT_JEST.

  DATA : LI_JEST  TYPE STANDARD TABLE OF LT_JEST ##NEEDED,

         LWA_JEST TYPE LT_JEST ##NEEDED,

         LV_STAT  TYPE CRM_JEST-STAT ##NEEDED.

  DATA: INFO    TYPE RFCSI ##NEEDED,

        MSG(80) VALUE SPACE ##NEEDED.

  TYPES: BEGIN OF LT_FINAL,

*           LV_CATID     TYPE COMT_CATEGORY_ID,

           LV_QUANT     TYPE BBP_MNG,

           LV_PRICE     TYPE BBP_PRICE,

           LV_CURR      TYPE WAERS,

           LV_ACCCAT    TYPE BBP_ACC_CAT,

           LV_COSTCTR   TYPE KOSTL,

           LV_ASSETNO   TYPE ANLN1,

           LV_ORDERNO   TYPE AUFNR,

           LV_COAREA    TYPE KOKRS,

           LV_PROFITCTR TYPE PRCTR,

           LV_WBSELEM   TYPE BBP_WBS_ELEM,

           LV_NETWORK   TYPE NPLNR,

           LV_ACTIVITY  TYPE VORNR,

           LV_VALUE     TYPE BBP_VALUE,

           LV_PURCHGRP  TYPE EKGRP,

           LV_PURCHORG  TYPE EKORG,

           LV_COCODE    TYPE BUKRS,

           LV_CREATEDBY TYPE ERNAM,

           LV_PLANT     TYPE BE_EWERK,

           LV_DOCTYPE   TYPE BBSRT,

           MEINS        TYPE BBP_MNG,

           WAERS        TYPE WAERS,

         END OF LT_FINAL.

  DATA: LO_AREA       TYPE REF TO /SAPSRM/IF_WF_AREA,

        LS_APPROVER   TYPE /SAPSRM/S_WF_APPROVER,

        LI_ITEM       TYPE STANDARD TABLE OF BBP_PDS_SC_ITEM_D,

        LWA_ITEM      TYPE BBP_PDS_SC_ITEM_D,

        LWA_HEADER    TYPE BBP_PDS_SC_HEADER_D,

        LI_ACCOUNT    TYPE STANDARD TABLE OF BBP_PDS_ACC,

        LI_STATUS     TYPE STANDARD TABLE OF BBP_PDS_STATUS,

        LWA_STATUS    TYPE BBP_PDS_STATUS ##NEEDED,

        LWA_ACCOUNT   TYPE BBP_PDS_ACC,

        LI_FINAL      TYPE STANDARD TABLE OF LT_FINAL,

        LI_APPROVERS  TYPE STANDARD TABLE OF SWHACTOR,

        LWA_APPROVERS TYPE SWHACTOR,

        LWA_FINAL     TYPE LT_FINAL,

        LV_RFCDEST    TYPE STRING.

* Input checks

  ASSERT ID /SAPSRM/WF_CFG CONDITION ( NOT IS_AREA IS INITIAL ).

  IF IS_AREA IS INITIAL.

    RETURN.

  ENDIF.

* Activate fallback agents

  IF IS_AREA-AREA_GUID = /SAPSRM/IF_WF_PROCESS_C=>GC_NIL_GUID.

    RETURN.

  ENDIF.

* Get responsibility area reference for given area GUID

  LO_AREA = /SAPSRM/CL_WF_AREA=>/SAPSRM/IF_WF_AREA~GET_INSTANCE_BY_GUID(

    IV_AREA_TYPE = /SAPSRM/IF_WF_PROCESS_C=>GC_AREA_TYPE_MANAGER    "LC_RESPONSIBLECLASS "

    IV_AREA_GUID = IS_AREA-AREA_GUID

    ).

  CALL FUNCTION 'BBP_PD_SC_GETDETAIL'

    EXPORTING

      I_GUID          = IS_DOCUMENT-DOCUMENT_GUID

      I_WITH_ITEMDATA = 'X'

    IMPORTING

      E_HEADER        = LWA_HEADER

    TABLES

      E_ITEM          = LI_ITEM

      E_ACCOUNT       = LI_ACCOUNT

      E_STATUS        = LI_STATUS.

  CLEAR LWA_ITEM.

  DELETE LI_ACCOUNT WHERE DEL_IND = 'X'.

  SORT LI_ACCOUNT BY DISTR_PERC DESCENDING DIST_QUAN DESCENDING DIST_VALUE DESCENDING.

  LOOP AT LI_ITEM INTO LWA_ITEM.

    CLEAR LWA_ACCOUNT.

    READ TABLE LI_ACCOUNT INTO LWA_ACCOUNT WITH KEY P_GUID = LWA_ITEM-GUID BINARY SEARCH.

    IF SY-SUBRC = 0.

      CLEAR LWA_FINAL.

      LWA_FINAL-LV_QUANT = LWA_ITEM-QUANTITY.

      LWA_FINAL-LV_PRICE = LWA_ITEM-PRICE.

      LWA_FINAL-LV_CURR = LWA_ITEM-CURRENCY.

      CASE LWA_ACCOUNT-ACC_CAT.

        WHEN 'CC'.

          CLEAR LWA_FINAL-LV_ACCCAT.

          LWA_FINAL-LV_ACCCAT = 'K'.

        WHEN 'AS'.

          CLEAR LWA_FINAL-LV_ACCCAT.

          LWA_FINAL-LV_ACCCAT = 'A'.

        WHEN 'NET'.

          CLEAR LWA_FINAL-LV_ACCCAT.

          LWA_FINAL-LV_ACCCAT = 'N'.

        WHEN 'OR'.

          CLEAR LWA_FINAL-LV_ACCCAT.

          LWA_FINAL-LV_ACCCAT = 'F'.

        WHEN 'WBS'.

          CLEAR LWA_FINAL-LV_ACCCAT.

          LWA_FINAL-LV_ACCCAT = 'P'.

      ENDCASE.

      LWA_FINAL-LV_COSTCTR = LWA_ACCOUNT-COST_CTR.

      LWA_FINAL-LV_ASSETNO = LWA_ACCOUNT-ASSET_NO.

      LWA_FINAL-LV_ORDERNO = LWA_ACCOUNT-ORDER_NO.

      LWA_FINAL-LV_COAREA  = LWA_ACCOUNT-CO_AREA.

      LWA_FINAL-LV_PROFITCTR = LWA_ACCOUNT-PROFIT_CTR.

      LWA_FINAL-LV_WBSELEM = LWA_ACCOUNT-WBS_ELEM_E.

      LWA_FINAL-LV_NETWORK = LWA_ACCOUNT-NETWORK.

      LWA_FINAL-LV_ACTIVITY = LWA_ACCOUNT-ACTIVITY.

      IF LWA_ACCOUNT-DIST_VALUE IS NOT INITIAL OR LWA_ACCOUNT-DIST_VALUE <> 0.

        LWA_FINAL-LV_VALUE = LWA_ACCOUNT-DIST_VALUE. "LWA_ITEM-VALUE. Change on 19.02.2016 - 4kama8417

      ELSEIF LWA_ACCOUNT-DIST_QUAN IS NOT INITIAL OR LWA_ACCOUNT-DIST_QUAN <> 0.

        LWA_FINAL-LV_VALUE = LWA_ACCOUNT-DIST_QUAN * LWA_ITEM-PRICE.

      ELSE.

        LWA_FINAL-LV_VALUE = ( LWA_ITEM-VALUE * LWA_ACCOUNT-DISTR_PERC ) / 100 .

      ENDIF.

      LWA_FINAL-LV_COCODE = LWA_ITEM-BE_CO_CODE.

      LWA_FINAL-LV_CREATEDBY = LWA_HEADER-CREATED_BY.

      LWA_FINAL-LV_PLANT = LWA_ITEM-BE_PLANT.

      LWA_FINAL-LV_DOCTYPE = LWA_ITEM-BE_DOC_TYPE.

      IF LWA_ACCOUNT-COST_CTR NE ' ' OR LWA_ACCOUNT-ASSET_NO NE ' '

        OR LWA_ACCOUNT-ORDER_NO NE ' ' OR LWA_ACCOUNT-PROFIT_CTR NE ' '

        OR LWA_ACCOUNT-WBS_ELEM_E NE ' ' OR LWA_ACCOUNT-NETWORK NE ' '

        OR LWA_ACCOUNT-ACTIVITY NE ' '.

        APPEND LWA_FINAL TO LI_FINAL.

      ENDIF.

    ENDIF. " ADDITIONAL CODE 03.12.2015

    CLEAR : LWA_FINAL, LWA_ITEM.

  ENDLOOP.

* Return all responsible users assigned to that area

  RT_APPROVER = LO_AREA->GET_RESPONSIBLE_APPROVERS( ).

  REFRESH RT_APPROVER[].

  IF RT_APPROVER[] IS INITIAL.

    IF LI_FINAL IS NOT INITIAL. "ADDITIONAL CODE 03.12.2015

      CALL FUNCTION 'ZPSC_FM_RFC_GETSCAPPROVER'

        DESTINATION LV_RFCDEST

        EXPORTING

          IM_FINAL              = LI_FINAL

        IMPORTING

          T_APPROVERS           = LI_APPROVERS

        EXCEPTIONS

          COMMUNICATION_FAILURE = 1 MESSAGE MSG

          SYSTEM_FAILURE        = 2 MESSAGE MSG.

      IF SY-SUBRC = 0.

        LOOP AT LI_APPROVERS INTO LWA_APPROVERS.

          LS_APPROVER-APPROVER_OT = LWA_APPROVERS-OTYPE.

          LS_APPROVER-APPROVER_ID = LWA_APPROVERS-OBJID.

          APPEND LS_APPROVER TO RT_APPROVER.

          CLEAR LS_APPROVER.

        ENDLOOP.

      ENDIF.

    ENDIF.

  ENDIF.

ENDMETHOD.

Kindly do let me know if I am missing anything. Appreciate your reply.

Thank you.

Best Regards.

Accepted Solutions (1)

Accepted Solutions (1)

laurent_burtaire
Active Contributor
0 Kudos

Hello Abhijit,

your responsability area assignment is not correct: you create only one area guid in method /SAPSRM/IF_EX_WF_RESP_RESOLVER~GET_AREA_TO_ITEM_MAP.

For financial approvers in your example, you should have two area guid. This means item assignement cannot be null (as there is more than one area guid).

Finally:

- IV_LEADING_OBJECT_ID cannot be the document responsible: it has to be defining criterion for each Financial approver (i guess, in your case, account assignment category),

- IV_AREA_TYPE cannot be /SAPSRM/IF_WF_PROCESS_C=>GC_AREA_TYPE_MANAGER class. It has to be the Z class you create to get responsible approvers (Financial approvers, based on account assignment category).


Check ABAP code in /SAPSRM/IF_EX_WF_RESP_RESOLVER~GET_AREA_TO_ITEM_MAP method from BAdI implementation /SAPSRM/BD_WF_SC_RR_PGRP (Enhancement implementation /SAPSRM/BD_WF_AGENTS_SC).

Regards.

Laurent.

Former Member
0 Kudos

Hi Laurent,

Thank you very much for your reply.

I have modified the code. I am not fetching approvers from custom Z class. I am fetching these details in Area_guid. Is it mandatory to fetch the approvers from a Z class ? Because even after changing ITEM_MAP method I could see appprovers are getting clubbed.

Please find below code of Item map and Area Guid. My understanding was we do not require to implement Get_responsible_Approver method from /SAPSRM/CL_WF_AREA_MANAGER.

Kindly confirm my understanding and also check my modified code. I would appreciate if you could review.

Item_Map

METHOD /SAPSRM/IF_EX_WF_RESP_RESOLVER~GET_AREA_TO_ITEM_MAP.

*----------------------------------------------------------------------*

* This implementation returns the manager of the document owners

*----------------------------------------------------------------------*

  TYPES: BEGIN OF TY_LS_ITEM_PGRP_MAP,

           PURCH_GRP_ID TYPE HROBJID,

           ITEM_GUID    TYPE BBP_GUID,

         END OF TY_LS_ITEM_PGRP_MAP.

  DATA LO_WF_PDO_SC        TYPE REF TO /SAPSRM/IF_WF_PDO_SC.

  DATA LO_PDO_SC           TYPE REF TO /SAPSRM/IF_PDO_BO_SC.

  DATA LS_HEADER           TYPE BBP_PDS_SC_HEADER_D.

  DATA LT_HEADER_GUID      TYPE BBPT_GUID.

  DATA LS_HEADER_GUID      TYPE BBP_GUID_TAB.

  DATA LT_ITEM_GUID        TYPE /SAPSRM/T_PDO_HIER_GUID_LIST.

  DATA LR_ITEM_GUID        TYPE REF TO /SAPSRM/S_PDO_HIER_GUID_LIST.

  DATA LT_ORGDATA          TYPE BBPT_PDS_ORG.

  DATA LR_ORGDATA          TYPE REF TO BBP_PDS_ORG.

  DATA LT_ITEM_TO_PGRP_MAP TYPE STANDARD TABLE OF TY_LS_ITEM_PGRP_MAP.

  DATA LS_ITEM_TO_PGRP_MAP TYPE TY_LS_ITEM_PGRP_MAP.

  DATA LR_ITEM_TO_PGRP_MAP TYPE REF TO TY_LS_ITEM_PGRP_MAP.

  DATA LO_AREA             TYPE REF TO /SAPSRM/IF_WF_AREA.

  DATA LS_AREA_TO_ITEM_MAP TYPE /SAPSRM/S_WF_ITEM_TO_AREA.

  DATA LX_PDO_EX           TYPE REF TO CX_STATIC_CHECK.

  DATA LT_ITEM             TYPE BBPT_PD_SC_ITEM_D.

  DATA LS_ITEM             TYPE BBP_PDS_SC_ITEM_D.

  DATA LT_DOCUMENT_RESPONSIBLE  TYPE /SAPSRM/T_WF_APPROVER.

*  DATA LO_AREA                  TYPE REF TO /SAPSRM/IF_WF_AREA.

*  DATA LS_AREA_TO_ITEM_MAP      TYPE /SAPSRM/S_WF_ITEM_TO_AREA.

  DATA : LI_ITEM  TYPE STANDARD TABLE OF BBP_PDS_SC_ITEM_D,

         LWA_ITEM TYPE BBP_PDS_SC_ITEM_D.

ASSERT ID /SAPSRM/WF_CFG CONDITION ( NOT IS_DOCUMENT IS INITIAL ).

  ASSERT ID /SAPSRM/WF_CFG CONDITION ( IS_DOCUMENT-DOCUMENT_TYPE EQ /SAPSRM/IF_PDO_OBJ_TYPES_C=>GC_PDO_SHOP ).

  IF IS_DOCUMENT IS INITIAL OR

     IS_DOCUMENT-DOCUMENT_TYPE NE /SAPSRM/IF_PDO_OBJ_TYPES_C=>GC_PDO_SHOP.

    RAISE EXCEPTION TYPE /SAPSRM/CX_WF_ABORT.

  ENDIF.

*----------------------------------------------------------------------*

* (1) Get the Shopping Cart's item list ...

*----------------------------------------------------------------------*

* Get shopping cart instance

  LO_WF_PDO_SC ?= /SAPSRM/CL_WF_PDO_IMPL_FACTORY=>GET_INSTANCE(

    IV_DOCUMENT_GUID = IS_DOCUMENT-DOCUMENT_GUID

    IV_DOCUMENT_TYPE = IS_DOCUMENT-DOCUMENT_TYPE

    IV_PDO_EVENT_HANDLING = ABAP_FALSE

    ).

  TRY.

      LO_PDO_SC ?= LO_WF_PDO_SC->/SAPSRM/IF_WF_PDO~GET_PDO( ).

* get leaf items

      LT_ITEM_GUID = LO_WF_PDO_SC->/SAPSRM/IF_WF_PDO~GET_ITEM_LIST( ).

    CATCH /SAPSRM/CX_PDO_WRONG_BUS_TYPE

          /SAPSRM/CX_PDO_PD_READ_ERROR

          /SAPSRM/CX_PDO_LOCK_FAILED

          /SAPSRM/CX_PDO_NO_AUTHORIZATIO

          /SAPSRM/CX_PDO_PARAMETER_ERROR

          /SAPSRM/CX_PDO_STATUS_ERROR

          /SAPSRM/CX_PDO_INCONS_USER

          /SAPSRM/CX_PDO_ERROR

          INTO LX_PDO_EX.

      RAISE EXCEPTION TYPE /SAPSRM/CX_WF_ERROR

        EXPORTING

          PREVIOUS = LX_PDO_EX.

    CATCH /SAPSRM/CX_PDO_ABORT INTO LX_PDO_EX.

      RAISE EXCEPTION TYPE /SAPSRM/CX_WF_ABORT

        EXPORTING

          PREVIOUS = LX_PDO_EX.

  ENDTRY.

*----------------------------------------------------------------------------*

* (2) Get purchasing group of each item

*     - (only item leafs included) -

*----------------------------------------------------------------------*

  LOOP AT LT_ITEM_GUID REFERENCE INTO LR_ITEM_GUID WHERE LEAF = ABAP_TRUE.

    LS_ITEM_TO_PGRP_MAP-ITEM_GUID = LR_ITEM_GUID->GUID.

    TRY.

        CALL METHOD LO_PDO_SC->GET_ITEM_DETAIL

          EXPORTING

            IV_ITEM_GUID = LS_ITEM_TO_PGRP_MAP-ITEM_GUID

          IMPORTING

            ET_ITEM      = LT_ITEM

            ET_ORGDATA   = LT_ORGDATA.

        READ TABLE LT_ITEM INDEX 1 INTO LS_ITEM.

        IF LS_ITEM-DEL_IND EQ ABAP_TRUE.

          CONTINUE.

        ENDIF.

        LOOP AT LT_ORGDATA REFERENCE INTO LR_ORGDATA.

          LS_ITEM_TO_PGRP_MAP-PURCH_GRP_ID = LR_ORGDATA->PROC_GROUP_ID.

          EXIT. "each item has exactly one p.-org/group pair

        ENDLOOP.

        APPEND LS_ITEM_TO_PGRP_MAP TO LT_ITEM_TO_PGRP_MAP.

      CATCH /SAPSRM/CX_PDO_NO_AUTHORIZATIO INTO LX_PDO_EX.

        RAISE EXCEPTION TYPE /SAPSRM/CX_WF_ERROR

          EXPORTING

            PREVIOUS = LX_PDO_EX.

      CATCH /SAPSRM/CX_PDO_ABORT INTO LX_PDO_EX.

        RAISE EXCEPTION TYPE /SAPSRM/CX_WF_ABORT

          EXPORTING

            PREVIOUS = LX_PDO_EX.

    ENDTRY.

  ENDLOOP.

*----------------------------------------------------------------------*

* (3) Return document item - responsibility area assignment

*----------------------------------------------------------------------*

* The item list is sorted according to the characteristics of an

* responsibility area (i.e. according to the purch. group ID here)

  SORT LT_ITEM_TO_PGRP_MAP.

  LOOP AT LT_ITEM_TO_PGRP_MAP REFERENCE INTO LR_ITEM_TO_PGRP_MAP.

    AT NEW ITEM_GUID. "PURCH_GRP_ID.

*     For each purchasing group a new responsibility area is created, which is

*     an instance of class /SAPSRM/CL_WF_AREA_PURCH_GRP; this instance can

*     later be retrieved by the org.-unit ID ("leading object ID") in

*     method GET_APPROVERS_BY_AREA_GUID to return the list of responsible

*     agents of this purchasing group

      LO_AREA = /SAPSRM/CL_WF_AREA=>/SAPSRM/IF_WF_AREA~CREATE_INSTANCE(

        IV_AREA_TYPE         = /SAPSRM/IF_WF_PROCESS_C=>GC_AREA_TYPE_PURCH_GRP "/SAPSRM/IF_WF_PROCESS_C=>GC_AREA_TYPE_MANAGER "/SAPSRM/IF_WF_PROCESS_C=>GC_AREA_TYPE_PURCH_GRP

        IV_LEADING_OBJECT_ID = LR_ITEM_TO_PGRP_MAP->ITEM_GUID

        ).

      LS_AREA_TO_ITEM_MAP-AREA_GUID = LO_AREA->GET_GUID( ).

    ENDAT.

    LS_AREA_TO_ITEM_MAP-ITEM_GUID = LR_ITEM_TO_PGRP_MAP->ITEM_GUID.

    APPEND LS_AREA_TO_ITEM_MAP TO RT_ITEM_TO_AREA_MAP.

  ENDLOOP.

* e.g. during document creation before adding of any items

  IF SY-SUBRC NE 0.

* Create responsibility area

    LO_AREA = /SAPSRM/CL_WF_AREA=>/SAPSRM/IF_WF_AREA~CREATE_INSTANCE(

      IV_AREA_TYPE            = /SAPSRM/IF_WF_PROCESS_C=>GC_AREA_TYPE_MANAGER

      IV_LEADING_OBJECT_ID    = SPACE

      ).

    LS_AREA_TO_ITEM_MAP-AREA_GUID = LO_AREA->GET_GUID( ).

* Return responsibility area GUID ... w/o item assignment (nil GUID)

    LS_AREA_TO_ITEM_MAP-ITEM_GUID = /SAPSRM/IF_WF_PROCESS_C=>GC_NIL_GUID.

    APPEND LS_AREA_TO_ITEM_MAP TO RT_ITEM_TO_AREA_MAP.

  ENDIF.

ENDMETHOD.

Area_Guid

METHOD /SAPSRM/IF_EX_WF_RESP_RESOLVER~GET_APPROVERS_BY_AREA_GUID.

  TYPES : BEGIN OF LT_JEST,

            OBJNR TYPE CRM_JEST-OBJNR,

            STAT  TYPE CRM_JEST-STAT,

            INACT TYPE CRM_JEST-INACT,

          END OF LT_JEST.

  DATA : LI_JEST  TYPE STANDARD TABLE OF LT_JEST ##NEEDED,

         LWA_JEST TYPE LT_JEST ##NEEDED,

         LV_STAT  TYPE CRM_JEST-STAT ##NEEDED.

  DATA: INFO    TYPE RFCSI ##NEEDED,

        MSG(80) VALUE SPACE ##NEEDED.

  TYPES: BEGIN OF LT_FINAL,

*           LV_CATID     TYPE COMT_CATEGORY_ID,

           LV_QUANT     TYPE BBP_MNG,

           LV_PRICE     TYPE BBP_PRICE,

           LV_CURR      TYPE WAERS,

           LV_ACCCAT    TYPE BBP_ACC_CAT,

           LV_COSTCTR   TYPE KOSTL,

           LV_ASSETNO   TYPE ANLN1,

           LV_ORDERNO   TYPE AUFNR,

           LV_COAREA    TYPE KOKRS,

           LV_PROFITCTR TYPE PRCTR,

           LV_WBSELEM   TYPE BBP_WBS_ELEM,

           LV_NETWORK   TYPE NPLNR,

           LV_ACTIVITY  TYPE VORNR,

           LV_VALUE     TYPE BBP_VALUE,

           LV_PURCHGRP  TYPE EKGRP,

           LV_PURCHORG  TYPE EKORG,

           LV_COCODE    TYPE BUKRS,

           LV_CREATEDBY TYPE ERNAM,

           LV_PLANT     TYPE BE_EWERK,

           LV_DOCTYPE   TYPE BBSRT,

           MEINS        TYPE BBP_MNG,

           WAERS        TYPE WAERS,

         END OF LT_FINAL.

  DATA: LO_AREA       TYPE REF TO /SAPSRM/IF_WF_AREA,

        LS_APPROVER   TYPE /SAPSRM/S_WF_APPROVER,

        LI_ITEM       TYPE STANDARD TABLE OF BBP_PDS_SC_ITEM_D,

        LWA_ITEM      TYPE BBP_PDS_SC_ITEM_D,

        LWA_HEADER    TYPE BBP_PDS_SC_HEADER_D,

        LI_ACCOUNT    TYPE STANDARD TABLE OF BBP_PDS_ACC,

        LI_STATUS     TYPE STANDARD TABLE OF BBP_PDS_STATUS,

        LWA_STATUS    TYPE BBP_PDS_STATUS ##NEEDED,

        LWA_ACCOUNT   TYPE BBP_PDS_ACC,

        LI_FINAL      TYPE STANDARD TABLE OF LT_FINAL,

        LI_APPROVERS  TYPE STANDARD TABLE OF SWHACTOR,

        LWA_APPROVERS TYPE SWHACTOR,

        LWA_FINAL     TYPE LT_FINAL,

        LV_RFCDEST    TYPE STRING.

  CONSTANTS : LC_RESPONSIBLECLASS TYPE SWF_CLSNAM VALUE 'ZCL_IM_WF_AREA_APPROVER' ##NEEDED.

ASSERT ID /SAPSRM/WF_CFG CONDITION ( NOT IS_AREA IS INITIAL ).

  IF IS_AREA IS INITIAL.

    RETURN.

  ENDIF.

* Activate fallback agents

  IF IS_AREA-AREA_GUID = /SAPSRM/IF_WF_PROCESS_C=>GC_NIL_GUID.

    RETURN.

  ENDIF.

* Get responsibility area reference for given area GUID

  LO_AREA = /SAPSRM/CL_WF_AREA=>/SAPSRM/IF_WF_AREA~GET_INSTANCE_BY_GUID(

    IV_AREA_TYPE = /SAPSRM/IF_WF_PROCESS_C=>GC_AREA_TYPE_PURCH_GRP "/SAPSRM/IF_WF_PROCESS_C=>GC_AREA_TYPE_MANAGER    "LC_RESPONSIBLECLASS "

    IV_AREA_GUID = IS_AREA-AREA_GUID

    ).

  CALL FUNCTION 'BBP_PD_SC_GETDETAIL'

    EXPORTING

      I_GUID          = IS_DOCUMENT-DOCUMENT_GUID

      I_WITH_ITEMDATA = 'X'

    IMPORTING

      E_HEADER        = LWA_HEADER

    TABLES

      E_ITEM          = LI_ITEM

      E_ACCOUNT       = LI_ACCOUNT

      E_STATUS        = LI_STATUS.

  CLEAR LWA_ITEM.

  DELETE LI_ACCOUNT WHERE DEL_IND = 'X'.

  SORT LI_ACCOUNT BY DISTR_PERC DESCENDING DIST_QUAN DESCENDING DIST_VALUE DESCENDING.

  LOOP AT LI_ITEM INTO LWA_ITEM.

    CLEAR LWA_ACCOUNT.

    READ TABLE LI_ACCOUNT INTO LWA_ACCOUNT WITH KEY P_GUID = LWA_ITEM-GUID BINARY SEARCH. "Commented on 18.02.2016 4kama8417

    IF SY-SUBRC = 0.

      CLEAR LWA_FINAL.

      LWA_FINAL-LV_QUANT = LWA_ITEM-QUANTITY.

      LWA_FINAL-LV_PRICE = LWA_ITEM-PRICE.

      LWA_FINAL-LV_CURR = LWA_ITEM-CURRENCY.

      CASE LWA_ACCOUNT-ACC_CAT.

        WHEN 'CC'.

          CLEAR LWA_FINAL-LV_ACCCAT.

          LWA_FINAL-LV_ACCCAT = 'K'.

        WHEN 'AS'.

          CLEAR LWA_FINAL-LV_ACCCAT.

          LWA_FINAL-LV_ACCCAT = 'A'.

        WHEN 'NET'.

          CLEAR LWA_FINAL-LV_ACCCAT.

          LWA_FINAL-LV_ACCCAT = 'N'.

        WHEN 'OR'.

          CLEAR LWA_FINAL-LV_ACCCAT.

          LWA_FINAL-LV_ACCCAT = 'F'.

        WHEN 'WBS'.

          CLEAR LWA_FINAL-LV_ACCCAT.

          LWA_FINAL-LV_ACCCAT = 'P'.

      ENDCASE.

      LWA_FINAL-LV_COSTCTR = LWA_ACCOUNT-COST_CTR.

      LWA_FINAL-LV_ASSETNO = LWA_ACCOUNT-ASSET_NO.

      LWA_FINAL-LV_ORDERNO = LWA_ACCOUNT-ORDER_NO.

      LWA_FINAL-LV_COAREA  = LWA_ACCOUNT-CO_AREA.

      LWA_FINAL-LV_PROFITCTR = LWA_ACCOUNT-PROFIT_CTR.

      LWA_FINAL-LV_WBSELEM = LWA_ACCOUNT-WBS_ELEM_E.

      LWA_FINAL-LV_NETWORK = LWA_ACCOUNT-NETWORK.

      LWA_FINAL-LV_ACTIVITY = LWA_ACCOUNT-ACTIVITY.

      IF LWA_ACCOUNT-DIST_VALUE IS NOT INITIAL OR LWA_ACCOUNT-DIST_VALUE <> 0.

        LWA_FINAL-LV_VALUE = LWA_ACCOUNT-DIST_VALUE. "LWA_ITEM-VALUE. Change on 19.02.2016 - 4kama8417

      ELSEIF LWA_ACCOUNT-DIST_QUAN IS NOT INITIAL OR LWA_ACCOUNT-DIST_QUAN <> 0.

        LWA_FINAL-LV_VALUE = LWA_ACCOUNT-DIST_QUAN * LWA_ITEM-PRICE.

      ELSE.

        LWA_FINAL-LV_VALUE = ( LWA_ITEM-VALUE * LWA_ACCOUNT-DISTR_PERC ) / 100 .

      ENDIF.

      LWA_FINAL-LV_COCODE = LWA_ITEM-BE_CO_CODE.

      LWA_FINAL-LV_CREATEDBY = LWA_HEADER-CREATED_BY.

      LWA_FINAL-LV_PLANT = LWA_ITEM-BE_PLANT.

      LWA_FINAL-LV_DOCTYPE = LWA_ITEM-BE_DOC_TYPE.

      IF LWA_ACCOUNT-COST_CTR NE ' ' OR LWA_ACCOUNT-ASSET_NO NE ' '

        OR LWA_ACCOUNT-ORDER_NO NE ' ' OR LWA_ACCOUNT-PROFIT_CTR NE ' '

        OR LWA_ACCOUNT-WBS_ELEM_E NE ' ' OR LWA_ACCOUNT-NETWORK NE ' '

        OR LWA_ACCOUNT-ACTIVITY NE ' '.

        APPEND LWA_FINAL TO LI_FINAL.

      ENDIF.

    ENDIF. " ADDITIONAL CODE 03.12.2015

    CLEAR : LWA_FINAL, LWA_ITEM.

  ENDLOOP.

* Return all responsible users assigned to that area

  RT_APPROVER = LO_AREA->GET_RESPONSIBLE_APPROVERS( ).

  REFRESH RT_APPROVER[].

  IF RT_APPROVER[] IS INITIAL.

    IF LI_FINAL IS NOT INITIAL. "ADDITIONAL CODE 03.12.2015

      CALL FUNCTION 'ZPSC_FM_RFC_GETSCAPPROVER'

        DESTINATION LV_RFCDEST

        EXPORTING

          IM_FINAL              = LI_FINAL

        IMPORTING

          T_APPROVERS           = LI_APPROVERS

        EXCEPTIONS

          COMMUNICATION_FAILURE = 1 MESSAGE MSG

          SYSTEM_FAILURE        = 2 MESSAGE MSG.

      IF SY-SUBRC = 0.

        LOOP AT LI_APPROVERS INTO LWA_APPROVERS.

          LS_APPROVER-APPROVER_OT = LWA_APPROVERS-OTYPE.

          LS_APPROVER-APPROVER_ID = LWA_APPROVERS-OBJID.

          APPEND LS_APPROVER TO RT_APPROVER.

          CLEAR LS_APPROVER.

        ENDLOOP.

      ENDIF.

    ENDIF.

  ENDIF.

ENDMETHOD.

laurent_burtaire
Active Contributor
0 Kudos

Hello,

i advise you to check /SAPSRM/BD_WF_SC_RR_PGRP BAdI implementation in order to understand how is managed:

- area type (instance of /SAPSRM/CL_WF_AREA_XXX to determine the responsible approvers: it cannot be a standard one as none deal with accounting category...),

- leading object (in your case, it cannot be the purchasing group...)

- area guid (not unique as SC items have to be validated by different approvers)

It does not mean you have to copy/paste standard ABAP code (which is used for a precise business need which is not yours...).

Regards.

Laurent.

Former Member
0 Kudos

Hi Laurent,

Please correct my understanding here.

According to me, I will have to make a copy of /SAPSRM/CL_IM_WF_RR_CCTR_SC and in the item map method, instead of at new cost_ctr_id, I will have to check Account Assignment Category as it would never be only cost center id.

Now, my question here is, how would I get details of the Shopping Cart in ZCL_WF_AREA_COST_CTR's responsible approver method. I am passing this class as IV_AREA_TYPE in both area_guid and Item_map method.

My analysis -

1. Create a copy of /SAPSRM/CL_IM_WF_RR_CCTR_SC (ZCL_IM_WF_RR_CCTR_SC) and /SAPSRM/CL_WF_AREA_COST_CTR (ZCL_WF_AREA_COST_CTR).

2. for IV_AREA_TYPE assign ZCL_WF_AREA_COST_CTR, in both area_guid and Item_map. Export item_guid from Item_map and import in to ZCL_WF_AREA_COST_CTR's GET_RESPONSIBLE_APPROVERS.

3. In Item_map get new account assignment Category and it will be obtained ZCL_WF_AREA_COST_CTR at statement - ls_costcenter_id-sobid = me->/sapsrm/if_wf_area~get_leading_object_id( ).

4. In class, ZCL_WF_AREA_COST_CTR, find approvers based on Shopping Cart Details and item guid, obtained from Item_map.


Kindly guide us on above points. Also i am still not sure how my area_guid should not be unique. Please advise.


Thank you.

Former Member
0 Kudos

Hi Laurent,

Kindly advise us. We would appreciate your reply.

Thank you.

Answers (0)