HANA SQL function IFNULL used to get currency code number of decimals from TCURC and TCURX

Share Button

The function IFNULL Function (Miscellaneous) in HANA allows to replace a null result with the second parameter of the function.
Table TCURC has the different currency codes like AUD, USD, JPY and the second table TCURX has the number of decimal places. This second table is an “exception” table, i.e., only currency codes that do not have 2 decimal places are in this table.

This poses a problem: values stored in transactional tables in JPY (Yen) are “divided” by 100: as the number of decimals is zero, the system stores the value as if divided by 100. So, out of SAP ECC they need to be multiplied by 10 to the power of (2 minus number of decimals). But as TCURX is an “exception” table, before doing this in a table function or other way, we may need to make sure that for every value in TCURC we have a value in TCURX:

1
2
3
4
SELECT A."WAERS", IFNULL(B."CURRDEC",'2') AS "CURRDEC" 
  FROM "myschema"."TCURC" AS A 
  LEFT OUTER JOIN "myschema"."TCURX" AS B
  ON A."WAERS" = B."CURRKEY"
TCURC TCURX
TCURC and TCURX

The result now has all currency codes even when they are not in table TCURX.

Share Button

Leave a Reply

Your email address will not be published. Required fields are marked *