Process: purchase requisition sourcing in SRM.

Requirement: requester of shopping cart must be defined via customer logic. In standard SAP solution requester is always an RFC-User (acces from PI System).

Remarks:

  • Following solution was designed and tested for SRM 7.01 SP 5, for tha purchase requisition transfer via SOA. If you use another version of SRM or PR transfer via RFC – you may need another solution.
  • Solution is realized with enhancements and modifications of standard SAP code. So no warranty and support from SAP.

Solution

Utility class

First of all you may need to create a customer utility class for requester determination.

Class will have a public static attribute and one method.

This attribute indicates the process of shopping cart creation from purchase requisition. Before creation attribute is set ot true, at the end – to false.

Value of the attribute will be used during creation process to differentiate shopping cart creation direct in SRM and via SOA.

Method get_requester is served to get user name of requester for shopping cart. Method implements customer logic and has only one returning parameter RV_UNAME type XUBNAME.

METHOD get_requester.   rv_requestor = 'KANIKEEV'. " Here you should define your customer logic ENDMETHOD.

Enhancements

For this solution you may need to enhance/modify following methods.

First you need to enhance proxy class, which is responsible for XML processing. You may find this class via SPROXY transaction for Interface PurchaseRequestERPSourcingRequest_In.

/SAPSRM/CL_PUR_REQ_ERP_SRC_REQ->/SAPSRM/II_PUR_REQ_ERP_SRC_REQ~PUR_REQ_ERPSRC_REQ

Here you need to create pre- and post-enhancements

Pre-enhancement: ZKSH_EXT_REQ_UTIL=>MV_EXT_REQ_CREATION = ABAP_TRUE.

Post-enhancement: ZKSH_EXT_REQ_UTIL=>MV_EXT_REQ_CREATION = ABAP_FALSE.

/SAPSRM/CL_PDO_BO_SC->GET_REQUESTER_OF_FIRST_ITEM

Here you need to create a post-enhancement.

IF abap_true = zksh_ext_req_utils=>mv_ext_req_creation.   rv_uname = zksh_ext_req_utils=>get_requester( ). ENDIF.

/SAPSRM/CL_CH_SOA_DO_MAP_PARTN->CONSTRUCTOR

Here you need to create a post-enhancement.

  DATA lv_requester TYPE xubname.   IF iv_create_user_context EQ abap_true. * Instantiate user context     TRY.       lv_requester = zksh_ext_req_utils=>get_requester( ).       CALL METHOD /sapsrm/cl_pdo_factory_user=>get_instance_us_context_prov         EXPORTING           iv_user            = lv_requester           iv_application     = iv_application         RECEIVING           ro_us_context_prov = mo_user_context.     CATCH /sapsrm/cx_pdo_incons_user INTO lx_pdo_icons_user.       mo_msg_hdlr->add_exception( io_pdo_error_exception = lx_pdo_icons_user ).     ENDTRY.   ENDIF.

/SAPSRM/CL_CH_SOA_DO_MAP_PLANT=>CONSTRUCTOR

Here you need to create a post-enhancement.

DATA lv_requester TYPE xubname. TRY.   lv_requester = zksh_ext_req_utils=>get_requester( ).   CALL METHOD /sapsrm/cl_pdo_factory_user=>get_instance_us_context_prov     EXPORTING       iv_user            = lv_requester       iv_application     = iv_application     RECEIVING       ro_us_context_prov = mo_user_context. CATCH /sapsrm/cx_pdo_incons_user INTO lx_pdo_icons_user.    mo_msg_hdlr->add_exception( io_pdo_error_exception = lx_pdo_icons_user ). ENDTRY.

/SAPSRM/CL_CH_SOA_DO_MAP_SHTOL->CONSTRUCTOR

Here you need to create a post-enhancement.

DATA lv_requester TYPE xubname. TRY.    lv_requester = zksh_ext_req_utils=>get_requester( ).    CALL METHOD /sapsrm/cl_pdo_factory_user=>get_instance_user_context       EXPORTING         iv_user         = lv_requester         iv_application  = iv_application       RECEIVING         ro_user_context = mo_user_context.   CATCH /sapsrm/cx_pdo_incons_user INTO lx_pdo_icons_user.     mo_msg_hdlr->add_exception( io_pdo_error_exception = lx_pdo_icons_user ). ENDTRY.

