Application Development and Automation 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: 
Read only

Currency Conversion

Former Member
0 Likes
1,018

Hi

I tried the following FM to convert Currency, Sy-Subrc = 0.

pls advise me if i am wrong

LOOP AT IT_DETAIL.

If s_waers is not initial.

CALL FUNCTION 'CONVERT_TO_FOREIGN_CURRENCY'

EXPORTING

DATE = SY-DATUM

FOREIGN_CURRENCY = s_WAERS

LOCAL_AMOUNT = it_detail-dmbtr

LOCAL_CURRENCY = bkpf-waers

  • rate = 0

TYPE_OF_RATE = 'M'

IMPORTING

  • exchange_rate =

FOREIGN_AMOUNT = it_detail-dmbtr

  • foreign_factor =

  • local_factor =

  • exchange_ratex =

EXCEPTIONS

NO_RATE_FOUND = 1

OVERFLOW = 2

NO_FACTORS_FOUND = 3

OTHERS = 4.

if sy-subrc<> 0

ELSE.

ENDIF.

ENDLOOP.

1 ACCEPTED SOLUTION
Read only

venkat_o
Active Contributor
0 Likes
977

Hi Kumar, Have a look the following .

LOOP AT it_detail.
  IF s_waers[] IS NOT INITIAL.
    "Select-Option s_waers is a internal table
    "You cant pass s_waers as a variable, as foreign_currency in CONVERT_TO_FOREIGN_CURRENCY function module.
    "What you have to do is read the table s_waers for perticalular currency and pass through function module
    CALL FUNCTION 'CONVERT_TO_FOREIGN_CURRENCY'
      EXPORTING
        date             = sy-datum
        foreign_currency = s_waers " You cant pass like this as s_waers is internal table.
        local_amount     = it_detail-dmbtr
        local_currency   = bkpf-waers
        type_of_rate     = 'M'
      IMPORTING
        foreign_amount   = it_detail-dmbtr.
    IF sy-subrc <> 0.
    ENDIF.
  ENDIF.
ENDLOOP.
Regards, Venkat.O

8 REPLIES 8
Read only

Former Member
0 Likes
977

Hi,

How is the currency key input field (s_WAERS) defined?

It should be char field with value of currency code in it (eg USD).

If it is select option as the name implies the code will not work.

Read only

0 Likes
977

Hi Sudhir

s_waers defined as ,

SELECT-OPTIONS: s_waers FOR bkpf-waers.

Read only

Former Member
0 Likes
977

Hi,

You have to define a new variable of char type and pass currency code to it. Then use this as input value to currency code parameter of the FM.

You cannot use select option directly in the FM

Read only

Former Member
0 Likes
977

Hi,

see the usage of FM,

Compare with you code and fields

DATA : l_skb1 like skb1.

data: l_amount like fdes-wrshb.

call function 'CONVERT_TO_FOREIGN_CURRENCY'

exporting

date = sy-datum

foreign_currency = l_skb1-waers---This is a structure

local_amount = fdes-wrshb

local_currency = fdes-dispw

importing

foreign_amount = l_amount

exceptions

no_rate_found = 1

overflow = 2

no_factors_found = 3

no_spread_found = 4

derived_2_times = 5

others = 6.

Read only

venkat_o
Active Contributor
0 Likes
978

Hi Kumar, Have a look the following .

LOOP AT it_detail.
  IF s_waers[] IS NOT INITIAL.
    "Select-Option s_waers is a internal table
    "You cant pass s_waers as a variable, as foreign_currency in CONVERT_TO_FOREIGN_CURRENCY function module.
    "What you have to do is read the table s_waers for perticalular currency and pass through function module
    CALL FUNCTION 'CONVERT_TO_FOREIGN_CURRENCY'
      EXPORTING
        date             = sy-datum
        foreign_currency = s_waers " You cant pass like this as s_waers is internal table.
        local_amount     = it_detail-dmbtr
        local_currency   = bkpf-waers
        type_of_rate     = 'M'
      IMPORTING
        foreign_amount   = it_detail-dmbtr.
    IF sy-subrc <> 0.
    ENDIF.
  ENDIF.
ENDLOOP.
Regards, Venkat.O

Read only

Former Member
0 Likes
977

Hi Venkat

S_waers is not an internal table. It is selection screen field

Read only

Former Member
0 Likes
977

No its an internal table if use select-options for s_waers then its an internal table

Read only

0 Likes
977

hi kumar,

it is a selection-screen field and at the same time an internal table with the following structure.


sign type c
option type char02
low type werks
high type werks

regards,

Peter