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 4: Let's try to design a dataflow to get the the sum of salaries of all departments and this sum should repeat for all the rows. The target table data should look like below:
1. Let us reuse the File Format as defined in the previous examples as Source.
2. Next we use the same Batch Job, JB_SCENARIO_DS. Within the Job we create a Data Flow, say DF_SCENARIO_4.
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_ALL_ROW. First select the columns DEPTNO and SALARY from the Schema In of the Query transform and Map to Output.
Next we define a New Output Column, say DUMMY with data type int and specify the Mapping as numeric 1.
5. Next we use another Query transform, say QRY_SUM_SAL. Select the columns SALARY from the Schema In of the Query transform and Map to Output. Rename the column to SUM_SALARY and specify the Mapping value as sum(FF_SRC_DEPT.SALARY ).
Using the Data Services function sum we will calculate the sum of salaries of all departments. Next to assign this value as a column along with all the source rows we will Join the two flows or pipelines.
So for that we define a New Output Column, say DUMMY with data type int and specify the Mapping as numeric 1.
6. Next we place another Query transform, say QRY_JOIN. Select the columns DEPTNO, SALARY of Input Schema QRY_ALL_ROW from the Schema In of the Query transform and Map to Output. Also select the column SUM_SALARY of Input Schema QRY_SUM_SAL from the Schema In of the Query transform and Map to Output. Perform an INNER JOIN between the Input Schemas QRY_ALL_ROW and QRY_SUM_SAL based on the column DUMMY.
So for all the source records we get the sum of salaries for all departments repeated as a column value.
7. Finally we place a Template Table as Target in the Target Datastore.
Click here to read the next scenario - Cumulative String Concatenation (Aggregation of string).