CRM and CX Blogs by SAP
Stay up-to-date on the latest developments and product news about intelligent customer experience and CRM technologies through blog posts from SAP experts.
cancel
Showing results for 
Search instead for 
Did you mean: 
former_member241146
Active Participant






















Overview for Implementing Custom Logic in SAP Marketing Cloud


 

Welcome to the blog posts of the SAP CX Services Marketing Practice.
We are happy to share with you our experience around Marketing Business, Technology and Analytics.
You want to see more blogs from us? Click here.

In this article, you will learn about the available options to enhance and extend the SAP Marketing Cloud solution by implementing your own custom logic.

Table of Contents








What is Custom Logic?


Custom logic is logic that you create to enhance SAP standard delivery implementations. To accommodate customers requirements, SAP provides predefined points to extend the solutions. This enhancement implementation is also known as Business Add-Ins (BAdI).

In SAP Marketing Cloud, it is possible to extend the logic of the following business contexts:




























































Business Contexts Context Description
MKT_DIGITAL_ACCOUNT Marketing: Digital Account
MKT_EXPORT_DEFINITION Marketing: Export Definition
MKT_INITIATIVE Marketing: Campaign
MKT_INI_EXT_SUCCESS_DATA Marketing: Campaign Performance Actual Measure
MKT_INI_PERFORMANCE_TARGET Marketing: Campaign Performance Target Measure
MKT_INTERACTION Marketing: Interaction
MKT_INTERACTION_CONTACT Marketing: Contact and Corporate Account
MKT_LANDING_PAGE Marketing: Landing Page
MKT_MARKETING_AREA Marketing: Marketing Area
MKT_PERMISSION Marketing: Permission
MKT_PLAN Marketing: Marketing Plan
MKT_PROGRAM Marketing: Program
MKT_RECO Marketing: Recommendations





You can find the overview of business contexts and their scope items with the Extensibility Cockpit app in SAP Marketing Cloud.



In general, this is the process to implement custom logic:



SAP Documentation: Creating Custom Logic:




  • Create your own enhancement implementations by using ABAP for Key Users.

  • Publish enhancement implementations to your test system.

  • Edit enhancement implementations or delete enhancement implementations that have already been published.

  • Export custom logic implementation as software collections to the production system.


Creating custom logic is one of the options available to extend and enhance the SAP Marketing Cloud standard delivery. You can find more information in our Extensibility Guide


 







An introduction in ABAP for Key Users


ABAP for Key Users is a subset of the ABAP programming language. You can use this ABAP variant to implement business logic extensions using a web-based editor provided in SAP Marketing Cloud.

You can find more information on how to develop using ABAP for Key Users in our SAP Documentation: Introduction to ABAP for Key Users. Note: restricted ABAP syntax exists. For example, any database operation except selects from released views, tweaking new tasks, dynamic programming, obsolete ABAP statements, and code generation. Additionally, only whitelisted (released) APIs can be used.

SAP Marketing Cloud provides the following classes that can be used in custom logic:
































































ABAP Class Name Description
CL_CUAN_CE_IC_QUERY Search for Interaction Contact
CL_CUAN_CE_IA_HELPER Interaction Helper
CL_CUAN_CE_IC_HELPER Interaction Contact Helper
CL_CUAN_CE_MKT_ATTR_CAT_HELPER Helper Class for Marketing Attributes Categories
CL_CUAN_CE_MKT_PERM_HELPER Helper Class for Marketing Permission
CL_CUAN_COMMON_HELPER Common Helper
CL_CUAN_INTERACTION_HELPER Helper Methods for Interactions
CL_CUAN_INTEREST_HELPER Interest Helper
CL_CUAN_LOC_HELPER Helper Class for Marketing Location
CL_CUAN_MKT_EXEC_HELPER Marketing Execution: Helper Class
CL_CUAN_PRODUCT_HELPER Helper Class for Product
CL_ABAP_CONTEXT_INFO Helper Class for System Info
CL_CUAN_INTERACT_CNTCT_HELPER Helper Class for Get Additional Contact Fields
CL_CUAN_CAMPAIGN_HELPER_API Helper Class for Campaign Data


 

Example 1: Use case implementation using CL_CUAN_CE_IC_QUERY class to search for an existing interaction contact.

