How to Use the STRING_AGG function in SAP HANA Calculation views


STRING_AGG is the used to show the multiple row data into single row by concatenate with Given Value
Ex: We have the Data like in the following.

By Using the STRING_AGG function with concatenate with ‘;’. we can get the following output.

Mainly we have two main Steps
1.      Creation of Tables (Using CDS) & Insert of data.
2.      How to use the String_Agg Function in Calculation view by using the created tables.

Step By Step Process for the above Mention Points

1.      Creation of Tables (Using CDS) & Insert of data.

Step -1: Open the Perspective as SAP HANA Development as shown in the below screenshot.



Step-2: Right click on System in Repositories and select the Import Remote Workspace as shown in the below screenshot.



Step-3: Provide the Workspace Location and Click on Finish as shown in the below screenshot.




Step-4: Right Click on Package and select New and in the Select Others as shown in the below screenshot.


Step-5: Select the DDL Source File and Click on Next as shown in the below screenshot.




Step-6: Select the Package and Click on Next as shown in the below screenshot.


Step-7: Select Define Empty Context and click on Finish as shown in the below screenshot.



Step-8: After click on finish we can get the following Screen.



Step-9: Creating two Tables By using the Script in the below screenshot.



Step-10: Right Click on DDL File and select Activate as shown in the below screenshot.



Step-11: Activation Successfully as shown in the below screenshot.



Step-12: Tables are created in the given Schema as shown in the below screenshot.



Step-13: Right click on table Emp_Details and select Generate Insert Statement as shown in the below screenshot.



Step-14: Execute the following Script.


Step-15: Successfully Data is loaded in the Table .



Step-16: Right click on table and select Open Data Preview .



Step-17: Data output of the table Emp_Details.



Step-18: Right click on table Emp_Salary_Details and select Generate Insert Statement as shown in the below screenshot.



Step-19: Execute the following Script.



Step-20: Successfully Data is loaded in the Table.



Step-21: Right click on table and select Open Data Preview.



Step-22: Data output of the table Emp_Salary_Details




2.      How to use the String_Agg Function in Calculation view by using the created tables.

Step-1: Right Click on Package and select the Calculation View as shown in the below screenshot.



Step-2: Select Calculation View Type as SQL Script as shown in the below screenshot.



Step-3: After Click on Finish Below screen will come .



Step-4: In the Details Screen we have to write the following script (We required the total Salary with All Months in the single Cell).



Step-5: Activate by clicking on the Activate .


Step-6: Calculation View is successfully Activated as shown in the below screenshot.



Step-7: For Seeing the Output of the View select Open in Data preview Editor as shown in the below screenshot.




Step-8: Output of the view (Actually No of Row of data is there we are showing the data in the single row by using the String_Agg Function on the Repeated Value)

Comments