Currency conversion using Routine with Unit (R_W_UNIT)
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
call function 'CONVERT_TO_LOCAL_CURRENCY'
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
* EXCHANGE_RATE =
local_amount = result
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
* if conversion not possible -> assign target values
result = hlp_value.
currency = source_fields-doc_currcy.
currency = source_fields-loc_currcy.
* RETURNCODE = 0.
Chandra Janardhansudhir Kunar replied
The issue is with the routine at the field and not at the start routine.
I realized that the Unit( Currency ) is not passed in the field routines along with result .
I do not know how it loops back to the field routine and adds a duplicate row when the Currency is not passed.
Appreciate your help .