The ABAP class returns the matching interaction contact.
DATA:
lt_contact TYPE cuan_t_qr_ce_ic_root_ext,
ls_query TYPE cuan_s_q_ce_ic_root_ext,
lt_query TYPE cuan_t_q_ce_ic_root_ext.
* Create Query internal table to search for existing contacts
CLEAR ls_query.
ls_query-name_last = 'Doe'. "last name
ls_query-name_first = 'John'. "first name
* ls_query-name_text = . "full name
* ls_query-country = . "country code
* ls_query-country_ft = . "country free text
* ls_query-region = . "region code
* ls_query-region_ft = . "region free text
* ls_query-postcode1 = . "postal code
* ls_query-city1 = . "city
* ls_query-street = . "street
* ls_query-house_num1 = . "house number
* ls_query-title = . "title code
* ls_query-title_ft = . "title free text
* ls_query-search_text = "search text
APPEND ls_query TO lt_query.
* search for interaction contacts
cl_cuan_ce_ic_query=>search(
EXPORTING
query = lt_query " Interaction Contact Query
IMPORTING
contact = lt_contact " Interaction Contact Root Result
).

 

Example 2: How to use SY-DATUM?

For ABAP developers, it is common to use SYST structure (sy-datum, sy-uzeit, sy-uname and others). As you can only use whitelisted APIs, you cannot use SYST in ABAP for Key user. Instead, you call the appropriate method of the class CL_ABAP_CONTEXT_INFO.


DATA(v_date) = cl_abap_context_info=>get_system_date( ).
DATA(v_time) = cl_abap_context_info=>get_system_time( ).
DATA v_text TYPE string.
CONCATENATE v_date v_time INTO v_text SEPARATED BY SPACE.



 

Example 3: You can select data from standard Core Data Services (CDS) views like I_Mkt_Initiative (campaign data), I_Mkt_Interaction (interactions), I_Mkt_Contact (contacts) and others.


* SELECT MARKETING AREA FROM CAMPAIGN
IF marketing_area_id IS INITIAL.
SELECT SINGLE MarketingArea
INTO @data(v_id_marketing_area)
FROM I_Mkt_Initiative
WHERE CampaignID = @CAMPAIGN_ID.
ENDIF.




 




Example 4: Or you can also select data from a specific Custom Business Object (CBO) in custom logic. The CBO generates a CDS View. Once generated, you just need to SELECT FROM "CDS View" in your custom logic.
* Select additional MARKETING AREAs from CBO: YY1_ADD_MKT_AREA
SELECT id_mkt_area_allowed FROM yy1_add_mkt_area
APPENDING TABLE @target_mkt_area_ids
WHERE id_mkt_area_origin = @sorce_mkt_area_id.

 

Example 5: Use Helper Class to read standard data. For example, to read campaign attributes, use CL_CUAN_campaign_HELPER_API.


DATA: v_campaign_id         TYPE cuan_initiative_id,
o_oc_header_attribute TYPE REF TO cuan_s_oc_header_attribute,
s_campaign_root TYPE cuan_s_campaign_root_api.
READ TABLE header_attributes REFERENCE INTO o_oc_header_attribute
WITH KEY param_name = if_cuan_mkt_orch_constants=>sc_open_channel_header_attr-campaign. " CAMPAIGN
IF sy-subrc IS INITIAL. " Campaign identifier has been passed in parameter HEADER_ATTRIBUTES
v_campaign_id = o_oc_header_attribute->param_value.
s_campaign_root = cl_cuan_campaign_helper_api=>campaign_root_read( EXPORTING iv_id = v_campaign_id ).
IF s_campaign_root-priority EQ cl_cuan_campaign_helper_api=>co_priority-high.
* ....
ELSE.
* ....
ENDIF
ENDIF.


 


Best Practices for ABAP Coding






























Area Description
Naming Conventions The purpose of using a standardized name convention is to considerably increase the maintainability of customer-specific adaptations and expansions. Define general rules and familiarize developers to them.
Code Commenting Make sure that the code has explicit comments about the functionality of the implemented custom logic.
Error Handling When executing particular ABAP statements, the SAP kernel sets the value of the global variable SY-SUBRC. Generally, a SY-SUBRC value of zero indicates a successful execution of a statement. SY-SUBRC system field is still available with ABAP for Key Users. Always check SY-SUBRC in your ABAP custom code after READ internal table, SELECT data or CALL to internal functions. Also, always check for Exceptions when you call ABAP-class methods.
Selects/Joins

SELECT clauses in LOOP should be avoided. As an alternative, use VIEWS, JOINS or the addition clause FOR ALL ENTRIES in SELECTS.

FOR ALL ENTRIES tips:

  • Make sure the internal table referenced with FOR ALL ENTRIES is not empty, otherwise all items will be selected from the datasource table.

  • Make sure there the internal table does not contain duplicate entries, otherwise duplicated records will be loaded from the datasource table. Use DELETE ADJACENT DUPLICATES clause to clean internal tables.


