Formatting amounts is not only dependent on the currency, but is also dependent on the country. Here some examples:
|Country||Currency||Example amount||Symbol position (1)||Space in between (2)||Decimal sign (3)||Number of decimals (4)||Currency symbol (5)|
There are 3 characteristics of an amount format which are country specific.
1. Symbol position. (In USA it is left, in Germany right.)
2. Space in between symbol and amount. (In USA no space, Netherlands one space.)
3. Decimal sign.
And 2 characteristics are currency specific
4. Number of decimals.
5. Currency symbol.
Characteristic 3 and 4 can be retrieved from SAP database tables.
3. Decimals sign: SAP field “Decimal Format” (T005X-XDEZP).
4. Number of decimals: SAP field “Number of decimal places” (TCURX-CURRDEC).
So for characteristics 1, 2 and 5 we need an extra table.
Currency ABAP class
I created a class to format amounts based on the country and currency. The class name is ZCUR_CURRENCY_BO.
Get formatted amount in ABAP.
"Get currency object DATA(lo_currency_bo) = zcur_currency_bo_ft=>get_factory( )->get_currency_bo( iv_country_key = <ls_currency>-country_key iv_currency_key = <ls_currency>-currency_key ). "Format amount DATA(lv_formatted_amount) = lo_currency_bo->format_amount( lv_amount ).
- iv_country_key = ‘US’
- iv_currency_key = ‘USD’
- lv_formatted_amount = $1,234.57
How does it work?
In class ZCUR_CURRENCY_BO_DP in the CLASS_CONSTRUCTOR method the table GT_CURRENCY_LIST is filled with the characteristics 1, 2 and 5.
( country_key = ‘US’ currency_key = ‘USD’ left_symbol = |$| right_symbol = || )
( country_key = ‘DE’ currency_key = ‘EUR’ left_symbol = || right_symbol = | €| )
- 1. Symbol position
The symbol is placed in the field left_symbol or right_symbol.
- 2. Space in between symbol and amount
The space is placed with the left_symbol or right_symbol. See for example the German right_symbol = | €|.
- 5. Currency symbol
The currency symbol is placed in the field left_symbol or right_symbol.
- Table GT_CURRENCY_LIST is not yet complete.
You can extend it in your own system.
Program ZCUR_CURRENCY_BO_LIST can be used to create a list of all currencies.
The colum “L/R” = “Left or right symbol indicator” indicates whether a currency has a left or right symbol.
If you have some updates for me with these currency symbols, than please send them to me via blogs.sap.com or via Github.
- If a currency does not have a left_symbol or right_symbol, than the Currency ISO code will be placed to right of the amount with a space in between. For example for Egypt 1,234.57 EGP.
- Always check with program ZCUR_CURRENCY_BO_LIST the currency you use.
Don’t assume all symbols are correct. And test it wherever you use it.
It is about money, so you should always be careful.
Using the framework
- Be sure you have program ZABAPGIT in your SAP system.
- Import the Github repository:
… in your SAP system.
- Start program ZCUR_CURRENCY_BO_LIST to see the results.
Alwin van de Put