CRM and CX Blogs by Members
Find insights on SAP customer relationship management and customer experience products in blog posts from community members. Post your own perspective today!
cancel
Showing results for 
Search instead for 
Did you mean: 
Former Member
0 Kudos
514
Introduction

Activities on REX 3.0 can be filtered based on the Days Profile by standard configuration. Days profile is defined and used as a filter for activities as upper and lower range for the start date of an activity from the present day. The upper range is equal to the Present Day + No of Days in Future the activity start date should fall for it to qualify to flow to REX. Similarly the lower range is equal to the Present Day + No of Days in past the activity date should fall.
All the activities within the upper and lower range will flow to Mobile device given the activity should have the Sales Representative (Syncing from the
Device) as Employee Responsible.
We faced the challenge to implement the REX 3.0 filters as we were required filter the visits based on count for each customer, i.e., a fixed number of future as well as past activities of an account should flow to REX.
We will try to give the technical implementation in the document.

Technical Flow Description


  • The parameter ET_ACTIVITY_GUIDS of the internal FM ‘/MAC/RSFM_GET_USR_ACT_LIST’ of BAPI /MAC/RSFM_GET_USR_ACTIVITIES is updated with all the activity GUIDs of the customer.
  • The enhancement spot lr_badi_activity->/mac/rs_badi_act_get_list_bef of  FM of /MAC/RSFM_GET_ACT_LIST is implemented (ZBADI_IMPL_ACT)to update the GUIDs.
  • The implementation class ZBADI_IMPL_ACT is created and made required changes in the method /MAC/RS_BADI_IF_ACT~/MAC/RS_BADI_ACT_GET_LIST_BEF.

ABAP Development


  The below logic is included in the method /MAC/RS_BADI_IF_ACT~ /MAC/RS_BADI_ACT_GET_LIST_BEF: 
  • The selection criteria to fetch the activity GUIDs are as :
    • Transaction type : All DEX REX transaction type( FM : /MAC/RSFM_GET_SRV_CUSTOMIZING, Parameter ET_ACT_DOWN_PARAM)Partner function: ‘00000009’ (Activity Partner).
    • Partner: the entire customer for whom the SR is employee responsible (FM /MAC/RSFM_GET_BP_LIST, Parameter ET_ACCOUNT_ID).
    • Date: Valid from, valid to from REX date profile.
  • Rejected (I1032), cancelled (E0007), finished (I1008), closed (E0009) Activities are deleted from the list.
  • Max no of past and future activities for each customer from the customization table ZACT_CNT is fetched to filter the activities based on start date of the activity.
  • All follow up activities of the final activity list are fetched and appended with the same list.
The standard REX code in the FM is skipped by setting value CV_SKIP = ‘X’.

Custom Table structure ZACT_CNT




























FieldData typeWidthDecDescription
MANDTCLNT30Client
COUNT_PAST_ACTNUMC40No of objects
COUNT_FUTURE_ACTNUMC40No of objects

Sample code:


METHOD /mac/rs_badi_if_act~/mac/rs_badi_act_get_list_bef.
CONSTANTS:lc_eq(2)             TYPE c VALUE 'EQ',
lc_i                 TYPE c VALUE 'I',
lc_object_type       TYPE name_komp        VALUE 'OBJECT_TYPE',
lc_process_type     TYPE name_komp        VALUE 'PROCESS_TYPE',
lc_category          TYPE name_komp        VALUE 'CATEGORY',
lc_partner_fct       TYPE name_komp        VALUE 'PARTNER_FCT',
lc_valid_from        TYPE name_komp        VALUE 'VALID_FROM',
lc_valid_to          TYPE name_komp        VALUE 'VALID_TO',
lc_bu_partner        TYPE name_komp        VALUE 'BU_PARTNER',
lc_bus2000110        TYPE tvarv_val        VALUE 'BUS2000110',
lc_orderadm_h        TYPE crmt_object_name VALUE 'ORDERADM_H',
lc_activity_h        TYPE crmt_object_name VALUE 'ACTIVITY_H',
lc_appointment       TYPE crmt_object_name VALUE 'APPOINTMENT',
lc_partner           TYPE crmt_object_name VALUE 'PARTNER',
lc_status            TYPE crmt_object_name VALUE 'STATUS',
lc_rejected          TYPE crm_j_status     VALUE 'I1032',
lc_closed            TYPE crm_j_status     VALUE 'E0009',
lc_cancelled         TYPE crm_j_status     VALUE 'E0007',
lc_finished          TYPE crm_j_status     VALUE 'I1008',
lc_docflow           TYPE crmt_object_name VALUE 'DOC_FLOW'.