Field Symbols Field symbols refers to existing data. Work in a LOOP or iterations for each row from internal tables using Field Symbols. This is always faster than copying or moving the data to auxiliary work structure areas, especially if the table content needs to be changed. You should use field symbols whenever possible.







How to Implement Custom Logic


In SAP Marketing Cloud, you access the Custom Fields and Logic app to implement custom logic.





A description of the custom logic procedure can be found in the Creating Custom Logic documentation.



Create an enhancement implementation by choosing a business context and BAdI. After, add an implementation description and ID and the Web-Development Editor will be enabled for ABAP custom logic implementation.



In the Editor, there are code examples to help you implement your custom code as well as detailed BAdI documentation.


Custom Logic Tracing


SAP Marketing Cloud enables you to trace BAdI implementations after publishing by the Custom Logic Tracing app. You can trace the values of the input, the actions, as well as check the execution processing time of your custom logic. You can also see which exceptions are raised and where they occur.



It is a powerful troubleshooting app to find implementation issues. It can also help you to identify performance tuning points in your custom code.









Which Enhancements are Available to Implement in SAP Marketing Cloud?


SAP Marketing Cloud offers several points to enhance the standard solution. You can find a list of available BAdIs in SAP Help.

Digital Account


Customize the access token request for digital account services.














Business Context BAdI Definition Name BAdI Description
MKT_DIGITAL_ACCOUNT CUAN_DA_GET_ACCESS_TOKEN Getting of Access Token


Export Definition


For campaigns using Export Files Definition, you can implement custom logic to modify files structure, add columns, hide columns by checking user authorization, filter the list of File Export Definitions in campaigns, and to modify the header, attributes or target group members during file exportation.












































Business Context BAdI Definition Name BAdI Description
MKT_EXPORT_DEFINITION HPA_EXP_DEF_ADD_ACT_PARAMETER Add Action Parameter
MKT_EXPORT_DEFINITION HPA, EXP_ADD_ATTR_FOR_EXP_FILE Add Attributes to Export Definition Content
MKT_EXPORT_DEFINITION HPA_EXP_DEF_CHECK_AUTH4COLUMN Check User Authorization for Preview Columns of Export Content
MKT_EXPORT_DEFINITION HPA_EXP_GET_EXPORT_DEFINITIONS Configure Retrieval of Dropdown List for Export Definitions
MKT_EXPORT_DEFINITION HPA_EXP_DEF_GET_KEYS Get Keys to Determine the CSV and Preview Content
MKT_EXPORT_DEFINITION HPA_EXP_DEF_SET_OBJECT_HEADER Set Object Header and Content Attribute Columns in CSV File
MKT_EXPORT_DEFINITION HPA_EXP_DEF_COLUMN_NO_INI_VAL Set Flag for Specific Columns: No Initial Attribute Value from Segmentation


Campaign


You can adapt and enhance campaign execution procedure based on your requirements, update attributes, change hyperlinks or filter campaigns during replication to SAP Cloud for Customer.












































Business Context BAdI Definition Name BAdI Description
MKT_INITIATIVE CUAN_CAMPAIGN_CHECK Check Attributes of Campaign Header
MKT_INITIATIVE CUAN_CAMPAIGN_UPDATE Update Attributes of Campaign Header
MKT_INITIATIVE CUAN_CMSG_ADAPT_HYPERLINKS Adjust Hyperlink Parameters While Sending Emails
MKT_INITIATIVE CUAN_CMSG_ADD_BLOCK_ATTRIBUTES Add Block Attributes
MKT_INITIATIVE CUAN_CPG_EXEC_DYN_CNTNT_MTH Dynamic Content Retrieval for Campaign Execution
MKT_INITIATIVE CUAN_LM_CAMPAIGN_REPLICATION Filter for Campaigns to Be Replicated to SAP Cloud for Customer
MKT_INITIATIVE CUAN_LM_TARGET_SYS_TYPE Lead Management: Determine Target System Type


Open Channel


Enhancements to implement open channel for Custom Action during Campaign Executions. Find more information in Open Channel documentation.


































Business Context BAdI Definition Name BAdI Description
MKT_INITIATIVE CUAN_CPG_OPN_CHNL_DEFINITION (1) Open Channel: Define Implementations: Mandatory
MKT_INITIATIVE CUAN_CPG_OPN_CHNL_IA_TEMPL (2) Open Channel: Define Parameters for Implementation: Optional
MKT_INITIATIVE CUAN_CPG_OPN_CHNL_PARAMETER (3) Open Channel: Define Global Settings for Execution: Optional
MKT_INITIATIVE CUAN_CPG_OPN_CHNL_PRE_PROC (4) Open Channel: Enhance Payload for Data Transfer: Optional
MKT_INITIATIVE CUAN_CPG_OPN_CHNL_PRE_TRANSF (5) Open Channel: Define Template for Outbound Interaction: optional


