Skip to Content
Technical Articles
Author's profile photo Olegs Tovstenko

Building custom SAP HANA View for SAP Marketing Cloud to Segment customers based on Agreement Type count

In this blog post I will explain how to extend SAP Marketing Cloud Segmentation application in order to segment customers based on their Agreement Type count, creating a Custom SAP HANA 2.0 Calculation View in SAP Web IDE.

Typically Utility companies have several Agreement Types for their services, such as ‘Residential Contract Account’, ‘Commercial Contract Account’, where single Consumer can have multiple agreements of each type:

Agreement%20Type%20attribute

Agreement Type attribute

Starting from 2008 version of SAP Marketing Cloud, you can use blocks for Agreement Bundles in email templates and emails to send customers information about their Agreement Bundles and Agreement Members. This functionality is specially very useful to the Utility Industries since it helps to add information of Contract Accounts and Contracts underneath them in these agreement blocks. Currently the solution supports 1:n relationship between Agreement Bundle and Agreement Bundle Member and it requires each Agreement Bundle to have a distinct Agreement type.

The exact amount of Agreements for each consumer per Agreement Type is not transparent in Segmentation application (sample: only one Contract Account of Residential Type and one Contract Account of Commercial Type). This can be easily achieved by developing Custom Calculation view and assigning it to Segmentation.

 

Part I – Prerequisites

  1. Set-up SAP Web IDE development environment for SAP HANA Calculation view in Cloud Foundry
  2. Export whitelisted content from your SAP Marketing Cloud tenant into SAP Web IDE.

 

Part II – Create new Custom Calculation View

In the ‘MKT_metadata’ tree find ‘src’ folder and below create a new folder ‘Custom View’:

New%20Folder

New Folder

Right-click on newly created ‘Custom View’ folder and choose New > Calculation View:

New%20Calculation%20View

New Calculation View

Fill in View name, label and data category as CUBE:

Calculation%20View%20Name%20and%20Category

Calculation View Name and Category

Newly created Custom Calculation view will open in graphical designer automatically:

New%20View

New Custom Calculation View

On the right-hand side panel of the View graphical editor I have multiple options, like create a projection, add join, rank, union and others. Select the Projection option from the left panel of the View editor section and click on the graphical designer work area of the View, it will create a new ‘Projection_1’ afterwards select ‘+’ to add a data source

Projection_1

Projection_1

As a data source I will use agreement root table from SAP Marketing Cloud, which has all the necessary data like: Interaction contact key, agreement type, external agreement id. Once you press on ‘+’ you will see a pop-up, in a search field type ‘CUAND_AGR_ROOT’, select the table and press ‘Finish’:

CUAND_AGR_ROOT%20source%20table

CUAND_AGR_ROOT source table

(NOTE: if you don’t see the table in the list, check that you manage to import marketing medata zip file successfully – prerequisite step 2)

After selecting corresponding data source ‘Projection_1’ will look like this:

Projection%20with%20data%20source

Projection with data source

Now I will make required data fields from source table visible as output columns of my projection. Select the projection.On the right-hand side, additional property settings will appear, if it’s still not visible for you by default, try to extend the property work area by pulling marked tab to the left and then stay at the first tab ‘Mapping’.  Select the fields from data source (left side) and drag-and-drop them to ‘Output Columns’ on the left side:

Projection%20Mapping

Projection Mapping

Fields to be pulled for output: SAPCLIENT; MKT_AGREEMENTEXTERNALID; MKT_AGREEMENTISBUNDLE; CONTACTORIGIN; INTERACTIONCONTACTUUID; MKT_AGREEMENTTYPE. (order of the fields is not fixed)

I will apply filters at the hdbtable level, such as client and contract account by writing SQL expression at the last tab of projection ‘Filter Expression’:

("SAPCLIENT" ='$$client$$') AND ("MKT_AGREEMENTISBUNDLE" ='X')

Projection Filter

Next, I will link my ‘Projetion_1’ to above aggregation node by clicking at projection node and using arrow:

Link%20Projection%20to%20Aggregation%20node

Link Projection to Aggregation node

