Skip to Content
0
Dec 29, 2014 at 02:02 AM

Currency conversion using Routine with Unit (R_W_UNIT)

1063 Views

Dear Guru's,

I have tried to use this Rule type to derive local currency from document currency.

I have a routine to check the availability of Local currency and document currency. If both are different then convert to local currency using exchange rate ( from source fields ).

Below are more details about it. similar to this there are few other fields having the conversion routine.

I am using FN - 'CONVERT_TO_LOCAL_CURRENCY'

When when i load the data to the info cube i find, duplicate records in it , as below ( test data ).

One record with local currency as blank and the other with local currency and corresponding key figure updated.

Please help to correct, if there is any mistake in using the rule type.

Routine is coded as below:

.

data: lc_rate_dec type p decimals 5.

lc_rate_dec = source_fields-exchg_rate.

if source_fields-doc_currcy = source_fields-loc_currcy

* no conversion necessary -> Main case 1

and not ( source_fields-doc_currcy is initial

or source_fields-loc_currcy is initial ) .

result = hlp_value.

elseif not ( source_fields-doc_currcy is initial

or source_fields-loc_currcy is initial or

source_fields-trans_date is initial ) .

*conversion necessary with SOURCE_FIELDS-TRANS_DATE -> Normally not

*possible

call function 'CONVERT_TO_LOCAL_CURRENCY'

exporting

date = source_fields-trans_date

foreign_amount = hlp_value

foreign_currency = source_fields-doc_currcy

local_currency = source_fields-loc_currcy

rate = lc_rate_dec

importing

* EXCHANGE_RATE =

local_amount = result

exceptions

no_rate_found = 1

overflow = 2

no_factors_found = 3

no_spread_found = 4

derived_2_times = 5.

if sy-subrc ne 0.

*message a802 with SOURCE_FIELDS-TRANS_DATESOURCE_FIELDS-DOC_CURRCY

*SOURCE_FIELDS-LOC_CURRCY

* sy-subrc.

endif.

else.

* if conversion not possible -> assign target values

result = hlp_value.

currency = source_fields-doc_currcy.

endif.

currency = source_fields-loc_currcy.

* RETURNCODE = 0.

Attachments

Rule type 1.png (50.9 kB)
Rule type 2.png (32.4 kB)