FIELD-SYMBOLS: <activity_tab>  TYPE ANY TABLE.

DATA: lv_start_date            TYPE sy-datum,
lv_end_date              TYPE sy-datum,
lv_guid                  TYPE guid_32,            "#EC NEEDED
lv_days_ahead            TYPE /mac/rsde_no_days,
lv_days_back             TYPE /mac/rsde_no_days,
lv_subrc                 TYPE sysubrc,
lv_index                 TYPE sy-index,
lv_past_no               TYPE zno_of_objects,
lv_future_no             TYPE zno_of_objects.

DATA: lr_1o_search             TYPE REF TO cl_crm_q1o_search.

DATA: i_selection_param        TYPE genilt_selection_parameter_tab,
i_guids                  TYPE crmt_object_guid_tab,
i_doc_flow               TYPE crmt_doc_flow_wrkt,
i_return                 TYPE bapiret2_t,
i_return_val             TYPE bapiret2_t,
i_act_data               TYPE REF TO data,
i_tran_type_down         TYPE /mac/rst_act_down_param,
i_device_transactions    TYPE /mac/rst_device_trans,
i_account_id             TYPE /mac/rst_bp_id,
i_column_value           TYPE TABLE OF zcolumnvalue,
i_act_guids              TYPE crmt_object_guid_tab,
i_requested_objects      TYPE crmt_object_name_tab,
i_orderadm_h             TYPE crmt_orderadm_h_wrkt,
i_activity_h             TYPE crmt_activity_h_wrkt,
i_appointment            TYPE crmt_appointment_wrkt,
i_partner                TYPE crmt_partner_external_wrkt,
i_status                 TYPE crmt_status_wrkt.

DATA: wa_selection_param       TYPE genilt_selection_parameter,
wa_act_tab               TYPE crmst_query_r_act_btil,
wa_tran_type_down        TYPE /mac/rss_act_down_param,
wa_account_id            TYPE /mac/rss_bp_id,
wa_sales_org             TYPE /mac/rss_crm_erp_sales_org,
wa_guid                  TYPE guid_32,
wa_act_guids             TYPE crmt_object_guid,
wa_doc_flow              TYPE crmt_doc_flow_wrk,
wa_requested_objects     TYPE crmt_object_name,
wa_orderadm_h            TYPE crmt_orderadm_h_wrk,
wa_activity_h            TYPE crmt_activity_h_wrk,
wa_appointment           TYPE crmt_appointment_wrk,
wa_partner               TYPE crmt_partner_external_wrk,
wa_status                TYPE crmt_status_wrk,
wa_no_act                TYPE zact_cnt.

DATA: wa_activities    TYPE crmst_query_r_act_btil,
i_activities     TYPE crmt_query_r_act_btil,
i_all_activities TYPE crmt_query_r_act_btil,
lv_result_size              TYPE i,
lv_delete_from_index        TYPE i.

"Read mobile relevant customization - Activity Type, Partner Function, Days Back and Days Ahead
CALL FUNCTION '/MAC/RSFM_GET_SRV_CUSTOMIZING'
EXPORTING
iv_act_flag       = 'X'
IMPORTING
et_act_down_param = i_tran_type_down.
CALL FUNCTION '/MAC/RSFM_GET_CLNT_CUSTOMIZING'
IMPORTING
et_device_transactions = i_device_transactions.


CALL FUNCTION '/MAC/RSFM_USER_ORG_UNIT'
EXPORTING
iv_user_id   = sy-uname
IMPORTING
es_sales_org = wa_sales_org.
LOOP AT i_tran_type_down INTO wa_tran_type_down.
lv_index = sy-tabix.
READ TABLE i_column_value  WITH KEY table_line = wa_tran_type_down-process_type TRANSPORTING NO FIELDS.
IF sy-subrc NE 0.
DELETE i_tran_type_down FROM lv_index.
ENDIF.

ENDLOOP.

LOOP AT i_tran_type_down  INTO wa_tran_type_down.
" Define Transaction Type Filter  from Customization
IF wa_tran_type_down-process_type IS NOT INITIAL.
READ TABLE i_device_transactions WITH KEY process_type = wa_tran_type_down-process_type
  device_trans_key = '0001' TRANSPORTING NO FIELDS.