Campaign Performance


Enhance the data checks during import of campaigns performance data.



















Business Context BAdI Definition Name BAdI Description
MKT_INI_EXT_SUCCESS_DATA CUAN_CMPGN_PERF_IMPORT_SUCCESS Adapt Campaign Success Before Import
MKT_INI_PERFORMANCE_TARGET CUAN_CMPGN_PERF_IMPORT_TARGET Adapt Campaign Targets Before Import


Interaction


You can modify interaction data before import or adapt interaction data displayed in the interaction history list (Contacts and Profiles app in SAP Marketing Cloud, Interaction tab).



















Business Context BAdI Definition Name BAdI Description
MKT_INTERACTION CUAN_IA_REVISE_FOR_DISPLAY Revise Interaction Data Before Import
MKT_INTERACTION CUAN_IA_REVISE_FOR_IMPORT Revise Interaction Data for Display on the UI





BAdIs for MKT_INTERACTION are called for each interaction event. Always try to restrict additional database SELECTs (filtering by Interaction Types per example) during your custom logic implementation. Performance is critical.



Contact and Corporate Account


You can modify interaction contacts or golden record when importing a contact, modify a contact when importing an interaction, or modify finding-matching logic enhancing the contact merge process.







































Business Context BAdI Definition Name BAdI Description
MKT_INTERACTION_CONTACT CUAN_FIND_INTERACTION_CONTACT Find Interaction Contact
MKT_INTERACTION_CONTACT CUAN_IMPORT_IA_4_IC Review Imported Interaction Updating an Interaction Contact
MKT_INTERACTION_CONTACT CUAN_IMPORT_IA_IC_ADJUST Adjust System Behavior on Interaction Contact Import
MKT_INTERACTION_CONTACT CUAN_IMPORT_IC Review Imported Interaction Contact Data
MKT_INTERACTION_CONTACT CUAN_MERGE_IC Merge Interaction Contact
MKT_INTERACTION_CONTACT CUAN_UPDATE_IC_ROOT Update Interaction Contact (Best Record)


Landing Page


You can change the data on the landing page files before publishing them during automated landing page publication, create custom logic to determine which contacts should be updated during the landing page input data and also prefill data in the landing page with data that SAP Marketing has already collected about your contacts.





























Business Context BAdI Definition Name BAdI Description
MKT_LANDING_PAGE CUAN_CP_DEPLOY_ADJUST_FILES Change File Contents Before Landing Page Publication
MKT_LANDING_PAGE CUAN_CP_DETERMINE_CONTACT Find Contact Using Landing Page Input
MKT_LANDING_PAGE CUAN_CP_READ_CONTACT_PREFILL Read Contact Data for Landing Page Personalization
MKT_LANDING_PAGE CUAN_CP_SEND_CONFIRMATION Control Sending of Confirmation E-mail for Double Opt-In Process


Marketing Area


You can allow additional marketing areas for target groups or switch to a different marketing area during the Campaign Execution.



















Business Context BAdI Definition Name BAdI Description
MKT_MARKETING_AREA CUAN_MKT_EXEC_MARKETING_AREA Marketing Area Separation for Campaign Execution
MKT_MARKETING_AREA HPA_ALLOWED_MKT_AREAS Allowed Marketing Areas


You can find more information regarding Marketing Area custom logic in the Help SAP documentation.

Marketing Permission


Implement your own logic to handle marketing permissions, newsletter subscriptions and suppression rules.





























Business Context BAdI Definition Name BAdI Description
MKT_PERMISSION CUAN_MKT_NEWSLETTER_PERMISSION Permission and Subscription Check
MKT_PERMISSION CUAN_MKT_PERMISSION_PASS Permission and Subscription Copy
MKT_PERMISSION CUAN_MKT_PERMISSION_UPDATE Permission and Subscription Update
MKT_PERMISSION CUAN_MKT_SUPPRESSION_RULES Suppression Rules Check


Marketing Plan


Enhancements to check and update attributes for marketing plan before saving it.



















Business Context BAdI Definition Name BAdI Description
MKT_PLAN CUAN_MARKETING_PLAN_CHECK Check Attributes of Marketing Plan Header
MKT_PLAN CUAN_MARKETING_PLAN_UPDATE Update Attributes of Marketing Plan Header


Marketing Program


Enhancements to check and update attributes for marketing program before saving it.



