At aggregation node again I will add required fields (Interaction contact key, agreement type, agreement id) as output column in ‘Mapping’ tab:

Aggregation%20mapping

Aggregation mapping

Now it’s time to create a counter for agreements, by going to ‘Calculated Column’ tab at aggregation node:

Create%20counter

Create counter

Drill down into properties of created counter:

Counter

Counter

Make sure that column type is set as ‘Measure’ and aggregation type is ‘COUNT_DISTINCT’. At the Counter column section select ‘MKT_AGREEMENTEXTERNALID’ as the source field for contract account count:

Counter%20column

Counter column

Proceed to Semantics node and mark ‘INTERACTIONCONTACTUUID’ as key field (to map our view in SAP Marketing Cloud) and select hidden checkbox for ‘MKT_AGREEMENTEXTERNALID’ as shown below (otherwise this will lead to different count result):

Semantics

I’m done with the View build, now I need only to activate it. Right-click on the view, select Build > Build Selected Files:

Activate%20Custom%20Calculation%20View

Activate Custom Calculation View

 

Part III – Import new Custom Calculation View into Marketing Cloud

After successful Custom view build, I will export the View from SAP Web IDE, by right click on the View>Export:

Export%20Custom%20View%20from%20WebIDE

Export Custom View from SAP Web IDE

Before loading the view into SAP Marketing Cloud, I must rename extension of the file from “.hdbcalculationview” to “.xml” and save.

Login to SAP Marketing Cloud and run ‘Add Custom View’ app under the Extensibility and Adaptability for Marketing tab. (Note: if you can’t find the app, make sure you have required authorization rights for your role). You will get a pop-up message informing you about upgrade to SAP HANA 2.0, just proceed to second tab ‘Import View Definition’, set view usage type as ‘Segmentation’, browse for your view and press Import View:

Import%20Custom%20Calculation%20View%20into%20Marketing%20Cloud

Import Custom Calculation View into Marketing Cloud

Now I need to assign my new Custom Calculation View to segmentation. Go to ‘Marketing Extensibility’ app and scroll down till Custom View section and select ‘Assign to Segmentation’:

Assign%20Custom%20View%20to%20Segmentation

Assign Custom View to Segmentation

Pres on ‘+’ sign at the left bottom side of the screen to add new View and fill in the details as displayed below:

New%20view%20assignment

New view assignment

Go to ‘Segmentation Configuration’ app > Segmentation Objects and Attributes > Consumers and scroll to Assigned Data Sources list, searching for ‘_SAP_CV_AGR_COUNT’ and click on it. Once inside let’s configure attribute visibility and conditions for key figure. , go to ‘Edit’ mode and adjust checkboxes as below:

Configure%20Assigned%20Data%20Source%20Attributes

Configure Assigned Data Source Attributes

By marking Agreement type ‘visible as dimension’ in segmentation configuration will allow me to use that attribute as condition for Agreement type count measure.

Finally let’s check how does it look in ‘Segmentation model’ app. Attributes of the newly added custom view by default will be at the end of all existing marketing attributes and groups (if you have not changed this in segmentation configuration) or type attribute name ‘Agreement Count’ in search field and then drag-and-drop it to ‘All consumers’ node, entering the count equal ‘1’ and at conditions from the drop down menu select ‘Agreement type’ as ‘001 – Residential Contract Account’, press keep:

Consumers with single Residential Agreement Account

Now we have a first branch which stores all Consumers who has exactly one Residential Contract Account. Repeat the same operation, selecting single contract account of type ‘002 – Commercial Contract Account’, which will generate a second branch. Afterwards select the first node and drag-and-drop it over the second node, you will get a combine segments pop-up, choose ‘intersect’ option:

Combine%20Segments%3A%20Intersect

Combine Segments: Intersect

At the end I got a Segment node which has Consumer ID, who has exactly one Residential and exactly one Commercial Contract Account:

Final%20node%20for%20Target%20Group

Final node for Target Group

With this new measure attribute ‘Agreement count’ I can easily create different segmentation nodes for my marketing campaigns and offers, based on exact amount of agreement type consumer has and be more efficient in targeting the right audience.