IF sy-subrc EQ 0.
CLEAR wa_selection_param.
wa_selection_param-attr_name = lc_process_type.
wa_selection_param-sign      = lc_i.
wa_selection_param-option    = lc_eq.
wa_selection_param-low       = wa_tran_type_down-process_type.
APPEND wa_selection_param TO i_selection_param.

" Define category Filter  from Customization
CLEAR wa_selection_param.
wa_selection_param-attr_name = lc_category.
wa_selection_param-sign      = lc_i.
wa_selection_param-option    = lc_eq.
wa_selection_param-low       = wa_tran_type_down-act_category.
APPEND wa_selection_param TO i_selection_param.

ENDIF.
ENDIF.
ENDLOOP.
CLEAR wa_no_act.
SELECT SINGLE count_past_act
count_future_act
FROM zact_cnt
INTO CORRESPONDING FIELDS OF wa_no_act.

" Define Business Object Category Filter -Fetch Activities & Task
CLEAR wa_selection_param.
wa_selection_param-attr_name = lc_object_type.
wa_selection_param-sign      = lc_i.
wa_selection_param-option    = lc_eq.
wa_selection_param-low       = lc_bus2000110.
APPEND wa_selection_param TO i_selection_param.


"Partner Function for activity partner
CLEAR wa_selection_param.
wa_selection_param-attr_name = lc_partner_fct.
wa_selection_param-sign      = lc_i.
wa_selection_param-option    = lc_eq.
wa_selection_param-low       = '00000009'.
APPEND wa_selection_param TO i_selection_param.


" Get accounts for sy-user
CALL FUNCTION '/MAC/RSFM_GET_BP_LIST'
IMPORTING
et_account_id = i_account_id.

IF i_account_id IS NOT INITIAL.

LOOP AT i_account_id INTO wa_account_id WHERE partner_id IS NOT INITIAL.
DELETE i_selection_param WHERE attr_name EQ lc_bu_partner
OR attr_name EQ lc_valid_from
OR attr_name EQ lc_valid_to.

CLEAR wa_selection_param.
wa_selection_param-attr_name = lc_bu_partner.
wa_selection_param-sign      = lc_i.
wa_selection_param-option    = lc_eq.
wa_selection_param-low       = wa_account_id-partner_id.
APPEND wa_selection_param TO i_selection_param.

***********************Past Orders****************************
"Valid From Date
lv_days_back = wa_tran_type_down-days_behind.
IF lv_days_back IS INITIAL.
lv_start_date = sy-datum.
ELSE.
lv_start_date = sy-datum - lv_days_back. "Deduct the days back to get the valid from date
ENDIF.

CLEAR wa_selection_param.
wa_selection_param-attr_name = lc_valid_from.
wa_selection_param-sign      = lc_i.
wa_selection_param-option    = lc_eq.
wa_selection_param-low       = lv_start_date.
APPEND wa_selection_param TO i_selection_param.


"Valid To Date
CLEAR wa_selection_param.
CLEAR lv_end_date.
lv_end_date = sy-datum - 1.
wa_selection_param-attr_name = lc_valid_to.
wa_selection_param-sign      = lc_i.
wa_selection_param-option    = lc_eq.
wa_selection_param-low       = lv_end_date.
APPEND wa_selection_param TO i_selection_param.

"Set the Selection Parameters to Activity Object Search
CREATE OBJECT lr_1o_search.

CALL METHOD lr_1o_search->set_selection_parameters
EXPORTING
iv_obj_il                 = 'BTQACT'
it_selection_parameters   = i_selection_param
IMPORTING
et_return                 = i_return
EXCEPTIONS
partner_fct_error         = 1
object_type_not_found     = 2
multi_value_not_supported = 3
OTHERS                    = 4.

lv_subrc = sy-subrc.
IF lv_subrc <> 0.
RETURN.
ENDIF.

CREATE DATA i_act_data TYPE TABLE OF crmst_query_r_act_btil.

ASSIGN i_act_data->* TO <activity_tab>.

"Run the Activity query
CALL METHOD lr_1o_search->get_result_values
EXPORTING
iv_max_hits = '999999999'
IMPORTING
et_results  = i_activities
et_return   = i_return.

IF sy-subrc <> 0.
APPEND LINES OF i_return TO i_return_val.
RETURN.
ELSEIF i_activities[] IS NOT INITIAL.
DELETE i_activities WHERE status_system EQ lc_rejected OR status EQ lc_closed OR status_system EQ lc_finished or status EQ lc_cancelled.
DESCRIBE TABLE i_activities LINES lv_result_size.
IF lv_result_size > wa_no_act-count_past_act.
lv_delete_from_index = wa_no_act-count_past_act + 1.
SORT i_activities BY from DESCENDING from_time DESCENDING.
DELETE i_activities FROM lv_delete_from_index.
ENDIF.
APPEND LINES OF i_activities TO i_all_activities.
REFRESH i_activities.
ENDIF.
***********************Future Orders****************************
DELETE i_selection_param WHERE attr_name EQ lc_valid_from OR attr_name EQ lc_valid_to.

