0% found this document useful (0 votes)
992 views3 pages

Decimal Conversion For The Currency Field - ABAP - STechies

SAP stores currency values in tables with 2 decimals even for currencies with fewer decimals, and uses function modules to convert values between the 2 decimal format for storage and the correct number of decimals for display to users. The document provides examples of these conversions, explaining how amounts in JPY and BHD currencies are converted between 2 decimal storage format and their actual 0 and 3 decimal display formats.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
992 views3 pages

Decimal Conversion For The Currency Field - ABAP - STechies

SAP stores currency values in tables with 2 decimals even for currencies with fewer decimals, and uses function modules to convert values between the 2 decimal format for storage and the correct number of decimals for display to users. The document provides examples of these conversions, explaining how amounts in JPY and BHD currencies are converted between 2 decimal storage format and their actual 0 and 3 decimal display formats.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

Decimal Conversion for the Currency Field

By: Uttam | 16 Apr 2011 7:17 am | 0 Comments

156 0 1 2

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.

Read More About SAP ABAP

FM to converts the data to two


1. 'CURRENCY_AMOUNT_BAPI_TO_SAP' FM
decimal before saving

'CURRENCY_AMOUNT_SAP_TO_BAPI FM for the conversion to correct


2 FM
' 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 -> Holds 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 -> Holds 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

Read Here at SAP ABAP Forum to Get Answers for More Questions Like Aforementioned.

You might also like