Logo DWBI.org Login / Sign Up
Sign Up
Have Login?
This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.
Login
New Account?
Recovery
Go to Login
By continuing you indicate that you agree to Terms of Service and Privacy Policy of the site.
SAP Data Services

Data Services Scenario Questions Part 5

 
Updated on Oct 02, 2020

In this tutorial we will discuss some scenario based questions and their solutions using SAP Data Services. This article is meant mainly for Data Services beginners.

This article is one of the series of articles written to showcase the solutions of different business scenarios in SAP Data Services. You may browse all the scenarios from the below list.

  1. Cumulative Sum of salaries, department wise
  2. Getting the value from the previous row in the current row
  3. Getting the value from the next row in the current row
  4. Getting total Sum of a value in every row
  5. Cumulative String Concatenation (Aggregation of string)
  6. Cumulative String Aggregation partition by other column
  7. String Aggregation

Consider the following Source data in a flat file:

DEPTNOENAME
20G
10A
10D
20E
10B
10C
20F
20H

Scenario 5: Let's try to transform & load the source data to the target table as below:

DEPTNOENAME_LIST
10A
10A,B
10A,B,C
10A,B,C,D
20A,B,C,D,E
20A,B,C,D,E,F
20A,B,C,D,E,F,G
20A,B,C,D,E,F,G,H

Solution:

1. Let us first define the Source File Format. This same file format will be reused for the next set of the scenario questions.

File Format
File Format

2. Next we use the same Batch Job, JB_SCENARIO_DS. Within the Job we create a Data Flow, say DF_SCENARIO_5.

3. At the Data flow level i.e. Context DF_SCENARIO_5, we Insert a new Parameter using the Definitions tab. Let's name it as $PREV_NAME with Data type varchar(100) and Parameter type as Input.

Parameters- Data flow
Parameters- Data flow
Parameter Properties
Parameter Properties

At the Job level i.e. Context JB_SCENARIO_5, we initialize the Parameter $PREV_NAME using the Calls tab. We set the Argument value to NULL.

Parameters- Job
Parameters- Job
Parameter Value
Parameter Value

4. Next we create a New Custom Function from the Local Object Library. Let's name it CF_CONCAT_ENAME.

Custom Function
Custom Function

Within the Custom Function Smart Editor, first we Insert two Parameters, namely $CURR_NAME and $PREV_NAME with Data types as varchar(20) and varchar(100) respectively. Their Parameter type being Input and Input/Output respectively.

Custom Function Definition
Custom Function Definition

Also we modify the Return Parameter Data type to varchar(100).

5. Next we define the custom function as below and Validate the same.

if ( $PREV_NAME IS NULL )
    $PREV_NAME = $CURR_NAME;
else
    $PREV_NAME = $PREV_NAME || ',' || $CURR_NAME;	 

Return $PREV_NAME;

The purpose of defining the Parameter and Custom Function is to perform Parameter Short-circuiting. Here within the function, we basically set the $PREV_NAME Parameter of type Input/Output to concatenate all employee names till the current processing row. Since it is of type Input/Output the concatenated string value is passed back into the Dataflow Parameter. So by using Custom Function we can modify and pass values to a Dataflow Parameter. Hence the Parameter defined at Dataflow level is short-circuited with the Input/Output Parameter of the Custom Function.

6. Lets go back and design the Data flow. First of all we take the File Format defined earlier, from the Local Object Library as Source.

Data flow
Data flow

7. Next we place a Query transform, say QRY_SORT. First we select the columns DEPTNO and ENAME from the Schema In of the Query transform and Map to Output. Specify the ORDER BY on DEPTNO and ENAME in Ascending type.

Query- Sort
Query- Sort

8. Next we place a Query transform, say QRY_CONCAT_NAME. First we select the columns DEPTNO from the Schema In of the Query transform and Map to Output.

Next we specify a New Function Call in Schema Out of the Query transform. Choose the Custom Functions from the Function categories and select the Function name CF_CONCAT_ENAME.

Next we Define Input Parameters. We specify the inputs as below:

$CURR_NAME = QRY_SORT.ENAME

$PREV_NAME = $PREV_NAME
Function Input Parameters
Function Input Parameters

Select the Return column as the Output Parameter.

Query- Function Call
Query- Function Call

9. Next we place a Query transform, say QRY_FORMAT. First we select the columns DEPTNO and Return from the Schema In of the Query transform and Map to Output. Rename the Return column to ENAME_LIST.

Query- Format
Query- Format

10. Finally we place a Template Table as Target in the Target Datastore.

Data Preview
Data Preview

Click here to read the next scenario - Cumulative String Aggregation partition by other column.

PrimeChess

PrimeChess.org

PrimeChess.org makes elite chess training accessible and affordable for everyone. For the past 6 years, we have offered free chess camps for kids in Singapore and India, and during that time, we also observed many average-rated coaches charging far too much for their services.

To change that, we assembled a team of top-rated coaches including International Masters (IM) or coaches with multiple IM or GM norms, to provide online classes starting from $50 per month (8 classes each month + 4 tournaments)

This affordability is only possible if we get more students. This is why it will be very helpful if you could please pass-on this message to others.

Exclucively For Indian Residents: 
Basic - ₹1500
Intermediate- ₹2000
Advanced - ₹2500

Top 10 Articles