"Valid From Date
CLEAR wa_selection_param.
lv_start_date = sy-datum.
wa_selection_param-attr_name = lc_valid_from.
wa_selection_param-sign      = lc_i.
wa_selection_param-option    = lc_eq.
wa_selection_param-low       = lv_start_date.
APPEND wa_selection_param TO i_selection_param.

"Valid To Date
lv_days_ahead = wa_tran_type_down-days_ahead.
IF lv_days_ahead IS INITIAL.
lv_end_date = sy-datum.
ELSE.
lv_end_date = sy-datum + lv_days_ahead.  "Add the days ahead to get the valid to date
ENDIF.

CLEAR wa_selection_param.
wa_selection_param-attr_name = lc_valid_to.
wa_selection_param-sign      = lc_i.
wa_selection_param-option    = lc_eq.
wa_selection_param-low       = lv_end_date.
APPEND wa_selection_param TO i_selection_param.


"Set the Selection Parameters to Activity Object Search
CREATE OBJECT lr_1o_search.

CALL METHOD lr_1o_search->set_selection_parameters
EXPORTING
iv_obj_il                 = 'BTQACT'
it_selection_parameters   = i_selection_param
IMPORTING
et_return                 = i_return
EXCEPTIONS
partner_fct_error         = 1
object_type_not_found     = 2
multi_value_not_supported = 3
OTHERS                    = 4.

lv_subrc = sy-subrc.
IF lv_subrc <> 0.
RETURN.
ENDIF.

CREATE DATA i_act_data TYPE TABLE OF crmst_query_r_act_btil.

ASSIGN i_act_data->* TO <activity_tab>.

"Run the Activity query
CALL METHOD lr_1o_search->get_result_values
EXPORTING
iv_max_hits = '999999999'
IMPORTING
et_results  = i_activities
et_return   = i_return.

IF sy-subrc <> 0.
APPEND LINES OF i_return TO i_return_val.
RETURN.
ELSEIF i_activities[] IS NOT INITIAL.
DELETE i_activities WHERE status_system EQ lc_rejected OR status EQ lc_closed OR status_system EQ lc_finished or status EQ lc_cancelled.
DESCRIBE TABLE i_activities LINES lv_result_size.
IF lv_result_size > wa_no_act-count_future_act.
lv_delete_from_index = wa_no_act-count_future_act + 1.
SORT i_activities BY from ASCENDING from_time ASCENDING.
DELETE i_activities FROM lv_delete_from_index.
ENDIF.
APPEND LINES OF i_activities TO i_all_activities.
REFRESH i_activities.
ENDIF.


ENDLOOP.  " Customer Loop


ENDIF.

IF i_all_activities IS NOT INITIAL.
LOOP AT i_all_activities INTO wa_activities.
CLEAR lv_guid.
lv_guid = wa_activities-guid.
INSERT wa_activities-guid INTO TABLE i_guids.
INSERT lv_guid            INTO TABLE ct_activity_guids.
ENDLOOP.
ENDIF.

" Fetching followup's of activities.
MOVE lc_docflow TO wa_requested_objects.
INSERT  wa_requested_objects INTO TABLE i_requested_objects.

CALL FUNCTION 'CRM_ORDER_READ'
EXPORTING
it_header_guid       = i_guids
it_requested_objects = i_requested_objects
IMPORTING
et_doc_flow          = i_doc_flow[]
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.

IF sy-subrc <> 0.
* Implement suitable error handling here
ENDIF.

REFRESH:i_guids.
IF i_doc_flow IS NOT INITIAL.
LOOP AT i_doc_flow INTO wa_doc_flow.
CLEAR:lv_guid.
lv_guid = wa_doc_flow-objkey_b.
INSERT lv_guid INTO TABLE ct_activity_guids.
ENDLOOP.
ENDIF.
SORT ct_activity_guids.
DELETE ADJACENT DUPLICATES FROM ct_activity_guids.
cv_skip = 'X'.

ENDIF.

ENDMETHOD.
********Above documents was co authored by my fellow colleague Karthi Dhayalan. *********
Labels in this area