Register Login

Convert Currency Format

Updated May 18, 2018

SAP (Systems Applications and Products) maintains ALL currencies in its tables (BSEG, MBEW, etc) with 2 decimals

Even the currencies which do not have 2 decimals

For example - JPY which has zero decimals, BHD which has 3 decimals

All standard SAP reports and transaction views - Material master, GL etc convert the two decimal database to the correct decimals for end-user viewing.

Below mentioned function module converts the data to two decimal before saving to table

And the conversion to correct decimals for end-user viewing.

1.

'CURRENCY_AMOUNT_BAPI_TO_SAP'

FM

FM to converts the data to two decimal before saving

2

'CURRENCY_AMOUNT_SAP_TO_BAPI '

FM

FM for the conversion to correct decimals for end user viewing.

*To converts the data to two decimal before saving

Data:w_source type p decimals 2.

*“ The Curr field, which is the required format

PARAMETER :w_tgt type BAPICURR-BAPICURR.
PARAMETER : w_curr type TCURC-WAERS .

*w_tgt -> Hold’s the amount to be converted ,i.e the value entered by *the End user

*w_curr -> The currency field entered by the User for amount w_tgt

CALL FUNCTION 'CURRENCY_AMOUNT_BAPI_TO_SAP'
EXPORTING
currency =w_curr
bapi_amount = w_tgt
IMPORTING
SAP_AMOUNT = w_tgt
EXCEPTIONS
BAPI_AMOUNT_INCORRECT =1
OTHERS=2
.

IF sy-subrc <>0.
* MESSAGE ID SY-MSGID TYPESY-MSGTY NUMBER SY-MSGNO
* WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
w_source = w_tgt.

write:/(30) 'Value stored in SAP:',w_source.

Sample Output:

Input 1 : w_tgt : 123 , w_curr : JPY

Output : w_source : 1.23

Input 2: w_tgt : 123.123 w_curr : BHD

Output: w_source : 1231.23

***********************************************************

*The conversion to correct decimals for end user viewing.

Data : w_source type p decimals 3.

*“ The Curr field, which is the displayed Can be two or four decimals as per the requirement

PARAMETER : w_tgt type BAPICURR-BAPICURR.
PARAMETER : w_curr type TCURC-WAERS .

*w_tgt -> Hold’s the amount to be converted ,i.e the value entered by *the End user

*w_curr -> The currency field entered by the User for amount w_tgt

CALL FUNCTION 'CURRENCY_AMOUNT_SAP_TO_BAPI'
EXPORTING
currency = w_curr
sap_amount = w_tgt
IMPORTING
bapi_amount = w_tgt .

IF sy-subrc <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
*WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.

w_source=w_tgt.

write:/(30)'Value displayed :',w_source.

Sample Output:

Input 1 : w_tgt : 1.23 , w_curr : JPY

Output : w_source :123.000

Input 2 : w_tgt : 123.12 w_curr : BHD

Output :w_source :12.312

Thanks


×