cancel
Showing results for 
Search instead for 
Did you mean: 

sort according to another field order

Former Member
0 Kudos

say there are 2 input and 2 output fields

The first input field is mapped to the first output field , after grouping similar values together

e.g:

input field1 output field1

a a

d a

e d

c d

d c

e e

a e

Now the 2 nd input field has to be mapped to 2nd output field according to the order in which the 1st field has been mapped.

We can not use sortByKey here as the first field is not mapped in lexographical nor numerical order.

How then can we map the 2nd field according to order of first?

Thanks in advance

Pratichi

Accepted Solutions (0)

Answers (5)

Answers (5)

Former Member
0 Kudos

Java Collection Framework might be helpful in your case.

Say, the second input (input2) should be ordered first input (input1). Create a Java Map. This Map should have input1 as key and String array as value. The string array will have output1, input2 and output2.

Get the outputs and place them in their respective placeholders. Finally sort the map on the key.

NB: Make appropriate modification if the above scenario is not an exact match to your requirement.

Hope that helps.

Regards,

Sumant

Former Member
0 Kudos

Pratichi,

can you show me the test case output for second filed also as per the first field

Madhav

Former Member
0 Kudos

Hi Pratichi,

The UDF that you are writting to group similar values together for the input field1.

try chaging that UDF with two arguments

1. inputField1

2. inputField2

use the concept of Edit Java section(Declaring Global variable .To Know more about it refer

http://wiki.sdn.sap.com/wiki/display/stage/UsingEditJavaSectioninMessageMapping)

Declare a Global variable in the Global Variable section as


String[] format = new String[30];

while you are gouping inputField1 ,group inputField2 also and store in the global variable format.

Write one more UDF to read values from the global variable and map it to OutputFiled2.

(you can use same java code as you normally use to store and read values from the string array).

Thanks and Regards,

Kubra fatima.

Former Member
0 Kudos

Hi Pratichi,

Ok.But 1 confusion.

Here, For Input field 1 ,are you using 'Sort' function?

Regards,

Supriya.

Former Member
0 Kudos

Hi

No i am not using sort function. I have written a udf for sorting the first field.

Pratichi

Former Member
0 Kudos

Hi

Anyone there with a solution to this?

former_member187339
Active Contributor
0 Kudos

Hi Pratichi,

Use sortbykey and then formatbyexmple (inorder to get the structure in your format). The second input for formatbyexample will be the same mapig that you have used for field1 (where output you have showed as "a"

Regards

Suraj

Former Member
0 Kudos

Hi Pratichi,

Can you pls tell, what logic have you applied for mapping Output field1?

Regards,

Supriya.

Former Member
0 Kudos

Hi Supriya,

The logic used is that , we group the same values of the field1 into separate context.

for example

if input is like below:

a

b

b

c

e

e

a

b

output will be

a

a

ContextChange

b

b

b

ContextChange

c

ContextChange

e

e

ContextChange

Thanks

Pratichi

.