Skip to Content
0

Sort different contexts (having multiple values), in ascending order, for the same queue.

Jul 06, 2017 at 11:05 AM

95

avatar image

Hello all,

I have a requirement where I need to sort one queue which contains multiple contexts and each context is having multiple values.

As per attached screenshot, I need to sort the output based on the value that is occurring before '+' symbol and publish the output in ascending order. My output should ideally look like follows:

15112371+98.83

15112371+0.43

.

.

.

15112371+

-Context Change-

15112372+98.84

15112372+0.50

.

.

.

15112372+

Looking forward to your kind inputs.

Best regards,

Aman

capture.jpg (56.2 kB)
10 |10000 characters needed characters left characters exceeded

@avinash.avi Could you please help here?

Thanks,

Aman

0

Hi Aman,

Didn't get a chance to open scn on Friday. Did you manage to solve this or still looking for the code?

Thanks,

Avinash B

0

Still looking for it buddy. Requesting kind help.

Thanks.

0
* Please Login or Register to Answer, Follow or Comment.

1 Answer

Best Answer
Avinash Bandela Jul 10, 2017 at 04:03 AM
1

Hi Aman,

Try following

Do a remove context --> sort --> UDF with all values in queue.

CODE:

String s1="";
String s2="";


try{


for(int i=0;i<input.length;i++)
{
		s1=input[i].substring(0,input[i].indexOf("+"));
		s2=input[i+1].substring(0,input[i+1].indexOf("+"));


	if (s1.equals(s2)) 
		{
						result.addValue(input[i]);
		}
		else
		{
						result.addValue(input[i]);
						result.addValue(ResultList.CC);
		}
}




}




catch(Exception e)
{


}


Thanks,

Avinash B


capture.jpg (15.9 kB)
Show 7 Share
10 |10000 characters needed characters left characters exceeded

Hello Avinash,

Thanks a lot for your inputs. Below is the output that I am getting. LHS is the old output and RHS is the new one. Though the values are getting sorted, the highlighted one is getting missed in the new output. Could you please suggest?

Thanks,

Aman

capture.jpg (92.3 kB)
0

Sorry My bad. Try this. It should work fine.

String s1="";
String s2="";


for(int i=0;i<input.length;i++)
{


	if(i!=input.length-1)
	{


		s1=input[i].substring(0,input[i].indexOf("+"));
		s2=input[i+1].substring(0,input[i+1].indexOf("+"));


					if (s1.equals(s2)) 
					{
								result.addValue(input[i]);
					}
					else
					{
								result.addValue(input[i]);
								result.addValue(ResultList.CC);
					}
	}
	else
	{
				result.addValue(input[i]);
	}
}



Thanks,

Avinash B

1

Hello @avinash.avi,

Thanks a lot for the update. The logic and code that you have provided are working perfectly fine for below input (LHS) and I am getting RHS as output. This is perfect.

However, this code is not working for the following input. Could you please suggest the changes that needs to be done to this code in order to make it work similar to the above?

Best regards,

Aman

capture.jpg (45.7 kB)
capture.jpg (31.9 kB)
0

Hello Avinash,

Here is the output that I am expecting here:

15112371+CU+

15112371+CR+

15112371+ZN+

15112371+TI+

15112371+MN+0.03

15112371+FE+0.20

15112371+SI+0.43

15112371+MG+0.46

15112371+AL+98.83

- Context Change-

15112372+CU+

15112372+ZN+

15112372+TI+

15112372+CR+0.01

15112372+MN+0.03

15112372+FE+0.19

15112372+MG+0.38

15112372+SI+0.50

15112372+AL+98.84

0

Hello @avinash.avi,,

I just realised, even if I do not get a ContextChange, that will serve the purpose for me. Requesting you to kindly suggest on the logic. Below is the input (screenshot) that I am getting and below that is the desired output.

15112371+CU+

15112371+CR+

15112371+ZN+

15112371+TI+

15112371+MN+0.03

15112371+FE+0.20

15112371+SI+0.43

15112371+MG+0.46

15112371+AL+98.83

15112372+CU+

15112372+ZN+

15112372+TI+

15112372+CR+0.01

15112372+MN+0.03

15112372+FE+0.19

15112372+MG+0.38

15112372+SI+0.50

15112372+AL+98.84

Thanks in advance.

-Aman

capture.jpg (31.9 kB)
0

Hello Avinash,

I managed to get the desired output by tweaking the mapping logic and using standard functions. Also, used a substring UDF.

Thanks a ton for your help.

Best regards,

Aman

0

Good to hear Bro..!
Cheers :)

0