For more information about why you should integrate SAP S/4HANA Utilities with SAP Marketing Cloud, you can read about how utilities can leverage the Segmentation application to identify target groups and how utilities can enrich their SAP S/4HANA integration with SAP Marketing Cloud by using custom fields.

Assigned Tags

      7 Comments
      You must be Logged on to comment or reply to a post.
      Author's profile photo Damodar Damodar
      Damodar Damodar

      Hi,

       

      I tried to open the links which you mentioned in the article. Unfortunately, the link ( why you should...)has broken. Could you get me the correct link to get more information?

       

      Regards

       

      Author's profile photo Olegs Tovstenko
      Olegs Tovstenko
      Blog Post Author

      Hi Damodar,

      Thank you for noticing this.

      I have aligned with the blog post author and now it is re-published and accessible from my reference link or below one:

      https://blogs.sap.com/2019/03/21/why-integrate-sap-s4hana-utilities-with-sap-marketing-cloud/

       

      Regards,

      Olegs

      Author's profile photo Jef Op de Beeck
      Jef Op de Beeck

      Dear all,

      We are currently struggling to make our custom view in segmentation view available. It is very similar to the blog except we are not creating calculation views.

      Our use case is merging two datasources (one standard, one from a custom business object) we have identified our join attribute and joined both datasources. We use a left-outer and have already tried 1.1 and n.m cardinality.

      Our overall view looks as followed:

       

      Once we enable it for segmentation the attributes are empty. However if we recreate the same custom view via a custom CDS view we do see that there should be values available.

       

       

      Any advice is welcome!

       

      Kind regards, Jef Op de Beeck

      Author's profile photo Olegs Tovstenko
      Olegs Tovstenko
      Blog Post Author

      Hi Jef Op de Beeck,

      If I understood your business requirement correctly you don't need a Custom view for that, you may achieve it by using Add Custom Business Object to Segmentation application.

      Where you should select the segmentation object to which the custom business object needs to be assigned, then map the fields of the root node of the custom business object and define required field of the nodes as visible.

      Once tested in Test/Quality tenant you should export the custom business object and segmentation assignment using the Register Extensions for Transport application.

      For more details please refer to SAP Help Portal - Custom Business Object in Segmentation

      Regards,

      Olegs

      Author's profile photo Jef Op de Beeck
      Jef Op de Beeck

      Hi Oleg,

      thanks for the reply! Allow me to explain our use case a bit further.

      We are filling up our standard object on account level via a custom integration. Currently it is not possible within the standard integration. The standard fields are also not available for segmentation.

      Therefore, we created a CBO that we indeed can use in the segmentation as you mention. We need the custom view to use our standard fields in the segmentation.

      So if the standard field on the account is equal to 1234 and the value 1234 is also maintained in our CBO then it should appear in our custom view, which we then use to segmentate on the value 1234 for our account.

      Hope this clarifies,

       

      Kind regards,

      Jef

      Author's profile photo Olegs Tovstenko
      Olegs Tovstenko
      Blog Post Author

      Hi Jef Op de Beeck,

      Does the root node of your CBO contain the ID_ORIGIN and ID of the interaction contact?

      If yes, you should be able to use Add Custom Business Object to Segmentation app.

      If no, then you are on the right path - Creating Custom View. There are two ways of adding custom views as data sources to a Segmentation Object:

      1. Build the custom views and join them in the central star join as dimension views.
      2. Build the custom views and assign them as data sources via the Segmentation configuration.

      For more details I would kindly recommend you to refer to Best Practice on SAP HANA Modeling for Segmentation blog post, section Custom View modeling guidelines hope this helps.

      Regards,
      Olegs

      Author's profile photo Jef Op de Beeck
      Jef Op de Beeck

      Hi Oleg,

      The CBO does not contain the ID_Origin and ID of the interaction contacts.

      The thing is we already created the custom view based on the best practices. Yet, our custom view does not contain any values. We are quite sure that our custom view is correct.

      Do you see anything weird i my visualization.

       

      Regards,

       

      Jef