Skip to Content

TItle.JPG

Applies to:

SAP CRM 7.0, EHP1, EHP2 and EHP3

Summary

This document basically deals with Categorization Schema in SAP CRM. As per my experience I had great difficult in dealing with Categories in SAP CRM as the project requirement was to fetch the current categories  along with their Hierarchical relationships(there are total of 4 levels of categories allowed which starts with Cat1, Cat2, Cat3 and Cat4 upto level 4 also known as Multilevel categorization) SAP CRM system. As per project requirement we had to retrieve the complete hierarchy and then display for the end user on HTMLUI5 App to create SAP CRM transaction. This will be helpful for many technical/functional consultants. Basically we have the functional module which will actually retrieve the complete hierarchy and prepare the internal table containing the complete list of hierarchies along with their parents(higher level categories).

Author(s):

 

Rajwin Singh Sood

Company: Mindtree

Created on: 24th June 2016

Rajwin Sood.jpg

Rajwin Singh Sood is currently working as SAP CRM Technical Manager at Mindtree. He has got experience of about 10 years in SAP ABAP and SAP CRM web UI. He is

also a SAP CRM EHP2 Certified associated consultant. Prior to working with Mindtree he had worked with  Atos,SAP India(SAP

 

Global Delivery), Capgemini , Accenture and Infosys. He worked in SAP CRM Web Ui in areas like BSP

 

enhancements, transaction launchers, BOL Programming, BRFPlus.

Scenario

 

We have Categorization data maintained with respect to SAP CRM service requests which we need to make it presentable to the end user via HTMLUI5 hybrid application. So that user could create service requests in synchronization with SAP CRM. In other words the end user will get all the four level categories in the form of drop down as its appearing in SAP CRM WEBUI.

Function module creation

Create the Z function module where in the importing parameters will be Process type(transaction type) and Service request number(transaction number) both of these will be optional as the categorizations schema can be picked up on the basis of either process type or with the existing transaction id. Please refer to the below screenshots:-

Category_first_screen.JPG

The returning parameter will of table type containing the complete list of hierarchy along with the parents the complete structure is given below:-

second screen.JPG

here the associated type we developed is custom but its exact copy of standard SAP CRM table QPCT which is the text table for categories. You can accordingly fit it as per your requirement.

Function module ABAP code

the function module which we have created is RFC enabled as we need this to be called via hybrid HTMLUI5 application. the complete code is given below:-


*DATA DECLARATION
DATA: lr_core
TYPE REF TO cl_crm_bol_core.

DATA: lr_qs               TYPE REF TO cl_crm_bol_dquery_service,
ls_param           
TYPE        crmt_name_value_pair,
ls_category        
TYPE        crmt_erms_cat_ca_lang,
lr_category        
TYPE REF TO if_crm_erms_catego_category,
ls_search_param    
TYPE       crmt_erms_cat_as_query,
lv_kat             
TYPE       comt_catalog,
lv_code_grupp      
TYPE       qcodegrp,
lv_pattern         
TYPE       string,
ls_crmc_erms_cat_ok
TYPE crmc_erms_cat_ok,
ls_crmc_erms_cat_ln
TYPE crmc_erms_cat_ln,
lt_param           
TYPE        crmt_name_value_pair_tab,
lr_result          
TYPE REF TO if_bol_bo_col,
lt_object_subcode  
TYPE crmt_erms_cat_ob_buf_tab,
lv_last_record     
TYPE i,
lv_code            
TYPE qcode,
ls_object_subcode  
TYPE crmt_erms_cat_ob_buf,
lt_object_subcode1 
TYPE crmt_erms_cat_ob_ln_tab,
ls_object_subcode1 
TYPE crmt_erms_cat_ob_ln,
lv_schema_cat      
TYPE crm_erms_cat_as_id,
lv_subj_prof       
TYPE crmt_subject_profile,
lr_iter            
TYPE REF TO if_bol_entity_col_iterator,
lv_attr_name       
TYPE name_komp,
lt_asp             
TYPE crmt_erms_cat_as_buf_tab,
ls_asp             
LIKE LINE OF lt_asp,
lt_asp_lang        
TYPE crmt_erms_cat_as_lang_tab,
lt_asp_guid        
TYPE crmt_erms_cat_guid_tab,
lt_subject         
TYPE crmt_subject_wrkt,
ls_subject         
LIKE LINE OF lt_subject,
lt_crmd_orderadm   
TYPE crmt_object_guid_tab,
lt_hierarchy       
TYPE crmt_erms_cat_hi_update_ttype,
ls_hierarchy       
TYPE crmt_erms_cat_hi_update,
lv_guid            
TYPE crmt_object_guid,
ls_orderh          
TYPE crmd_orderadm_h,
lv_option          
TYPE bapioption,
lt_qpct            
TYPE STANDARD TABLE OF qpct,
ls_qpct            
LIKE LINE OF lt_qpct,
lv_low             
TYPE string,
ls_categories      
TYPE zqpct_s,
ls_categories_par  
TYPE zqpct_s,
lr_entity          
TYPE REF TO cl_crm_bol_entity.