/SAPSRM/CL_SOA_PUR_REQ->CREATE_PDO_SC_INSTANCE

Here you need to create a overwrite-enhancement.

METHOD iow_zksh_ei_cl_soa_pur_req~create_pdo_sc_instance. *"------------------------------------------------------------------------* *" Declaration of Overwrite-method, do not insert any comments here please! *" *"methods CREATE_PDO_SC_INSTANCE . *"------------------------------------------------------------------------*     DATA:       lo_pdo_message_handler TYPE REF TO /sapsrm/if_pdo_msg_consumer. * Exceptions     DATA:       lx_pdo_wf_mode_ban      TYPE REF TO /sapsrm/cx_pdo_wf_mode_ban,       lx_pdo_wrong_bus_type   TYPE REF TO /sapsrm/cx_pdo_wrong_bus_type,       lx_pdo_pd_read_error    TYPE REF TO /sapsrm/cx_pdo_pd_read_error,       lx_pdo_lock_failed      TYPE REF TO /sapsrm/cx_pdo_lock_failed,       lx_pdo_no_authorizatio  TYPE REF TO /sapsrm/cx_pdo_no_authorizatio,       lx_pdo_parameter_error  TYPE REF TO /sapsrm/cx_pdo_parameter_error,       lx_pdo_status_error     TYPE REF TO /sapsrm/cx_pdo_status_error,       lx_pdo_incons_user      TYPE REF TO /sapsrm/cx_pdo_incons_user,       lx_pdo_error            TYPE REF TO /sapsrm/cx_pdo_error,       lx_pdo_abort            TYPE REF TO /sapsrm/cx_pdo_abort.     DATA lv_requester TYPE xubname.     TRY. *     Create Shopping Cart instance         lv_requester = zksh_ext_req_utils=>get_requester( ).         CALL METHOD /sapsrm/cl_pdo_factory_sc_adv=>create_new_instance           EXPORTING             iv_uname           = lv_requester             iv_bosubtype       = 'ER'           IMPORTING             eo_message_handler = lo_pdo_message_handler             eo_sc_instance     = me->core_object->mo_pdo_pr.         zsrmcln_ext_req_utils=>set_pdo( me->core_object->mo_pdo_pr ).       CATCH /sapsrm/cx_pdo_wf_mode_ban INTO lx_pdo_wf_mode_ban.         me->core_object->mo_msg_hdlr->add_exception( io_pdo_error_exception = lx_pdo_wf_mode_ban ).       CATCH /sapsrm/cx_pdo_wrong_bus_type INTO lx_pdo_wrong_bus_type.         me->core_object->mo_msg_hdlr->add_exception( io_pdo_error_exception = lx_pdo_wrong_bus_type ).       CATCH /sapsrm/cx_pdo_pd_read_error INTO lx_pdo_pd_read_error.         me->core_object->mo_msg_hdlr->add_exception( io_pdo_error_exception = lx_pdo_pd_read_error ).       CATCH /sapsrm/cx_pdo_lock_failed INTO lx_pdo_lock_failed.         me->core_object->mo_msg_hdlr->add_exception( io_pdo_error_exception = lx_pdo_lock_failed ).       CATCH /sapsrm/cx_pdo_no_authorizatio INTO lx_pdo_no_authorizatio.         me->core_object->mo_msg_hdlr->add_exception( io_pdo_error_exception = lx_pdo_no_authorizatio ).       CATCH /sapsrm/cx_pdo_parameter_error INTO lx_pdo_parameter_error.         me->core_object->mo_msg_hdlr->add_exception( io_pdo_error_exception = lx_pdo_parameter_error ).       CATCH /sapsrm/cx_pdo_status_error INTO lx_pdo_status_error.         me->core_object->mo_msg_hdlr->add_exception( io_pdo_error_exception = lx_pdo_status_error ).       CATCH /sapsrm/cx_pdo_incons_user INTO lx_pdo_incons_user.         me->core_object->mo_msg_hdlr->add_exception( io_pdo_error_exception = lx_pdo_incons_user ).       CATCH /sapsrm/cx_pdo_abort INTO lx_pdo_abort.         me->core_object->mo_msg_hdlr->add_exception( io_pdo_error_exception = lx_pdo_abort ).       CATCH /sapsrm/cx_pdo_error INTO lx_pdo_error.         me->core_object->mo_msg_hdlr->add_exception( io_pdo_error_exception = lx_pdo_error ).     ENDTRY.     CALL METHOD me->core_object->mo_msg_hdlr->set_message_consumer       EXPORTING         io_message_handler = lo_pdo_message_handler.   ENDMETHOD.                    "IOW_ZKSH_EI_CL_SOA_PUR_REQ~CREATE_PDO_SC_INSTANCE

