Handling Currencies having Zero Decimals in SAP ABAP

Some of the currencies have no decimal notation in it. Yes it’s true NO DECIMAL PORTION. Example: JPY, KRW etc. We can never have 10.25 JPY.
If this is surprising, the more surprise and shock is how SAP stores these currencies in standard table. It stores 100 JPY as 1.00 in the table.
YIKES !!
Yes all these currencies are stored like that. Let’s examine how SAP stores the value.
Before that it’s important to know that these currency settings are stored in table TCURX.
Example: If JPY currency is supported in your SAP system. It will have an entry in TCURX and will have Number of decimal places (CURRDEC) = 0.
tcurx

Before SAP stores any value of these currencies it applies the formula:
Stored value = actual value / ( 10 ^ (2 – CURRDEC) )
Example in case of JPY, Currdec = 0. So 100 JPY will be stored in table as
Stored value = 100 / 10 ^2 = 100/100 = 1.00
Let’s take an example of currency having 3 decimals. Yes there are currencies having 3 decimals. Example Tunisian Dinar (TND).
100 TND is stored in SAP table as = 100 / 10 ^ (2 – 3) = 100/(1/10) = 1000.00
Wow right!!
Off course all standard SAP programs are aware of this strange formula and will convert it back to correct number while display or doing some operations.
But custom Z programs will not work properly for these currencies. We have to convert the number back to original format manually (especially when you are posting using BAPI or while performing some arithmetic operations).
To get back the original value, just read the TCURX –CURRDEC for that currency and apply the formula
Actual value = stored value * ( 10 ^ ^ (2 – CURRDEC) ).
Example:
Actual value of 0.01 JPY stored in table
  • 0.01 * 10 ^ 2 => 1 JPY
READ TABLE i_tcurx INTO wa_tcurx WITH KEY currkey = x_post_temp-twaer BINARY SEARCH.
IF sy-subrc EQ 0.
    v_overval  =  x_post_temp-overval * ( 10 ** (2 - wa_tcurx-currdec )).
ENDIF.
We can also use a function module to accomplish the same:
We can use the FM CURRENCY_AMOUNT_SAP_TO_BAPI to convert and get the original value.
Example: JPY stored as 0.01 refers to 1 JPY
We can use the FM CURRENCY_AMOUNT_SAP_TO_BAPI to convert and get the original value.
We can use the FM CURRENCY_AMOUNT_BAPI_TO_SAP to get the stored value in table.
Ex: 100 JPY stored as 1.00 JPY
We can use the FM CURRENCY_AMOUNT_BAPI_TO_SAP to get the stored value in table.
Now before you start converting all values in your program, be aware that if your program doesn’t post/write anything and just displays a report, you can simple use the fieldcatalog of the ALV which does these conversions automatically at the time report is displayed.
This will work when your final internal table / report display is having the currency column along with currency values. Just use ctabname and cfieldname in field catalog and refer to the field holding currency.
  w_fieldcat_alv-fieldname = 'TOTPRICE'.
  w_fieldcat_alv-tabname    = 'I_OUTPUT’.
  w_fieldcat_alv-col_pos  = l_col.
  w_fieldcat_alv-seltext_m = ‘TOTAL PRICE.
  w_fieldcat_alv-no_zero = ‘X’.
  w_fieldcat_alv-outputlen = ‘10’.
  w_fieldcat_alv-just = ‘R’. “(+)SRP – ER07170
“ Add currency reference
  w_fieldcat_alv-ctabname = ‘I_OUTPUT’.
  w_fieldcat_alv-cfieldname = ‘TWAER’.
APPEND w_fieldcat_alv TO li_fieldcat_alv.
That’s it SAP takes care of conversion and currency formatting when it is displaying the report. You don’t need to manually do the conversion in the program.