REFRESH: lt_param,
lt_asp,
lt_asp_lang,
lt_asp_guid,
lt_subject,
lt_qpct,
lt_crmd_orderadm.

CLEAR  : ls_param,
ls_qpct,
ls_orderh,
ls_asp,
ls_categories,
ls_subject.

****we can do the search on the basis of either for existing service request available for modification
IF iv_object_id IS NOT INITIAL.
CALL FUNCTION ‘CONVERSION_EXIT_ALPHA_INPUT’
EXPORTING
input  = iv_object_id
IMPORTING
output = iv_object_id.

SELECT SINGLE guid
INTO ls_orderh-guid
FROM crmd_orderadm_h
WHERE object_id = iv_object_id.
****now fetch the the schema ID from the SR id
APPEND ls_orderh-guid TO lt_crmd_orderadm.
CALL FUNCTION ‘CRM_ORDER_READ’
EXPORTING
it_header_guid       = lt_crmd_orderadm
IMPORTING
et_subject           = lt_subject
EXCEPTIONS
document_not_found   =
1
error_occurred       =
2
document_locked      =
3
no_change_authority  =
4
no_display_authority =
5
no_change_allowed    =
6
OTHERS               = 7.
READ TABLE lt_subject INTO ls_subject INDEX 1.
IF sy-subrc IS INITIAL.
***read the schema ID
lv_schema_cat = ls_subject-asp_id.
lv_kat        = ls_subject-katalogart.
ENDIF.
***we can do the search on the basis of process type in case the service request will created for the first time
ELSEIF iv_process_type IS NOT INITIAL.
***first fetch the subject profile with respect to the process type
SELECT SINGLE subject_profile
INTO lv_subj_prof
FROM crmc_service_h
WHERE process_type = iv_process_type.
****now fetch the catalog type to fetch the schema id
IF sy-subrc IS INITIAL AND lv_subj_prof IS NOT INITIAL.
SELECT SINGLE katalogart codegruppe   FROM crmv_report_subj INTO (lv_kat ,lv_code_grupp) WHERE subject_profile = lv_subj_prof.
****now fetch the schema id
IF lv_kat IS NOT INITIAL AND lv_code_grupp IS NOT INITIAL.
CONCATENATE lv_kat
lv_code_grupp
‘%’
INTO lv_pattern.
SELECT * FROM crmc_erms_cat_ok INTO ls_crmc_erms_cat_ok UP TO 1 ROWS
WHERE obj_extkey LIKE lv_pattern.
ENDSELECT.
IF ls_crmc_erms_cat_ok IS NOT INITIAL.
SELECT * FROM crmc_erms_cat_ln
INTO ls_crmc_erms_cat_ln UP TO 1 ROWS
WHERE obj_guid EQ ls_crmc_erms_cat_ok-obj_guid
AND lnk_type EQ ‘IS_CODE’.
ENDSELECT.
IF ls_crmc_erms_cat_ln IS NOT INITIAL.
SELECT SINGLE asp_id FROM crmv_erms_cat_ca INTO lv_schema_cat WHERE cat_guid EQ ls_crmc_erms_cat_ln-cat_guid.
ENDIF.
ENDIF.
ENDIF.
ENDIF.
ENDIF.
IF lv_kat IS NOT INITIAL.
***fetch the internal table from the category master
SELECT * FROM qpct INTO TABLE lt_qpct WHERE katalogart = lv_kat AND sprache = sy-langu.
ENDIF.
***now we need to initiate search for category schema
IF lv_schema_cat IS NOT INITIAL.
ls_search_param-asp_id = lv_schema_cat.
GET TIME STAMP FIELD ls_search_param-asp_tstamp.
CALL METHOD cl_crm_erms_catego_ma_default=>if_crm_erms_catego_manager~get_aspect_search
EXPORTING
iv_as_query = ls_search_param
IMPORTING
et_asp      = lt_asp
et_asp_lang = lt_asp_lang
et_asp_guid = lt_asp_guid.
***now get the complete hierarchy upto level 4 for the schema with categories assigned to.
READ TABLE lt_asp INTO ls_asp INDEX 1.
IF sy-subrc IS INITIAL.

