Welcome To My BLOG

This site is to give a brief idea for the abap learners who are looking for some real time programs .It consists of collection of programs from my side . I hope these programs are very much used for all of the learners. Please check the links for any information in ABAP.
Please vote for my Blog. And please input me on this mail addrssess.Email me

Share this link with your friends

http://www.rebtel.com/u/15163104576

For every friend who signs up using this link and makes a payment, we'll give you 8 €!


Wednesday, September 22, 2010

FM Currency Conversion

Currency Convertion (i.e. from EUR to GBP)
Below is the code for converting currency values from one currency to another. For demonstration purposes
this example converts 10 euros into GBP. Please note when you display this value you may first need to
convert it from its internal SAP value to the proper external display value. See below code for more details.
Convert currency value from internal(SAP) to external(display)
CODE:
Values stored in fields of type CURR can have different values than those displayed on screen. To
ensure the correct value is displayed on screen or used in calculations the value in the field must be
accosiated to its currency unit. This can be done using a number of standard ABAP statements like
WRITE/ *Write TO and also with the FM CURRENCY_AMOUNT_SAP_TO_DISPLAY. Once you
have done this you may want to convert the value to another currency.
Author: Peter Phasha
* Convert Internal SAP value to Currency value
data: p_intval like wmto_s-amount. "Internal Amount
data: gd_disval like wmto_s-amount. "Display Amount
call function 'CURRENCY_AMOUNT_SAP_TO_DISPLAY'
exporting
currency = po_tab-waers
amount_internal = p_intval
importing
amount_display = gd_disval
exceptions
internal_error = 1
others = 2.
DATA: gd_fcurr TYPE tcurr-fcurr,
gd_tcurr TYPE tcurr-tcurr,
gd_date TYPE sy-datum,
gd_value TYPE i.
gd_fcurr = 'EUR'.
gd_tcurr = 'GBP'.
gd_date = sy-datum.
gd_value = 10.
PERFORM currency_conversion USING gd_fcurr
gd_tcurr
gd_date
CHANGING gd_value.
* Convert value to Currency value
*&---------------------------------------------------------------------*
*& Form currency_conversion
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* -->P_GD_FCURR text
* -->P_GD_TCURR text
* -->P_GD_DATE text
* <--P_GD_VALUE text
*----------------------------------------------------------------------*
FORM currency_conversion USING p_fcurr
p_tcurr
p_date
CHANGING p_value.
DATA: t_er TYPE tcurr-ukurs,
t_ff TYPE tcurr-ffact,
t_lf TYPE tcurr-tfact,
t_vfd TYPE datum,
ld_erate(12) TYPE c.
CALL FUNCTION 'READ_EXCHANGE_RATE'
EXPORTING
* CLIENT = SY-MANDT
date = p_date
foreign_currency = p_fcurr
local_currency = p_tcurr
TYPE_OF_RATE = 'M'
* EXACT_DATE = ' '
IMPORTING
exchange_rate = t_er
foreign_factor = t_ff
local_factor = t_lf
valid_from_date = t_vfd
* DERIVED_RATE_TYPE =
* FIXED_RATE =
* OLDEST_RATE_FROM =
EXCEPTIONS
no_rate_found = 1
no_factors_found = 2
no_spread_found = 3
derived_2_times = 4
overflow = 5
zero_rate = 6
OTHERS = 7
.
IF sy-subrc EQ 0.
ld_erate = t_er / ( t_ff / t_lf ).
p_value = p_value * ld_erate.
ENDIF.
ENDFORM. " currency_conversion

No comments: