Application Development Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 

Currency Conversion

Former Member
0 Kudos
400

Hello,

I have a requirement where i need to convert my currency INR to USD. I used the FM ' CONVERT_TO_FOREIGN_CURRENCY'

CALL FUNCTION 'CONVERT_TO_FOREIGN_CURRENCY'

EXPORTING

CLIENT = SY-MANDT

DATE = SY-DATUM

FOREIGN_CURRENCY = USD

LOCAL_AMOUNT = 1000

LOCAL_CURRENCY = INR

RATE = 0

TYPE_OF_RATE = 'M'

READ_TCURR = 'X'

But when i execute the program it says that "Field "USD" is unknown. It is neither in one of the specified tables". How do i rectify this error please help me out.

Can anyone tell me, in which table-field is the currency USD and INR are stored?

Regards,

Abhishek.

1 ACCEPTED SOLUTION

SuhaSaha
Advisor
Advisor
0 Kudos
323

Hello Abhishek,


CALL FUNCTION 'CONVERT_TO_FOREIGN_CURRENCY'
EXPORTING
CLIENT = SY-MANDT
DATE = SY-DATUM
FOREIGN_CURRENCY = USD
LOCAL_AMOUNT = 1000
LOCAL_CURRENCY = INR
RATE = 0
TYPE_OF_RATE = 'M'   "--> Error may be because of this x-rate type
READ_TCURR = 'X'

Please check in TCURR what is the value in KURST (Exchange rate type) for the curr. conversion from INR --> USD. I doubt it is not 'M'. I will ask you to check in TCURR and modify your code accordingly:


CALL FUNCTION 'CONVERT_TO_FOREIGN_CURRENCY'
EXPORTING
CLIENT = SY-MANDT
DATE = SY-DATUM
FOREIGN_CURRENCY = USD
LOCAL_AMOUNT = 1000
LOCAL_CURRENCY = INR
RATE = 0
TYPE_OF_RATE = TCURR-KURST
READ_TCURR = 'X'

Hope this helps.

BR,

Suhas

20 REPLIES 20

Former Member
0 Kudos
323

Hi,

Check table TCURR

Fields are FCURR and TCURR

Currency codes maintained in TCURC

Also see TCODE S_BCE_68000174 for maintaining the exchange rates

Regards

Edited by: Rajvansh Ravi on Jan 28, 2009 9:52 AM

former_member217544
Active Contributor
0 Kudos
323

Hi,

As USD, 1000, INR are constants we need to keep them in single quotes.

CALL FUNCTION 'CONVERT_TO_FOREIGN_CURRENCY'

EXPORTING

CLIENT = SY-MANDT

DATE = SY-DATUM

FOREIGN_CURRENCY = 'USD'

LOCAL_AMOUNT = '1000'

LOCAL_CURRENCY = 'INR'

RATE = '0'

TYPE_OF_RATE = 'M'

READ_TCURR = 'X'.

Hope this will help you.

Regards,

Swarna Munukoti.

0 Kudos
323

Hi

Jus try changing the code as :

CALL FUNCTION 'CONVERT_TO_FOREIGN_CURRENCY'

EXPORTING

date = sy-datum

foreign_currency = 'USD'

local_amount = '1000.00'

local_currency = 'INR'

IMPORTING

FOREIGN_AMOUNT = l_amount .

IF sy-subrc <> 0.

ENDIF.

Only the above are mandatory . Also specify your fields within quotes.

0 Kudos
323

Hi Swarna,

My question is partly is answered, I have given the values in quotes. But when i execute the program it does not retrieve any value. Where is the value of USD is being stored?.. Do i have to take another variable to store the USD value and print it?.

How do i do it? Can you please explain me with an example.

Please help me out.

Regards,

Abhishek.

0 Kudos
323

Hi,

Check table TCURR for exchange rate

Regards

0 Kudos
323

Hi Martina,

Do i have to declare the field I_amount, as you suggested. If so, what type of declaration should be given to the variable I_amount. ?

I have already taken a variable and declared it in importing-foreign amount. And i printed it at the end of the program. But the value retrived in the output is 0.00.

How do i rectify this?

Regards,

Abhishek

Edited by: abhishek sunkari on Jan 28, 2009 10:18 AM

0 Kudos
323

Hi,

you can also use the below FM for the conversion

CALL FUNCTION 'CRM_CONVERT_CURRENCY'

EXPORTING

iv_exch_rate_date = sy-datlo

iv_source_currency = 'INR'

iv_local_currency = 'INR'

iv_target_currency = 'USD'

CHANGING

cv_value = lv_amnt

EXCEPTIONS

conversion_not_possible = 1

OTHERS = 2.

IF sy-subrc <> 0.

MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno

WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4 INTO lv_dummy.

ENDIF.

the value of lv_amnt, will be in INR before the FM is called & it will be converted to USD after execution

0 Kudos
323

Hey Seemanthini,

Thanks a lot for the reply, i had a doubt regarding the variable 'lv_amount', i just wanted to know the declaration type. Should it be declared at the starting, if yes what should be the type of declaration.

Please help me out!

Regards,

Abhishek

0 Kudos
323

Hi,

DATA : lv_amnt TYPE crmt_net_value.

just convert whatever amount type you have to lv_amnt type before calling conversion

regards,

Seema

0 Kudos
323

Hi ,

you can declare that variable before using and clear that variable before passing to the Function module.

