Leverage the power of SAP S/4HANA core data services in Cloud Platform Integration for Data Services – Part 2.
This blog post is the part-2 of the first blog post I had written: Leverage the power of SAP S/4HANA core data services in Cloud Platform Integration for Data Services.
The CDS(Core Data Services) views can have parameters as input. In such cases these parameters has to be specified as part of the select statement, when these source tables are part of the CPI-DS data flows (Cloud Platform Integration for Data Services). If such CDS views are used inside the CPI-DS tasks and data flows, you will encounter an SQL error message in the back end. The error message is due to the fact that these CDS views require the input parameters to be specified when the SQL statement is executed.
In such cases having the CDS view simply as a source table in CPI-DS data flow, will not work. Rather you will have to use Custom ABAP transform in the CPI-DS data flow to leverage the usage of the CDS views.
Here is the way you can implement custom CDS view within the CPI-DS data flow which can be integrated to Integrated Business Planning (IBP).
In the example below I have used the I_SALESORDERITEMCUBE which requires 2 input parameters: P_ExchangeRateType (Exchange Rate Type) and P_DisplayCurrency (Display currency). This is shown in the below Figure 1.
Figure 1: CDS view in S/4HANA.
I have used a custom ABAP transform in CPI-DS to:
- Parameterize the “Exchange rate type” and “display currency” as the global variables in the CPI-DS data flow. The 2 parameters are named as:
- $KURST2 (representing: P_ExchangeRateType) and
- $CURR2 (representing: P_DisplayCurrency)
- These 2 parameters are passed to the custom ABAP transform – form routine as $KURST1 and $CURR1.
- In the custom ABAP code for the custom ABAP transform, I have represented these 2 variables as $PARAM1 ($KURST1) and $PARAM2 ($CURR1).
Following are the steps you could follow to realize usage of CDS views with parameters in CPI-DS.
Step 1: Choose the CDS view in SAP S/4HANA which requires parameters as part of its definition. Ensure that you note down the data elements of these CDS view parameters.
Step 2: Create the data flow in CPI-DS.
The figure 2 shows the data flow with the custom ABAP transform that is created in CPI-DS:
Figure 2: Data flow with custom ABAP.
Ensure that you have created the required data stores for this dataflow. Source would be a SAP S/4HANA and target would be a SAP Integrated Business Planning system (SAP IBP).
Step 3: Configure the custom ABAP
Within the custom ABAP, create 2 global variables and the output of the custom ABAP as shown in the figure 3.
Figure 3: Create global variables and output of the custom ABAP.
Step 4: Configure the ABAP form parameters and create the ABAP custom code.
Create 2 form parameters for the custom ABAP transform.
These 2 parameters will represent the global variables that were created in Step 3. Doing this ensures that you can change these 2 variables during the execution of the dataflow.
Figure 4 shows the declaration of the 2 variables. If you have chosen a CDS view other than the one specified in this blog post, you can get parameter definitions from the S/4HANA system by checking the CDS view fiori app.
Figure 4 below shows the configuration of the ABAP form parameters
Now select the ABAP form editor and write the ABAP code that is specified in the figure 5.
Figure 5: ABAP custom code in the custom ABAP transform.
In the above example, the parameters are now passed from the CPI-DS to the custom ABAP form routine, which is in turn passed to the SQL statement.
Finish the data flow by mapping it until the target.
Test 1: Sending the $KURST2 = ‘1001’ and $CURR2 = ‘USD’.
The output is as shown in the figure 6. The currency field is shown as ‘USD after executing in design mode in CPI-DS data flow.
Figure 6: Design run-time output of the above data flow for Display currency = ‘USD’.
Test 2: Changing the $KURST2 = ‘EURO’ and $CURR2 = ‘EUR’. Figure 7 shows the output of the field in EUR.
Figure 7: Design run-time output of the above data flow for Display currency = ‘EUR’.
Based on the example provided in this blog post, you can now use CDS views with parameters in CPI-DS through custom ABAP transforms.