Created by Jerry Wang, last modified on Jul 19, 2014
根据PPR id搜索出对应的instance:
通过item relation拿到所有的item:
通过PRPItemVPRuleRel拿到该item所有的rule:
进而拿到所有的rule parameter:
使用如下代码打印指定ppr的所有rule信息:
class ZCL_CRM_PPR_TOOL definition public final create public . public section. class-methods CLASS_CONSTRUCTOR . class-methods GET_PRP_BY_ID importing !IV_PRP_ID type CRMT_PRP_ID returning value(RO_INSTANCE) type ref to CL_CRM_BOL_ENTITY . class-methods PRINT_ITEM_RULE importing !IO_PRP_ROOT type ref to CL_CRM_BOL_ENTITY . class-methods INIT_LOG . class-methods INSERT_APP_LOG importing !IV_ID type SYMSGNO !IV_VALUE type ANY optional !IV_VALUE2 type ANY optional !IV_VALUE3 type ANY optional !IV_VALUE4 type ANY optional . class-methods SAVE_APP_LOG . protected section. private section. class-data SO_BOL_CORE type ref to CL_CRM_BOL_CORE . class-data SO_APP_HANDLER type BALLOGHNDL . class-data ST_APP_LOG type CRMT_SOC_APP_LOG . ENDCLASS. CLASS ZCL_CRM_PPR_TOOL IMPLEMENTATION. * <SIGNATURE>---------------------------------------------------------------------------------------+ * | Static Public Method ZCL_CRM_PPR_TOOL=>CLASS_CONSTRUCTOR * +-------------------------------------------------------------------------------------------------+ * +--------------------------------------------------------------------------------------</SIGNATURE> method CLASS_CONSTRUCTOR. so_bol_Core = cl_crm_bol_core=>get_instance( ). so_bol_core->load_component_set( 'PRP' ). init_log( ). endmethod. * <SIGNATURE>---------------------------------------------------------------------------------------+ * | Static Public Method ZCL_CRM_PPR_TOOL=>GET_PRP_BY_ID * +-------------------------------------------------------------------------------------------------+ * | [--->] IV_PRP_ID TYPE CRMT_PRP_ID * | [<-()] RO_INSTANCE TYPE REF TO CL_CRM_BOL_ENTITY * +--------------------------------------------------------------------------------------</SIGNATURE> method GET_PRP_BY_ID. DATA: ls_query_parameters TYPE genilt_query_parameters, lt_selection_parameter TYPE genilt_selection_parameter_tab, ls_selection_parameter TYPE genilt_selection_parameter. ls_query_parameters-MAX_HITS = 1. ls_selection_parameter-OPTION = 'EQ'. ls_selection_parameter-ATTR_NAME = 'PRP_ID'. ls_selection_parameter-SIGN = 'I'. ls_selection_parameter-LOW = iv_prp_id. APPEND ls_selection_parameter TO lt_selection_parameter. DATA(lo_collection) = so_bol_core->dquery( iv_query_name = 'PRPAdvSearch' is_query_parameters = ls_query_parameters it_selection_parameters = lt_selection_parameter ). ASSERT lo_collection->size( ) = 1. ro_instance = lo_collection->get_first( ). endmethod. * <SIGNATURE>---------------------------------------------------------------------------------------+ * | Static Public Method ZCL_CRM_PPR_TOOL=>INIT_LOG * +-------------------------------------------------------------------------------------------------+ * +--------------------------------------------------------------------------------------</SIGNATURE> method INIT_LOG. DATA: ls_log TYPE bal_s_log, ls_mdef TYPE bal_s_mdef. ls_log-object = 'CRM_PRP'. ls_log-subobject = 'UU_DELETE'. CALL FUNCTION 'BAL_LOG_CREATE' EXPORTING i_s_log = ls_log IMPORTING e_log_handle = ls_mdef-log_handle EXCEPTIONS log_header_inconsistent = 1 OTHERS = 2. ASSERT sy-subrc = 0. CALL FUNCTION 'BAL_GLB_MSG_DEFAULTS_SET' EXPORTING i_s_msg_defaults = ls_mdef. so_app_handler = ls_mdef-log_handle. endmethod. * <SIGNATURE>---------------------------------------------------------------------------------------+ * | Static Public Method ZCL_CRM_PPR_TOOL=>INSERT_APP_LOG * +-------------------------------------------------------------------------------------------------+ * | [--->] IV_ID TYPE SYMSGNO * | [--->] IV_VALUE TYPE ANY(optional) * | [--->] IV_VALUE2 TYPE ANY(optional) * | [--->] IV_VALUE3 TYPE ANY(optional) * | [--->] IV_VALUE4 TYPE ANY(optional) * +--------------------------------------------------------------------------------------</SIGNATURE> method INSERT_APP_LOG. DATA: lv_log TYPE bal_s_msg, lv_timestamp TYPE timestampl, lv_value1 TYPE string, lv_value2 TYPE string, lv_value3 TYPE string, lv_value4 TYPE string. lv_log-msgid = 'ZPRP'. lv_log-msgno = iv_id. lv_log-msgty = 'I'. lv_value1 = iv_value. lv_value2 = iv_value2. lv_value3 = iv_value3. lv_value4 = iv_value4. lv_log-msgv1 = lv_value1. lv_log-msgv2 = lv_value2. lv_log-msgv3 = lv_value3. lv_log-msgv4 = lv_value4. GET TIME STAMP FIELD lv_timestamp. lv_log-time_stmp = lv_timestamp. APPEND lv_log TO st_app_log. endmethod. * <SIGNATURE>---------------------------------------------------------------------------------------+ * | Static Public Method ZCL_CRM_PPR_TOOL=>PRINT_ITEM_RULE * +-------------------------------------------------------------------------------------------------+ * | [--->] IO_PRP_ROOT TYPE REF TO CL_CRM_BOL_ENTITY * +--------------------------------------------------------------------------------------</SIGNATURE> METHOD print_item_rule. DATA(item_collection) = io_prp_root->get_related_entities( iv_relation_name = 'PRPItemRel' ). DATA(item_iterator) = item_collection->get_iterator( ). DATA(item) = item_iterator->get_first( ). WHILE item IS NOT INITIAL. DATA(item_id) = item->get_property_as_string( 'PRP_I_ID' ). DATA(item_guid) = item->get_property_as_string( 'GUID' ). insert_app_log( iv_id = '000' iv_value = item_id iv_value2 = item_guid ). DATA(rule_collection) = item->get_related_entities( iv_relation_name = 'PRPItemVPRuleRel' ). IF rule_collection IS INITIAL OR rule_collection->size( ) = 0. item = item_iterator->get_next( ). CONTINUE. ENDIF. DATA(ruleset) = rule_collection->get_first( ). DATA(ruleset_guid) = ruleset->get_property_as_string( 'GUID' ). insert_app_log( iv_id = '002' iv_value = ruleset_guid ). DATA(rule_paras) = ruleset->get_related_entities( iv_relation_name = 'PRPRuleParamRel' ). DATA(rule_iterator) = rule_paras->get_iterator( ). DATA(rule_para) = rule_iterator->get_first( ). WHILE rule_para IS NOT INITIAL. DATA(rule_guid) = rule_para->get_property_as_string( 'GUID' ). DATA(parent_guid) = rule_para->get_property_as_string( 'PARENT_GUID' ). DATA(rule_value) = rule_para->get_property_as_string( 'RULE_LOW' ). DATA(rule_name) = rule_para->get_property_as_string( 'FIELDNAME' ). insert_app_log( iv_id = '001' iv_value = rule_guid iv_value2 = parent_guid iv_value3 = rule_value iv_value4 = rule_name ). rule_para = rule_iterator->get_next( ). ENDWHILE. item = item_iterator->get_next( ). ENDWHILE. save_app_log( ). ENDMETHOD. * <SIGNATURE>---------------------------------------------------------------------------------------+ * | Static Public Method ZCL_CRM_PPR_TOOL=>SAVE_APP_LOG * +-------------------------------------------------------------------------------------------------+ * +--------------------------------------------------------------------------------------</SIGNATURE> method SAVE_APP_LOG. DATA: ls_msg LIKE LINE OF st_app_log. LOOP AT st_app_log INTO ls_msg. CALL FUNCTION 'BAL_LOG_MSG_ADD' EXPORTING i_log_handle = so_app_handler i_s_msg = ls_msg. ENDLOOP. CHECK st_app_log IS NOT INITIAL. CALL FUNCTION 'BAL_DB_SAVE' EXPORTING i_save_all = 'X'. init_log( ). endmethod. ENDCLASS.
PPR mass create report
Created by Jerry Wang, last modified on Apr 14, 2014
可以使用该wiki介绍的report在系统里批量生成PPR数据:
指定需要生成的PPR 个数:
执行report后可以在status栏看到PPR的创建情况:
report执行完毕后会打印出生成的PPR 信息:
可以在UI上搜索出通过report创建的PPR:
SELECTION-SCREEN BEGIN OF BLOCK rad1
WITH FRAME TITLE host.
PARAMETERS: p_pre type char20 OBLIGATORY,
p_exc type abap_bool DEFAULT abap_false,
p_o_pre type char20 OBLIGATORY DEFAULT 'ParentObj',
p_o_txt type char20 OBLIGATORY DEFAULT 'Parent',
p_rank type CRMT_PRP_IL_ADM_H-prp_rank.
SELECTION-SCREEN END OF BLOCK rad1.
SELECTION-SCREEN BEGIN OF BLOCK rad2
WITH FRAME TITLE child.
PARAMETERS: c_pre type char20 OBLIGATORY,
c_exc type abap_bool DEFAULT abap_false,
c_o_pre type char20 OBLIGATORY DEFAULT 'ChildObj',
c_o_txt type char20 OBLIGATORY DEFAULT 'Child',
c_rank type CRMT_PRP_IL_ADM_H-prp_rank.
SELECTION-SCREEN END OF BLOCK rad2.
SELECTION-SCREEN BEGIN OF BLOCK rad3
WITH FRAME TITLE same.
PARAMETERS:
s_itm type char20 OBLIGATORY DEFAULT 'ITEMID',
s_itmt type char30 OBLIGATORY DEFAULT 'ITEM Description',
s_pro type comm_product-product_id OBLIGATORY DEFAULT 'ARNO_TEST004',
s_sa type CRMT_PRP_IL_ORGDATA-sales_org OBLIGATORY DEFAULT 'O 50000732',
s_ch type CRMT_PRP_IL_ORGDATA-DIS_CHANNEL OBLIGATORY DEFAULT '01',
s_ca type CRMT_PRP_IL_PRODUCT-CATEGORY_ID OBLIGATORY DEFAULT 'BASE_FS_BNDL',
s_des type string OBLIGATORY DEFAULT 'PRP Description',
s_cat TYPE COMM_CATEGORY-CATEGORY_ID DEFAULT 'OBJ_0401' OBLIGATORY,
s_fam TYPE COMM_PRODUCT-OBJECT_FAMILY DEFAULT '0401' OBLIGATORY,
s_from type CRMT_PRP_IL_VP-date_valid_from OBLIGATORY,
s_to type CRMT_PRP_IL_VP-date_valid_to OBLIGATORY.
SELECTION-SCREEN END OF BLOCK rad3.
SELECTION-SCREEN BEGIN OF BLOCK rad4
WITH FRAME TITLE run.
PARAMETERS: count type i OBLIGATORY DEFAULT 1,
start type i DEFAULT 0.
SELECTION-SCREEN END OF BLOCK rad4.
data: lo_core type ref to cl_crm_bol_core,
lo_collection type ref to if_bol_entity_col,
lo_root_entity type ref to cl_crm_bol_entity,
lr_PRPItemRel type ref to cl_crm_bol_entity,
lr_PRPItemProdRel type ref to cl_crm_bol_entity,
lr_category type ref to cl_crm_bol_entity,
lr_sale type ref to cl_crm_bol_entity,
lr_object type ref to cl_crm_bol_entity,
lr_account type ref to cl_crm_bol_entity,
lr_valid type ref to cl_crm_bol_entity,
lr_host type ref to cl_crm_bol_entity,
lr_reference type ref to cl_crm_bol_entity,
lr_handler type ref to cl_crm_bol_entity,
lo_transaction type ref to if_bol_transaction_context,
lr_fac type ref to cl_crm_bol_entity_factory,
lt_param type crmt_name_value_pair_tab,
ls_param type crmt_name_value_pair,
lv_success type abap_bool,
lv_input_invalid type abap_bool,
lv_header_failed type abap_bool,
lv_exclude type abap_bool,
lv_index type string,
lv_msg type string,
lv_mode type i,
lv_rank type CRMT_PRP_IL_ADM_H-prp_rank,
lv_p type string,
lv_c type string,
ls_prp type CRMT_PRP_IL_ADM_H,
lv_object_id type comm_product-product_id,
lv_object_descr type string,
lv_changed type abap_bool,
lo_glb_msg_cont type ref to cl_crm_genil_global_mess_cont,
lt_msg type crmt_genil_message_tab,
ls_msg type crmt_genil_message.
CONSTANTS: c_mode_p TYPE i VALUE 1,
c_mode_c TYPE i VALUE 2.
INITIALIZATION.
host = 'Maintain Settings for Host PPR'.
child = 'Maintain Settings for Referenced PPR'.
same = 'These settings are shared with Host and Referenced PPR'.
run = 'Specify Mass Create Option'.
START-OF-SELECTION.
lo_core = cl_crm_bol_core=>get_instance( ).
lo_core->load_component_set( 'PRP' ).
lo_core->load_component_set( 'PROD_ALL' ).
lo_transaction = lo_core->get_transaction( ).
PERFORM check_input.
CHECK lv_input_invalid = abap_false.
PERFORM main.
FORM create_prp_header USING prp_id TYPE char20 CHANGING prp TYPE REF TO cl_crm_bol_entity.
DATA: lv_ppr_id TYPE CRMT_PRP_IL_ADM_H-prp_id.
lr_fac = lo_core->get_entity_factory( 'PRPHeader' ).
clear: lt_param,prp,lv_header_failed, lv_ppr_id,lv_rank, lv_exclude.
ls_param-name = 'PRP_ID'.
IF lv_mode = c_mode_p.
CONCATENATE p_pre lv_index INTO lv_ppr_id.
lv_rank = p_rank.
lv_exclude = p_exc.
ELSE.
CONCATENATE c_pre lv_index INTO lv_ppr_id.
lv_rank = c_rank.
lv_exclude = c_exc.
ENDIF.
ls_param-value = lv_ppr_id.
append ls_param to lt_param.
ls_param-name = 'PRP_TYPE'.
ls_param-value = '0010'.
append ls_param to lt_param.
ls_param-name = 'DESCRIPTION'.
CONCATENATE s_des lv_index INTO ls_param-value.
append ls_param to lt_param.
ls_param-name = 'PRP_EXCLUSION_H'.
ls_param-value = lv_exclude.
append ls_param to lt_param.
IF lv_rank IS NOT INITIAL.
ls_param-name = 'PRP_RANK'.
ls_param-value = lv_rank.
APPEND ls_param TO lt_param.
ENDIF.
prp = lr_fac->create( lt_param ).
if prp is initial.
PERFORM display_msg.
lv_header_failed = abap_true.
ELSE.
lr_sale = prp->create_related_entity( 'PRPOrgDSalesOrgRel' ).
lr_sale->set_property( iv_attr_name = 'SALES_ORG' iv_value = s_sa ).
lr_sale->set_property( iv_attr_name = 'DIS_CHANNEL' iv_value = s_ch ).
ENDIF.
ENDFORM.
FORM create_validity.
lr_valid = lr_prpitemrel->create_related_entity( 'PRPItemVPFromToRel' ).
CHECK lr_valid IS NOT INITIAL.
lr_valid->set_property( iv_attr_name = 'DATE_VALID_FROM' iv_value = s_from ).
lr_valid->set_property( iv_attr_name = 'DATE_VALID_TO' iv_value = s_to ).
lo_core->modify( ).
ENDFORM.
FORM create_prp_item USING prp_header TYPE REF TO cl_crm_bol_entity.
DATA: lv_item_id TYPE CRMT_PRP_IL_ADM_I-prp_i_id,
lv_item_text type CRMT_PRP_IL_ADM_I-DESCRIPTION.
lr_PRPItemRel = prp_header->get_related_entity( 'PRPItemRel' ).
CHECK lr_PRPItemRel IS NOT INITIAL.
CONCATENATE s_itm lv_index INTO lv_item_id.
CONCATENATE s_itmt lv_index INTO lv_item_text.
lr_PRPItemRel->set_property( iv_attr_name = 'PRP_I_ID' iv_value = lv_item_id ).
lr_PRPItemRel->set_property( iv_attr_name = 'PRP_I_TYPE' iv_value = '1' ).
lr_PRPItemRel->set_property( iv_attr_name = 'DESCRIPTION' iv_value = lv_item_text ).
lr_PRPItemRel->set_property( iv_attr_name = 'LANGUAGE' iv_value = 'EN' ).
lo_core->modify( ).
ENDFORM.
FORM create_item_product.
lr_PRPItemProdRel = lr_PRPItemRel->create_related_entity( 'PRPItemProdRel' ).
CHECK lr_PRPItemProdRel IS NOT INITIAL.
lr_PRPItemProdRel->set_property( iv_attr_name = 'PRODUCT_ID' iv_value = s_pro ).
lr_PRPItemProdRel->set_property( iv_attr_name = 'PRODUCT_ID_TYPE' iv_value = 'PRODUCT_ID' ).
lr_PRPItemProdRel->set_property( iv_attr_name = 'PRODUCT_TYPE' iv_value = '01' ).
lr_PRPItemProdRel->set_property( iv_attr_name = 'TYPE' iv_value = '1' ).
lo_core->modify( ).
ENDFORM.
FORM create_category.
lr_category = lr_prpitemrel->create_related_entity( 'PRPItemProdCategoryRel' ).
CHECK lr_category IS NOT INITIAL.
lr_category->set_property( iv_attr_name = 'CATEGORY_ID' iv_value = s_ca ).
lo_core->modify( ).
ENDFORM.
FORM create_prp USING id TYPE char20 CHANGING pref TYPE REF TO cl_crm_bol_entity.
PERFORM create_prp_header USING id CHANGING pref.
CHECK lv_header_failed = abap_false.
PERFORM create_prp_item USING pref.
PERFORM create_item_product.
PERFORM create_item_obj.
PERFORM create_category.
PERFORM create_validity.
PERFORM save_single.
ENDFORM.
FORM main.
DO count TIMES.
lv_index = sy-index + start.
lv_mode = c_mode_p.
PERFORM create_prp USING p_pre CHANGING lr_host.
lv_mode = c_mode_c.
PERFORM create_prp USING c_pre CHANGING lr_reference.
PERFORM append_ref_prp USING lr_host.
PERFORM save_single.
PERFORM output.
lo_core->reset( ).
ENDDO.
ENDFORM.
FORM output.
CLEAR: lv_p, lv_c.
lv_p = p_pre && lv_index.
lv_c = c_pre && lv_index.
CONCATENATE 'Host PPR: ' lv_p ' Reference PPR: ' lv_c INTO lv_msg.
WRITE:/ lv_msg COLOR COL_POSITIVE INTENSIFIED ON.
PERFORM display_progress USING sy-index count lv_msg.
ENDFORM.
FORM create_object.
DATA: lr_fac_object TYPE ref to cl_crm_bol_entity_factory.
lr_fac_object = lo_core->get_entity_factory( 'Product' ).
PERFORM get_obj_id.
clear lt_param.
ls_param-name = 'PRODUCT_ID'.
ls_param-value = lv_object_id.
APPEND ls_param TO lt_param.
ls_param-name = 'PRODUCT_TYPE'.
ls_param-value = '01'.
APPEND ls_param TO lt_param.
ls_param-name = 'ROOT_CAT_ID'.
ls_param-value = s_cat.
APPEND ls_param TO lt_param.
ls_param-name = 'ROOT_HIER_ID'.
ls_param-value = 'R3PRODSTYP'.
APPEND ls_param TO lt_param.
ls_param-name = 'SHORT_TEXT'.
ls_param-value = lv_object_descr.
APPEND ls_param TO lt_param.
ls_param-name = 'OBJECT_FAMILY'.
ls_param-value = s_fam.
APPEND ls_param TO lt_param.
lr_fac_object->create( lt_param ).
ENDFORM.
FORM get_obj_id.
CLEAR: lv_object_id, lv_object_descr.
IF lv_mode = c_mode_p.
CONCATENATE p_o_pre lv_index INTO lv_object_id.
CONCATENATE p_o_txt lv_index INTO lv_object_descr.
ELSE.
CONCATENATE c_o_pre lv_index INTO lv_object_id.
CONCATENATE p_o_txt lv_index INTO lv_object_descr.
ENDIF.
ENDFORM.
FORM create_item_obj.
lr_object = lr_prpitemrel->create_related_entity( 'PRPItemProdIndObjectRel' ).
CHECK lr_object IS NOT INITIAL.
PERFORM create_object.
lr_object->set_property( iv_attr_name = 'TYPE' iv_value = '30' ).
lr_object->set_property( iv_attr_name = 'PRODUCT_ID' iv_value = lv_object_id ).
lr_object->set_property( iv_attr_name = 'PRODUCT_ID_TYPE' iv_value = 'PRODUCT_ID' ).
lr_object->set_property( iv_attr_name = 'PRODUCT_TYPE' iv_value = '01' ).
lo_core->modify( ).
ENDFORM.
FORM append_ref_prp USING parent TYPE REF TO cl_crm_bol_entity.
lr_handler = parent->get_related_entity( 'PRPItemRel' ).
lr_handler = lr_handler->create_related_entity( 'PRPItemVPPRPRel' ).
CHECK lr_handler IS NOT INITIAL.
CONCATENATE c_pre lv_index INTO lv_c.
lr_handler->set_property( iv_attr_name = 'REF_PRP_ID' iv_value = lv_c ).
lo_core->modify( ).
ENDFORM.
FORM save_single.
lv_changed = lo_transaction->check_save_needed( ).
check lv_changed eq abap_true.
lv_success = lo_transaction->save( ).
if lv_success = abap_true.
lo_transaction->commit( ).
else.
lo_transaction->rollback( ).
PERFORM display_msg.
ENDIF.
ENDFORM.
FORM display_msg.
lo_glb_msg_cont = lo_core->get_global_message_cont( ).
call method lo_glb_msg_cont->if_genil_message_container~get_messages
exporting
iv_message_type = if_genil_message_container=>mt_all
importing
et_messages = lt_msg.
loop at lt_msg into ls_msg.
write:/ ls_msg-message.
endloop.
ENDFORM.
FORM check_input.
IF count <= 0 OR count > 100000.
WRITE:/ 'Specify number of PPR you want to mass create: between 1 and 100000' COLOR COL_NEGATIVE INTENSIFIED ON.
lv_input_invalid = abap_true.
ENDIF.
IF start < 0 OR start > 100000.
WRITE:/ 'Specify start index: between 1 and 100000' COLOR COL_NEGATIVE INTENSIFIED ON.
lv_input_invalid = abap_true.
ENDIF.
ENDFORM.
FORM display_progress USING current type i total type i text type string.
DATA: percent TYPE i.
percent = current * 100 / total.
CALL FUNCTION 'SAPGUI_PROGRESS_INDICATOR'
EXPORTING
PERCENTAGE = percent
text = text.
ENDFORM.