cancel
Showing results for 
Search instead for 
Did you mean: 

Using SORT function in mapping

Former Member
0 Kudos

Hi,

I am having trouble getting my head around using the SORT function.

My interface is IDOC to File, The IDOC has a repeating segment (PAYLOAD) that can be of 3 types, either type A, B or C (this is set using a "TYPE" field).

In my file structure I have a repeating "ROW" element which has all of the fields for each row.

I want to group all the Type A data together, the Type B together and the Type C.

I have tried the following mapping on the "ROW" element but it doesn't seem to work:

"TYPE"--"sort"Split By Value (Value Change)--collapseContext--"ROW"

for each of the mappings under ROW I just have fields copied directly.

I think I am doing something wrong.

Thanks.

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Hi,

Can you give the sample Source and Target Structure?

Regards,

Aravind

Former Member
0 Kudos

Hi,

My source is a simple Custom IDOC:

<IDOC>

<HEADER>

......

</HEADER>

<PAYCARD>

< TYPE>A</TYPE>

< NAME>Gareth</NAME>

< ADDRESS>IRELAND</ADDRESS>

</PAYCARD>

<PAYCARD>

< TYPE>B</TYPE>

< NAME>Mary</NAME>

< ADDRESS>London</ADDRESS>

</PAYCARD>

<PAYCARD>

< TYPE>A</TYPE>

< NAME>John</NAME>

< ADDRESS>Dublin</ADDRESS>

</PAYCARD>

</IDOC>

My target is a simple DT which is going to be converted to Flat File in the CC.

MT_FILE

<ROW 0...Unbounded>

<NAME>

<ADDRESS>

For each PAYCARD segment in the source IDOC there should be a new ROW in the Target. I want to group all the "TYPE" segments together.

Gareth

Former Member
0 Kudos

Hi Gareth,

You can achieve this by using SortByKey Node function.

Follow the mapping.

 

<PAYCARD> -> <ROW>

<Type> ->removeContext -> (first input) SortByKey -> 
                                  (output of SortByKey) ->SplitByValue [Each Value] -> <Name>
<Name> ->removeContext ->(second input) SortByKey ->


Similarly to sort Address:


<Type>->removeContext->(first input)SortByKey -> 
                                  (output of SortByKey)->SplitByValue [Each Value] -> <Address>
<Address>->removeContext->(second input) SortByKey ->


I think this will sort as per your requirement.

Regards,

Aravind

Former Member
0 Kudos

Hi,

You could make this mapping



	TYPE --- +----------------+     +----------------+
		 |                |     |                |
		 | Concat         | --- | mySortFunction | --- NAME
		 |                |     |                |
	NAME --- +----------------+     +----------------+
	
	TYPE --- +----------------+     +----------------+
		 |                |     |                |
		 | Concat         | --- | mySortFunction | --- ADDR
		 |                |     |                |
	ADDR --- +----------------+     +----------------+

Where source code of mySortFunction is like this:


public void mySortFunction(String[] inputValues,ResultList result,Container container){
 
 
	for(int i=0;i<inputValues.length;i++)
		if(inputValues<i>.substring(0,1).equals("A"))
			result.addValue(inputValues<i>.substring(1, inputValues<i>.length-1);			
 
	for(int i=0;i<inputValues.length;i++)
		if(inputValues<i>.substring(0,1).equals("B"))
			result.addValue(inputValues<i>.substring(1, inputValues<i>.length-1);

	for(int i=0;i<inputValues.length;i++)
		if(inputValues<i>.substring(0,1).equals("C"))
			result.addValue(inputValues<i>.substring(1, inputValues<i>.length-1);

}

It is very simple. You concat TYPE whit your data, and then you sort all queue, so you have a new sort queue data. You must only then put out data.

Former Member
0 Kudos

Hi,

Map as follows:

"TYPE"--"removeContext"--"sort"Split By Value (Value Change)--collapseContext--"ROW"

"TYPE"--removeContext-sort--(to first input of sortByKey)

"Name"--removeContext--


(to second input of sortByKey)

After sortByKey, use formatByExample node function. The first input of formatByExample is as follows:

"TYPE"--"removeContext"--"sort"Split By Value (Value Change)---- 1St input of formatByExample

The 2nd input of formatByExample is as follows: Output of sortByKey

Map the output of formatByExample to NAME in the target side.

Follow exactly the same mapping for the ADDRESS field in the target side.

HOPE THIS HELPS YOU BUDDY!!!! I HAD A SIMILAR REQUIREMENT IN ONE OF MY INTERFACES AND I RESOLVED IT THIS WAY.

THANKS

BISWAJIT

Former Member
0 Kudos

Thanks for your suggestions everyone.

I will try some of them out and let you know if I get this sorted.

Thanks

Answers (5)

Answers (5)

Former Member
0 Kudos

Hi,

I resolved a problem like yours using a java UDF wich receives a queue value and return other one with sort values. The only problem is you need use this in all tags of the sort rows.

Good look.

Former Member
0 Kudos

Hi,

I attach a sample code... you must concatenate your key fields (Type for example) with node element to sort, and remove them before use the result.


public void mySortFunction(String[] inputValues,ResultList result,Container container){

	String[] outputValues = new String[inputValues.length];

	for(int i=0;i<inputValues.length;i++) {
		//place here your sort code
	}

	//return a result list with sort inputs

	for(int i=0;i<outputValues.length;i++)
		result.addValue(outputValue<i>);

}

Let me know if you need more information.

Former Member
0 Kudos

Hi,

Kindly do the following change:

"TYPE"--"removeContext"--"sort"Split By Value (Value Change)--collapseContext--"ROW"

That is you just need to add removeContext after TYPE to bring all the TYPE values in a single context, else sort will be of no use. After that, you can apply sort as sort is only useful when all the values are in a single context.

After that, whatever you have done is correct.

Hope it helps you!!!!

Thanks

Biswajit

stefan_grube
Active Contributor
0 Kudos

> for each of the mappings under ROW I just have fields copied directly.

sort has no influence on subnodes. if you really need to sort the XML document, you should use XSLT.

But first you should for an alternative to do your mapping without sorting.

Former Member
0 Kudos

>

> > for each of the mappings under ROW I just have fields copied directly.

>

> sort has no influence on subnodes. if you really need to sort the XML document, you should use XSLT.

> But first you should for an alternative to do your mapping without sorting.

Quote!

Former Member
0 Kudos

So is there no way for me to Group all the Type A Rows, Type B Rows and Type C Rows together in the file without using XSLT?

stefan_grube
Active Contributor
0 Kudos

When you group it for three ifferent values, then there is no need to sort it.

It is also possible to sort with graphical mapping tool. But the mapping will become complex.

Former Member
0 Kudos

check this log for getting understanding.

/people/stefan.grube/blog/2005/12/29/new-functions-in-the-graphical-mapping-tool-xi-30-sp13

chirag

markangelo_dihiansan
Active Contributor
0 Kudos

Hello,

"TYPE"--"sort"Split By Value (Value Change)--collapseContext--"ROW"

I think you should put removeContext just after TYPE, so that you can sort it.

Hope this helps,

Mark