在CL_CUAN_MKT_EXEC_EXECUTE_EMAIL类中获取目标组伙伴ID的技术问询
Great question! I’ve tackled exactly this scenario while customizing SAP Hybris Marketing’s email personalization, so here are three reliable approaches to get your 10-digit BP ID from the 16-digit member key stored in lt_pers_content:
1. Direct String Extraction (If Member Key Follows Fixed Format)
In most on-premise Hybris Marketing deployments, the 16-digit MEMBER_KEY in MT_TG_MEMBERS follows a consistent structure: 6-digit source system identifier + 10-digit Business Partner ID.
First, verify this pattern with a few sample records (compare the member key against known BP IDs in your system). If it holds, extract the last 10 characters using ABAP’s SUBSTRING function:
METHOD if_cuan_mkt_exec_execute_action~execute. " Call super class method first to populate content super->execute( exporting iv_action_id = iv_action_id changing ct_pers_content = ct_pers_content ). LOOP AT ct_pers_content ASSIGNING FIELD-SYMBOL(<fs_pers>). " Extract 10-digit BP ID from 16-digit member key DATA(lv_bp_id) = SUBSTRING( val = <fs_pers>-member_key off = 6 ). " Start at position 7 (0-indexed offset 6) " Store BP ID in custom field for email template use <fs_pers>-custom_fields-bp_id = lv_bp_id. ENDLOOP. ENDMETHOD.
2. Use SAP’s ID Mapping Utility Class
If the member key is a UUID or uses a non-fixed format (common in SAP Marketing Cloud), leverage the standard CL_CUAN_ID_MAPPING class to handle cross-system ID mapping reliably:
METHOD if_cuan_mkt_exec_execute_action~execute. super->execute( exporting iv_action_id = iv_action_id changing ct_pers_content = ct_pers_content ). DATA(lo_id_mapper) = CL_CUAN_ID_MAPPING=>GET_INSTANCE( ). LOOP AT ct_pers_content ASSIGNING FIELD-SYMBOL(<fs_pers>). TRY. DATA(ls_ext_id) = lo_id_mapper->GET_EXTERNAL_ID( iv_internal_id = <fs_pers>-member_key iv_context = 'BP' " Adjust context if needed (check your system's config) ). <fs_pers>-custom_fields-bp_id = ls_ext_id-external_id. CATCH cx_cuan_id_mapping_error. " Handle error (e.g., log missing mapping) CONTINUE. ENDTRY. ENDLOOP. ENDMETHOD.
3. Query the Member Master Data Table
For on-premise systems, you can directly query the CUAN_I_MEMBER table, which stores the mapping between internal member keys (16-digit) and external BP IDs (10-digit):
METHOD if_cuan_mkt_exec_execute_action~execute. super->execute( exporting iv_action_id = iv_action_id changing ct_pers_content = ct_pers_content ). LOOP AT ct_pers_content ASSIGNING FIELD-SYMBOL(<fs_pers>). SELECT SINGLE external_id INTO <fs_pers>-custom_fields-bp_id FROM cuan_i_member WHERE internal_id = <fs_pers>-member_key. " Handle cases where no mapping exists IF sy-subrc <> 0. <fs_pers>-custom_fields-bp_id = 'N/A'. " Or log the missing key ENDIF. ENDLOOP. ENDMETHOD.
Key Notes to Remember:
- Always use SAP’s enhancement framework: Don’t modify the standard
CL_CUAN_MKT_EXEC_EXECUTE_EMAILclass directly. Create a subclass or use a BAdI (likeCUAN_MKT_EXEC_ACTION_BADI) to implement your logic. - Validate the mapping: Test with multiple member keys to ensure your chosen method works across all target groups and source systems.
- Cloud vs. On-Prem: For SAP Marketing Cloud, avoid direct database queries—stick to the
CL_CUAN_ID_MAPPINGclass or OData APIs for compliance.
内容的提问来源于stack exchange,提问作者C. Ubkcah

