cancel
Showing results for 
Search instead for 
Did you mean: 

Output the values in reverse sequence

Former Member
0 Kudos

Hello All,

In mapping i need to output the source values in a reverse order and mapped it to the Target filed.

For example:

Source Structure:

<MT_Source>

<Detail>

<Field1>200</Field1>

</Detail>

<Detail>

<Field1>100</Field1>

</Detail>

<Detail>

<Field1>300</Field1>

</Detail>

<like this I will be having n number of Detail>

</MT_Source>

Target Structure:

<MT_Target>

<Details>

<Field1>300</Field1>

<Field1>200</Field1>

<Field1>100</Field1>

</Details>

</MT_Target>

Regrads

Vasant

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Hi,

You can achieve this using 2 lines of code....

UDF:

input will be a

Exceution type: all values of a context

for(int i=a.length-1;i>=0;i--)
{
result.addValue(a[i]);
}

Your mapping will be:

Input---RemoveContext--Sort---UDF--Output


Thanks

Amit Srivastava

Former Member
0 Kudos

just to add to Amit's reply above, everything seems fine except in mapping step:

Input---RemoveContext--Sort---UDF--Output

Here Sort is not needed. So it should be like below:

Input field - RemoveContext - UDF - Output field

or you can try:

Input field Field1(right click context change to MT_Source) - UDF - Output field Field1

Former Member
0 Kudos

Thanks Rajeev and Ankit for correcting me.....there is a bit of contrast between subject and example shown above and may be becoz of that i have added sort anywayz i guess Vasant can only clarify what actually he wants...

@Vasant

yes indeed sort is not required if u want to output the source values in reverse sequence...UDF and RC will help u...

Thanks

Amit Srivastava

Answers (1)

Answers (1)

Former Member
0 Kudos

Hi Vasant,

I am sure you have taken Field1 inside target structure occurrence as 0..unbound. Secondly, if you need fields in reverse order Amit's UDF will do that, remove sort before it.

But in your example for target structure you shown values in decreasing order on target not in reverse order. If you need values in decreasing order. No need to use UDF, just use Sort function and do descending sort.

Former Member
0 Kudos

Hello All,

Sorry for misleading output structure. I want the output in reverse sequence and i have obtained it using the UDF.

Thanks for the help.

Regards

Vasant