Modifications

/SAPSRM/CL_CH_SOA_DO_PR_ITM->CONSTRUCTOR

METHOD constructor.   DATA : ls_ipt LIKE LINE OF mt_allowed_ipt,          lt_limit_ipt LIKE   mt_allowed_ipt. * Exceptions   DATA:     lx_pdo_icons_user      TYPE REF TO /sapsrm/cx_pdo_incons_user.   CALL METHOD super->constructor     EXPORTING       io_base_mapper = io_base_mapper       io_msg_hdlr    = io_msg_hdlr. * Instantiate DOs   me->init_do( ). * Set node name   me->mv_node_name = 'PR_ITEM'(001).    "#EC * * Instantiate user context   TRY. *{   REPLACE        **********                                        1 *      CALL METHOD /sapsrm/cl_pdo_factory_user=>get_instance_user_context *        EXPORTING *          iv_user         = sy-uname *          iv_application  = iv_application *        RECEIVING *          ro_user_context = mo_user_context.       DATA lv_requester TYPE xubname.       IF abap_true = zksh_ext_req_utils=>mv_ext_req_creation.         lv_requester = zksh_ext_req_utils=>get_requester( ).       ELSE.         lv_requester = sy-uname.       ENDIF.       CALL METHOD /sapsrm/cl_pdo_factory_user=>get_instance_user_context         EXPORTING           iv_user         = lv_requester           iv_application  = iv_application         RECEIVING           ro_user_context = mo_user_context. *}   REPLACE     CATCH /sapsrm/cx_pdo_incons_user INTO lx_pdo_icons_user.       mo_msg_hdlr->add_exception( io_pdo_error_exception = lx_pdo_icons_user ).   ENDTRY. **** Get the Hierarchy Template and Store it   CALL METHOD /sappssrm/cl_ih_cust_prov=>get_template_from_trans_type     EXPORTING       iv_process_type       = 'EXTR'     RECEIVING       rv_hierarchy_template = mv_hier_template. **** FILL THE HIERARCHY TEMPLATE and Allowed IPT's.   CALL METHOD /sappssrm/cl_ih_cust_prov=>get_allowed_ipt_full     EXPORTING       iv_hier_templ  = mv_hier_template       iv_object_type = 'BUS2121'     RECEIVING       rt_ipt         = mt_allowed_ipt.   READ TABLE mt_allowed_ipt INTO ls_ipt WITH KEY ps_ctrl_key = '0001'.   CALL METHOD /sappssrm/cl_ih_cust_prov=>get_allowed_ipt_full     EXPORTING       iv_hier_templ  = mv_hier_template       iv_object_type = 'BUS2121'       iv_ps_ipt      = ls_ipt-ps_ipt     RECEIVING       rt_ipt         = lt_limit_ipt.   APPEND LINES OF lt_limit_ipt TO mt_allowed_ipt.   SORT mt_allowed_ipt BY ps_ctrl_key.   DELETE ADJACENT DUPLICATES FROM mt_allowed_ipt COMPARING ps_ctrl_key. ENDMETHOD.

/SAPSRM/CL_CH_SOA_DO_PR_ITM->ADD_ITEM