CALL METHOD cl_crm_erms_cat_hi_db=>get_kids
EXPORTING
iv_tree_guid        = ls_asp-asp_guid
iv_tree_type        =
‘CAT’
iv_level            =
4
IMPORTING
et_hierarchy        = lt_hierarchy
EXCEPTIONS
aspect_not_found    =
1
hierarchy_not_found =
2
OTHERS              = 3.
IF sy-subrc <> 0.
*     Implement suitable error handling here
ENDIF.

ENDIF.
****now read the hierarchy and get the categories details.
LOOP AT lt_hierarchy INTO ls_hierarchy.
REFRESH: lt_object_subcode,
lt_object_subcode1.
CLEAR: lv_code.
CALL METHOD cl_crm_erms_catego_ma_default=>if_crm_erms_catego_manager~get_category
EXPORTING
iv_cat_guid = ls_hierarchy-node_guid
IMPORTING
ev_instance = lr_category.
****now fetch the category details
IF lr_category IS BOUND.
CALL METHOD lr_category->get_details
IMPORTING
ev_cat_lang = ls_category.
****also fetch the subject code with respect tothe category
CALL METHOD lr_category->get_obj_with_inheritance
EXPORTING
iv_lnk_type =
‘IS_CODE’
IMPORTING
et_ob       = lt_object_subcode
et_ob_ln    = lt_object_subcode1.
READ TABLE lt_object_subcode INTO ls_object_subcode INDEX 1.
IF sy-subrc IS INITIAL.
lv_code = ls_object_subcode-ob-obj_extkey+10(4).
ENDIF.
ENDIF.
IF ls_category IS NOT INITIAL.
****fetch the catalog data from catalog master
*        LOOP AT lt_qpct INTO ls_qpct WHERE kurztext CP ls_category-cat_desc.
*          MOVE-CORRESPONDING ls_qpct TO ls_categories.
*        ENDLOOP.
IF lv_code IS NOT INITIAL.
READ TABLE lt_qpct INTO ls_qpct WITH KEY code = lv_code.
IF sy-subrc IS INITIAL.
MOVE-CORRESPONDING ls_qpct TO ls_categories.
ENDIF.
ENDIF.

ls_categories-level = ls_hierarchy-level.
****if its root or level one then mark that as parent of itself
IF ls_hierarchy-level = 1.
ls_categories-parent = ls_categories-code.
ELSE.
****fetch the parent details from the categories.
CALL METHOD cl_crm_erms_catego_ma_default=>if_crm_erms_catego_manager~get_category
EXPORTING
iv_cat_guid = ls_hierarchy-pare_guid
IMPORTING
ev_instance = lr_category.
****now fetch the category details
IF lr_category IS BOUND.
CALL METHOD lr_category->get_details
IMPORTING
ev_cat_lang = ls_category.
****also fetch the subject code with respect to the category
CALL METHOD lr_category->get_obj_with_inheritance
EXPORTING
iv_lnk_type =
‘IS_CODE’
IMPORTING
et_ob       = lt_object_subcode
et_ob_ln    = lt_object_subcode1.
DESCRIBE TABLE lt_object_subcode LINES lv_last_record.
READ TABLE lt_object_subcode INTO ls_object_subcode INDEX lv_last_record.
IF sy-subrc IS INITIAL.
lv_code = ls_object_subcode-ob-obj_extkey+10(4).
ENDIF.
ENDIF.
IF ls_category IS NOT INITIAL.
READ TABLE lt_qpct INTO ls_qpct WITH KEY code = lv_code.
IF sy-subrc IS INITIAL.
MOVE-CORRESPONDING ls_qpct TO ls_categories_par.
ENDIF.
ls_categories-parent = ls_categories_par-code.
ENDIF.
ENDIF.
APPEND ls_categories TO et_categories.
ENDIF.
*      ENDIF.
CLEAR: ls_categories,
ls_categories_par,
ls_category.
ENDLOOP.
ENDIF.

ENDFUNCTION.

 

 

Conclusion

Hope so this document will help people who are quite new to SAP CRM categorization Schema.

To report this post you need to login first.

2 Comments

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

Leave a Reply