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

code reduction

Former Member
0 Likes
684

Hi,

I have two fields which contains JPY currency.

I want to convert into USD using function module.I have coded two times for two fields.Is there any way to write one time to get currencies for two fields?

if t_bill-WAERK ne 'USD'.

  • for JPY

if t_bill-WAERK eq 'JPY'.

t_bill-NETWR = t_bill-NETWR * 100.

endif.

*for netwr

CALL FUNCTION 'CONVERT_TO_LOCAL_CURRENCY'

EXPORTING

CLIENT = SY-MANDT

DATE = t_bill-FKDAT

FOREIGN_AMOUNT = t_bill-NETWR

FOREIGN_CURRENCY = t_bill-WAERK

LOCAL_CURRENCY = 'USD'

IMPORTING

LOCAL_AMOUNT = v_bilamt.

*for netpr

CALL FUNCTION 'CONVERT_TO_LOCAL_CURRENCY'

EXPORTING

CLIENT = SY-MANDT

DATE = t_bill-FKDAT

FOREIGN_AMOUNT = t_bill-NETPR

FOREIGN_CURRENCY = t_bill-WAERK

LOCAL_CURRENCY = 'USD'

IMPORTING

LOCAL_AMOUNT = v_tp.

else.

v_bilamt = t_bill-netwr.

v_tp = t_bill-netpr.

endif.

points guaranteed

cheers

kaki

4 REPLIES 4
Read only

abdul_hakim
Active Contributor
0 Likes
657

Hi

Pass your currency in an itab then use the below code.

LOOP AT ITAB.

Call the FM.

ENDLOOP.

Read only

Former Member
0 Likes
657

YOu cannot reduce the number of times the FM is beign called. You can reduce the length of the code by writing a Perform for the function call.

perfrom Change_currency using t_bill-NETWR t_bill-waerk

changing v_bilamt.

perfrom Change_currency using t_bill-NETpr t_bill-waerk

changing v_tp.

Read only

Former Member
0 Likes
657
if t_bill-WAERK ne 'USD'.
* for JPY
if t_bill-WAERK eq 'JPY'.
t_bill-NETWR = t_bill-NETWR * 100.
endif.

*for netwr
perform convert_currency using t_bill-fkdat
                               t_bill-netwr
                               t_bill-waerk
                         changing v_bilamt.

*for netpr
perform convert_currency using t_bill-fkdat
                               t_bill-netpr
                               t_bill-waerk
                         changing v_tp.
else.
v_bilamt = t_bill-netwr.
v_tp = t_bill-netpr.
endif.
form convert_currency using fkdate type sy-datum
                            price type netpr
                            waerk type waerk
                       changing val type netpr.

CALL FUNCTION 'CONVERT_TO_LOCAL_CURRENCY'
EXPORTING
CLIENT = SY-MANDT
DATE = fkdate
FOREIGN_AMOUNT = price
FOREIGN_CURRENCY = WAERK
LOCAL_CURRENCY = 'USD'
IMPORTING
LOCAL_AMOUNT = val.
endform.

regards

vijay

Read only

Former Member
0 Likes
657

hi,

I think you can try using the FM Read_exchange_rate . This can be called only once to get the exchange rate for the currencies which can then be used to calculate the values of the two fields.

Regards,

Kalpana