METHOD add_item. * Exceptions   DATA:     lx_pdo_no_authorizatio TYPE REF TO /sapsrm/cx_pdo_no_authorizatio,     lx_pdo_abort           TYPE REF TO /sapsrm/cx_pdo_abort,     lx_pdo_incons_user     TYPE REF TO /sapsrm/cx_pdo_incons_user,     lx_pdo_curr_error      TYPE REF TO /sapsrm/cx_pdo_curr_error,     lx_pdo_cat_not_allowed TYPE REF TO /sapsrm/cx_pdo_cat_not_allowed,     lx_pdo_prd_not_unique  TYPE REF TO /sapsrm/cx_pdo_prd_not_unique,     lx_pdo_prd_not_found   TYPE REF TO /sapsrm/cx_pdo_prd_not_found.   TRY. *{   REPLACE        **********                                        1 *      CALL METHOD io_pdo_sc->/sapsrm/if_pdo_bo_sc~add_item *        EXPORTING *          iv_uname           = sy-uname *          is_item            = is_bbp_item *          iv_account_from_pr = iv_account_from_pr *        IMPORTING *          es_return          = es_return *        CHANGING *          co_message_handler = mo_pdo_consumer.       DATA lv_user TYPE xubname.       DATA lo_us_context TYPE REF TO /sapsrm/if_pdo_user_context.       lo_us_context = /sapsrm/cl_pdo_factory_user=>get_buffered_user_context( ).       IF lo_us_context IS BOUND.         lv_user = lo_us_context->/sapsrm/if_pdo_us_context_cons~get_user( ).       ELSEIF abap_true = zksh_ext_req_utils=>mv_ext_req_creation.         lv_user = zksh_ext_req_utils=>get_requester( ).       ELSE.         lv_user = sy-uname.       ENDIF.       CALL METHOD io_pdo_sc->/sapsrm/if_pdo_bo_sc~add_item         EXPORTING           iv_uname           = lv_user           is_item            = is_bbp_item           iv_account_from_pr = iv_account_from_pr         IMPORTING           es_return          = es_return         CHANGING           co_message_handler = mo_pdo_consumer. *}   REPLACE     CATCH /sapsrm/cx_pdo_cat_not_allowed INTO lx_pdo_cat_not_allowed.       mo_msg_hdlr->add_exception( io_pdo_error_exception = lx_pdo_cat_not_allowed ).     CATCH /sapsrm/cx_pdo_no_authorizatio INTO lx_pdo_no_authorizatio .       mo_msg_hdlr->add_exception( io_pdo_error_exception = lx_pdo_no_authorizatio ).     CATCH /sapsrm/cx_pdo_abort INTO lx_pdo_abort.       mo_msg_hdlr->add_exception( io_pdo_error_exception = lx_pdo_abort ).     CATCH /sapsrm/cx_pdo_incons_user INTO lx_pdo_incons_user .       mo_msg_hdlr->add_exception( io_pdo_error_exception = lx_pdo_incons_user ).     CATCH /sapsrm/cx_pdo_curr_error INTO lx_pdo_curr_error.       mo_msg_hdlr->add_exception( io_pdo_error_exception = lx_pdo_curr_error  ).     CATCH /sapsrm/cx_pdo_prd_not_unique INTO lx_pdo_prd_not_unique.       mo_msg_hdlr->add_exception( io_pdo_error_exception = lx_pdo_prd_not_unique  ).     CATCH /sapsrm/cx_pdo_prd_not_found INTO lx_pdo_prd_not_found.       mo_msg_hdlr->add_exception( io_pdo_error_exception = lx_pdo_prd_not_found  ).   ENDTRY. ENDMETHOD.

As a result you should become a custom requester for shopping carts, created from backend purchase requisitions.

P.S.:  English language is not my native language, and any person is not insured from mistakes and typing errors. If you have found an error in the text, please let me know.

P.P.S.: If you have some remarks or hints – please don’t hesitate to leave a comment.

New NetWeaver Information at SAP.com

Very Helpfull

 

 

User Rating: Be the first one !