on 12-29-2014 2:02 AM
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.
Dear All,
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 .
Regards,
Sudhir.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
A field routine cannot normally create duplicate records. Please compare with the source data - is it really doubling the records?
Also, every time you assign a value to the RESULT and CURRENCY fields, please add the following two lines
RETURNCODE = 0.
RETURN.
Without these two lines, the logic is bound to be wrong.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Suhas Karnik,
Thanks for your reply.
1. Returncode = 0 is throwing a syntax error.
I have tried with below exception:
raise exception type cx_rsrout_skip_val.
Endif.
Else.
raise exception type cx_rsrout_skip_val.
Endif.
but does not help.
2. is it really doubling the records?
Yes the added records are almost double the transferred records because of this.
Source has a single record:
Thanks & regards,
Sudhir.
Ok, ignore the returncode, that is a mistake from my end. The RETURN statement should be there, however.
No need to raise the exceptions, they will cause the code to throw runtime errors unnecessarily.
Run the DTP in debugging mode (filter for only this record) to see how the record is getting doubled. Normally field routines do not increase number of records, but if you have a Start/End routine it's possible for record counts to increase.
Hi Suhas Karnik,
Thank you again.
Yes as you mentioned, it it not the Field routine.
It is also not in the Start routine.
I have a very small piece of code in start routine :
select * from /bic/pyrt_xxx into table i_purorg_xx
where objvers = 'A'.
It is in the standard code itself. i find some table like _YT_SC_1 & _GT_1_1 getting filled with duplicate records. Because of which field routine is looped twice.
Is there any thing i missed in my 1st screen shot ( Rule details ). Or should i use Rule Type routine instead of Rule with routine.
Thanks & regards,
Sudhir.
Yes, that is the correct log. As per the log, 2 records were extracted from the source DSO. So the records are definitely not doubling in the field or start routine.
In the source DSO, there are two records for the selection criteria, so if the selection criteria are correct then the transformation is working fine.
That's a valid point. At least for the example you have given (the one for which you ran the debug DTP) there are two records in the source. For this example the records in target = records in source.
It might be that some other set of records is getting doubled. There might be some code in the Start/End routine that appends to the Source/Result package. To test that you'll need to identify an example record that is getting doubled, by comparing the source and target data.
User | Count |
---|---|
87 | |
10 | |
10 | |
10 | |
7 | |
6 | |
6 | |
5 | |
5 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.