CALL FUNCTION 'CONVERT_TO_LOCAL_CURRENCY_N'

EXPORTING

client = sy-mandt

date = bldat "For which date u want converted value

foreign_amount = hwste

foreign_currency = 'USD'

local_currency = '1000'

type_of_rate = 'M'

IMPORTING

local_amount = hwste

EXCEPTIONS

no_rate_found = 1

overflow = 2

no_factors_found = 3

no_spread_found = 4

derived_2_times = 5

OTHERS = 6.

IF sy-subrc <> 0.

MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno

WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.

ENDIF.

Former Member
0 Kudos
323

Hi,

The values to these variables should be passed in single quotes.

FOREIGN_CURRENCY = 'USD'

LOCAL_AMOUNT = '1000'

LOCAL_CURRENCY = 'INR'

RATE = '0'

Former Member
0 Kudos
323

In table TCURR, fields FCURR and TCURR.

Regards,

Joan

Former Member
0 Kudos
323

Hi

Give USD and INR in quotes as follows:

CALL FUNCTION 'CONVERT_TO_FOREIGN_CURRENCY'
  EXPORTING
*   CLIENT                  = SY-MANDT
    DATE                    = sy-datum
    FOREIGN_CURRENCY        = 'USD'
    LOCAL_AMOUNT            = 1000
    LOCAL_CURRENCY          = 'INR'
*   RATE                    = 0
*   TYPE_OF_RATE            = 'M'
*   READ_TCURR              = 'X'
* IMPORTING
*   EXCHANGE_RATE           =
*   FOREIGN_AMOUNT          =
*   FOREIGN_FACTOR          =
*   LOCAL_FACTOR            =
*   EXCHANGE_RATEX          =
*   DERIVED_RATE_TYPE       =
*   FIXED_RATE              =
* EXCEPTIONS
*   NO_RATE_FOUND           = 1
*   OVERFLOW                = 2
*   NO_FACTORS_FOUND        = 3
*   NO_SPREAD_FOUND         = 4
*   DERIVED_2_TIMES         = 5
*   OTHERS                  = 6
          .
IF SY-SUBRC <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
*         WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.

It doesnt give error now.

Hope this helps

Regards,

Jayanthi.K

Former Member
0 Kudos
323

hi

Try to use the fm CONVERT_TO_LOCAL_CURRENCY

BAPI_EXCHANGE_RATE_GETDETAIL

tarangini_katta
Active Contributor
0 Kudos
323

Hi Abshiek,

Use ur functionm module like this

CALL FUNCTION 'CONVERT_TO_FOREIGN_CURRENCY'

EXPORTING DATE = BKPF-WWERT

FOREIGN_CURRENCY = BKPF-WAERS

LOCAL_CURRENCY = T001-WAERS

LOCAL_AMOUNT = BSEG-DMBTR

RATE = BKPF-KURSF

TYPE_OF_RATE = 'M'

IMPORTING EXCHANGE_RATE = KURS

FOREIGN_AMOUNT = BSEG-WRBTR

FOREIGN_FACTOR = FAKTOR-F

LOCAL_FACTOR = FAKTOR-L

EXCEPTIONS NO_RATE_FOUND = 4

NO_FACTORS_FOUND = 8.

GO through the function module documenttaion of this FM.

there u have the clear information.

Thanks,

Former Member
0 Kudos
323

Hi,

Check the table TCURC...

Former Member
0 Kudos
323

Hi,

Maintain data in TCURR table parameter FCURR = USD, TCURR = INR.

Regards

Md.Mahaboobkhan

SuhaSaha
Advisor
Advisor
0 Kudos
324

Hello Abhishek,


CALL FUNCTION 'CONVERT_TO_FOREIGN_CURRENCY'
EXPORTING
CLIENT = SY-MANDT
DATE = SY-DATUM
FOREIGN_CURRENCY = USD
LOCAL_AMOUNT = 1000
LOCAL_CURRENCY = INR
RATE = 0
TYPE_OF_RATE = 'M'   "--> Error may be because of this x-rate type
READ_TCURR = 'X'

Please check in TCURR what is the value in KURST (Exchange rate type) for the curr. conversion from INR --> USD. I doubt it is not 'M'. I will ask you to check in TCURR and modify your code accordingly:


CALL FUNCTION 'CONVERT_TO_FOREIGN_CURRENCY'
EXPORTING
CLIENT = SY-MANDT
DATE = SY-DATUM
FOREIGN_CURRENCY = USD
LOCAL_AMOUNT = 1000
LOCAL_CURRENCY = INR
RATE = 0
TYPE_OF_RATE = TCURR-KURST
READ_TCURR = 'X'

Hope this helps.

BR,

Suhas

Former Member
0 Kudos
323

Hey Suhas,

Thanks a lot for the reply, you were rite, the problem mite have occurred due to the "TYPE_OF_RATE".

Its default value is 'M' always. Like you said i have checked the KURST field value in TCURR table for INR. But am afraid there no KURST value maintained for INR in TCURR, which means that the currency cannot be converted from or into INR. If i consider any other currency in FM i used to be dipalyed in USD, The output value is being displayed, but if i take INR, the value shows as 0.

Can you suggest me in solving this query. Can you give the reason or the process to check the INR value.

Regards,

Abhishek.

0 Kudos
323

Hello Abhishek,

You got to have the x-rate maintained in TCURR table else this FM will not work.

I think you should consult with your functional team regarding this.

BR,

Suhas