Data Services Scenario Questions Part 2
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.
- Cumulative Sum of salaries, department wise
- Getting the value from the previous row in the current row
- Getting the value from the next row in the current row
- Getting total Sum of a value in every row
- Cumulative String Concatenation (Aggregation of string)
- Cumulative String Aggregation partition by other column
- String Aggregation
Scenario 2: Let's try to Design a dataflow to get the Previous Departments Salary for the current Department. If there is no previous row exists for the current row, then the previous row salary should be displayed as null. The target table data should look like below:
DEPTNO | SALARY | PREVIOUS_SALARY |
10 | 1000 | NULL |
20 | 2000 | 1000 |
30 | 3000 | 2000 |
40 | 4000 | 3000 |
Solution:
1. Let us reuse the File Format as defined in the previous example as Source.
2. Next we use the Batch Job, JB_SCENARIO_DS. Within the Job we create a Data Flow, say DF_SCENARIO_2.
3. Use File Format, from the Local Object Library as Source in the Data flow Workspace.
4. Next we place a Query transform, say QRY_PREV_SAL. First we select the columns DEPTNO and SALARY from the Schema In of the Query transform and Map to Output.
Next we specify a New Output Column in Schema Out of the Query transform. Let's name it as PREV_SALARY with data type decimal(10,2).
Next we define the Mapping value as previous_row_value( FF_SRC_DEPT.SALARY ).
Using the Data Services function previous_row_value we can capture the previous value of a column for the current record being processed.
5. Finally we place a Template Table as Target in the Target Datastore.
Click here to read the next scenario - Getting the value from the next row in the current row.