Business Context BAdI Definition Name BAdI Description
MKT_PROGRAM CUAN_PROGRAM_CHECK Check Attributes of Program Header
MKT_PROGRAM CUAN_PROGRAM_UPDATE Update Attributes of Program Header


Recommendations


Implement custom logic to modify recommendations parameters before the Recommendation Scenario is calculated, and also to modify the impressions of (mass) recommendations.
























Business Context BAdI Definition Name BAdI Description
MKT_RECO RECO_AGGREGATE_IMPRESSIONS Aggregate or Transform Runtime Recommendation Impressions
MKT_RECO RECO_AGGREGATE_MASS_IMPRESSNS Aggregate or Transform Mass Runtime Recommendation Impressions
MKT_RECO RECO_ENHANCE_RUNTIME_PARAMETER Enhance Recommendation Runtime Parameters








Implementation Examples


In this section, you will find some BAdI implementation examples to handle different customer requirements.

Use-Case example 1: Customer requirement: to add new validation status to a specific ID_ORIGIN for a contact by using the BAdI CUAN_UPDATE_IC_ROOT.
******************************************************
* Sample logic setting the IC ROOT validation status *
******************************************************
* c_anonymous = ' '
* c_self_identified = '10'
* c_qualified = '20'
* c_business_partner = '30'
LOOP AT lt_ia_facet REFERENCE INTO lr_ia_facet.
CASE lr_ia_facet->id_origin.
WHEN cl_cuan_ce_ic_helper=>gc_crm_bupa OR "SAP CRM Business Partner
cl_cuan_ce_ic_helper=>gc_erp_bupa OR "SAP ERP Business Partner
cl_cuan_ce_ic_helper=>gc_erp_contact OR "SAP ERP Contact
cl_cuan_ce_ic_helper=>gc_erp_customer OR "SAP ERP Customer
if_cuan_ce_c=>co_origin_sap_erp_company OR "SAP ERP Company
if_cuan_ce_c=>co_origin_sap_c4c_indiv_cust. "SAP C4C Individual Customer
es_ic_new-validation_status = c_business_partner.
EXIT.
ENDLOOP.

 

Use-Case example 2: Customer requirement: to define an Interaction, use the same Marketing Area from a Contact assigned to the interaction during Import Interaction by using the BAdI CUAN_IA_REVISE_FOR_IMPORT.
DATA: lv_marketing_area type c length 40.

IF interaction_data-mkt_area_id is initial
OR interaction_data-mkt_area_id EQ 'GLOBAL'.
SELECT SINGLE InteractionContactMktgArea FROM I_MKT_IntactnCntctMktgArea
WHERE InteractionContactOrigin EQ @interaction_data-id_origin
AND InteractionContactId EQ @interaction_data-id
AND InteractionContactUUID EQ @interaction_data-contact_key
INTO @lv_marketing_area.
* Set Marketing Area into Interaction
interaction_data-mkt_area_id = lv_marketing_area.
ENDIF.


 


Use-Case example 3: Customer requirement: to add custom attributes to the Open Channel Campaign when sending data to the external system by using the BAdI CUAN_CPG_OPN_CHNL_PARAMETER.

 


  DATA: v_campaign_id        TYPE cuan_initiative_id,
s_header_Attributes LIKE LINE OF header_attibutes,
s_campaign_root TYPE cuan_s_campaign_root_api.
package_size = 100. " change the number of target group members processed in one package and transferred in the odata payload
CHECK_PERMISSION = abap_false.
read table HEADER_ATTRIBUTES assigning FIELD-SYMBOL(<fs_head>) WITH KEY param_name = 'CAMPAIGN'.
if sy-subrc eq 0.
v_campaign_id = <fs_head>-param_value.
endif.
s_campaign_root = cl_cuan_campaign_helper_api=>campaign_root_read( EXPORTING iv_id = v_campaign_id ).
clear s_header_attributes.
s_header_attributes-param_name = 'Z_NEW_FIELD'.
s_header_attributes-param_value = s_campaign_root_api-yy1_new_field.
append s_header_attributes to HEADER_ATTRIBUTES.
endif.



 







Conclusion


This article introduced you to an overview for implementing custom logic in SAP Marketing Cloud. Now, you know what to consider to extend the standard solution, the steps to start your implementation code, and which options are available for enhancement.

To find out more about extensibility, go to: Extensibility Overview for SAP Marketing Cloud





To access all our community or out of the box product documentation, please check out our List of Online Resources.



 

You want to see more articles from SAP Services? Click on the banner below.

Your SAP CX Services – Marketing Practice team.




 















5 Comments