Sap Hana Abap Sqlscript Functions
Sap Hana Abap Sqlscript Functions
layer i.e. avoid loops, further joins, formatting or data conversions. To achieve this, we can leverage
HANA SQL functions to ensure the that the data being returned from AMDP is complete and needs
zero or a light touch while passing to the ABAP Layer.
Using the below explained functions we as a HANA developer can make our lives easier.
Function1—— CAST
Description: This function converts any value to the desired data type.
Sample:
Explanation:
In the above example, WKURS field of the table EKKO is of DEC 9 type. But at the time of display to
the end user we want to concatenate a fixed text with the value of this field. For concatenation we
shall need to convert the value of this field to the string type. So we have used the cast operator to
convert decimal to string type.
Output:
Function2—– IFNULL:
Description:
Sample:
Output:
Explanation:
In the above example we want to fill the field KDATB of the table EKKO with the current date if the
value of the field is NULL. For this we have used the IFNULL function which has the field on which
we want to perform this function as the first parameter, and the second parameter is the expression
which we want to get executed if the value of the field is NULL.
Function3—– COALESCE
Description:
Returns the first non-NULL expression from a list. At least two expressions must be contained in
expression_list, and all expressions must be comparable. The result will be NULL if all the
arguments are NULL.
Sample:
Output:
Explanation:
In the parameters of COALESCE function we can pass as many expressions as we want. The
Function will look for the first non-null value and insert in our output. In the above example we have
fixed the value in the second expression which is ‘No PO’, so wherever the value of lifnr is null it will
place the hard-coded value.
Function4—– CONVERT_CURRENCY
Description: We can use this function in AMDP to display a column with values in the desired
currency, just like we have the same functionality in Modelling Views.
Sample code:
Output:
Explanation:
In the above example, we have converted the Gross_amount field values which were earlier in EUR
to USD using the above mentioned function.