cancel
Showing results for 
Search instead for 
Did you mean: 

GraphicalMapping: Split logic using user defined function

Former Member
0 Kudos

Hi all

I am doing a mapping in which the request xml comes this way

<header>                        ----- occurance 1
...............
</header>
<detail>                        ------- occurance 0 to unbounded
<F123ABC>1000</F123ABC>      ------- occurance 0 to 1
<F456PQR>2000</F456PQR>      ------- occurance 0 to 1
<G200XYZ></G200XYZ>      ------- occurance 0 to 1
<G500PPP>12</G500PPP>      ------- occurance 0 to 1
.................
</detail>    
<trailer>
..............
</trailer>

Now my target structure is like this

<zheader>                        ----- occurance 1
...............
</zheader>
<zdetail>                        ------- occurance 0 to unbounded
<record type>...............</<record type>
<Format>F</Format> ---if the tag <F123ABC> is not NULL then the data of format sortation and machine will be F,123 and ABC respectively and then whatever the between the TAG <F123ABC></F123ABC> will be fed in the *<quantity>*
<sortation>123<sortation>
<machine>ABC<machine>
<quantity>1000</quantity>
.................
</zdetail>    
<zdetail>                        ------- occurance 0 to unbounded
<record type>...............</<record type>
<Format>F</Format> ---if the tag <F456PQR> is not NULL then the data of format, sortation, and machine will be F,456 and PQR respectively and then whatever the between the TAG <F456PQR>2000</F456PQR>  will be fed in the *<quantity>*
<sortation>456<sortation>
<machine>PQR<machine>
<quantity>2000</quantity>
.................
</zdetail>    
<ztrailer>
..............
</ztrailer>

I tried this code in the UDF but it did not work

public void ud_splitDetail(String[] F123ABC,String[] F456PQR,String[] G200XYZ,String[] G500PPP,Detail,ResultList result,Container
   //write your code here
	int lenDetail=Detail.length;
	for(int i=0;i<lenDetail;i++)
	{
	//int len1=A.length;
	if(F123ABC<i>!=""){
	result.addValue("F");
	result.addContextChange();}

	if(F456PQR<i>!=""){
	result.addValue("F");
	result.addContextChange();
	}

	if(G200XYZ<i>!=""){
	result.addValue("F");
	result.addContextChange();
	}

	if(G500PPP<i>!=""){
	result.addValue("F");
	result.addContextChange();
	}
	
	else
	result.addValue("");
	result.addContextChange();
	}

The above code is to take F for format and the same way it is for sortation, machine and quantity

But this code is not working properly, it gives a lots of F and other values. Could anyone give me some idea of how to code for the desired output

Your help is really appreciable

Thanks

Naina

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

For this kind of mapping first you have to know how many tags will be there under <Details> node.

So as per your given example there are 4 tags and you wnat to map some constant values to target fields if the source fields in not empty.

So to achieve this you have to simply duplicate the target node <zdetail> 3 times (right click and say duplicate subtree). So finally you will have total 4 (1 original + 3 duplicate) <zdetail> target nodes.

Now do the mapping like this on each node...

if <F123ABC> exists then map a empty constant to <zdetail>., this will allow the mapping to happen only if tag <F123ABC> is not empty otherwise mapping will not happen for this node.

And also do the mapping for below fields under <zdetail> node according to your source node e.g.

map a constant 'F' to <Format>

map a constant '123' to <sortation>

map a constant 'ABC' to <machine>

map <F123ABC>100</F123ABC> to <quantity>

Similarly apply the above mapping logic for <F456PQR>, <G200XYZ> & <G500PPP> tags on remaining 3 <zdetail> nodes.

Former Member
0 Kudos

Thnks Sarvesh

First I need to duplicate <zdetail> nodes depending upon how many times its subnodes such as <F123ABC>,<F456PQR>, <G200XYZ> & <G500PPP> are not empty.

So in this case <zdetail> will be duplicated 3 times

1. For <F123ABC> , <zdetail> will be duplicated first because it is not NULL then

2. For <F456PQR>, <zdetail> will be duplicated secondbecause it is not NULL then

3. For <G500PPP>, <zdetail> will be duplicated third albecause it is also not NULL

but for it would not be duplicated.

<detail>                        ------- occurance 0 to unbounded
<F123ABC>1000</F123ABC>      ------- occurance 0 to 1
2000</F456PQR>      ------- occurance 0 to 1
<G200XYZ> </G200XYZ>      ------- occurance 0 to 1
<G500PPP>12</G500PPP>      ------- occurance 0 to 1
.................
</detail>

So first of all i have to map source <detail to target <zdetail> by writing a UDF in such a way that it is duplicated this many times. Could you please give exact source code for this.

I am online please reply

Thanks

Naina

Former Member
0 Kudos

Basically what I understood from your problem is, when ever your subnode have some value then you need to map that value to quantity field and rest of the fields at target side will be mapped with some constant values (based on the name of your source subnode).

Since you want to map the constant values of subnode therefore I need to know how many subnodes you have created under <detail> node.

In other words Let me know the exact number of subnodes that you have created under <detail> node at source side.

Also confirm what I explained above is correct?

Former Member
0 Kudos

Hi Sarvesh

You are right

when ever your subnode have some value then you need to map that value to quantity field and rest of the fields at target side will be mapped with some constant values (based on the name of your source subnode).

I have 4 subnodes under detail. I need these UDFs

1. To duplicate <detail> as many times its subnodes has some values for e.g. if on the first occurance of <Detail>, 2 of its subnodes have value then it will make two <zdetail> on the target side.

Also <detail> is 0 to unbounded so on the second occurance some other subnodes can be NOT NULL.

<zdetail>
<format>F</format>
<sortation>123</sortation>
...................
..................
</zdetail>
<zdetail>
<format>F</format>
<sortation>456</sortation>
...................
..................
</zdetail>

2. to feed data into the Format, Sortation machine and quantity fields.

I hope i gave ur answer

Regards

Naina

Former Member
0 Kudos

First of all you don't need any UDF for your requirement. Now follow below steps exactly as said...

Step1. At traget structure Right click on <zdetail> and select "Duplicate Subtree". Do this 3 times.

After doing this you will see there are total 4 <zdetail> nodes at target side.

Step2. Now we will do the mapping of first <zdetail> parent node as explained below...

If (WithoutElse) <F123ABC> is not Empty then map a Empty constant to <zdetail>. this will create the <zdetail> parent node only if tag <F123ABC> is not empty otherwise <zdetail> will not be created.

Now do the mapping of subnodes which are under <zdetail> node e.g.

map a constant 'F' to <Format>

map a constant '123' to <sortation>

map a constant 'ABC' to <machine>

map <F123ABC>100</F123ABC> to <quantity>

Step3. Follow step2 and do the mapping for <F456PQR>, <G200XYZ> & <G500PPP> with remaining 3 <zdetail> nodes in same manner.

Step4. Save & activate your mapping.

Former Member
0 Kudos

Sarvesh

Rather then duplicating the <zdetail> on target, can't I write a piece of code in a UDF to generate zdetail

Thnks

Naina

Former Member
0 Kudos

Sarvesh

There is one more issue....the source and target structure is like this

SOURCE

<detail>                        ------- occurance 0 to unbounded
<countryName>India</countryName>
<F123ABC>1000</F123ABC>      ------- occurance 0 to 1
<F456PQR></F456PQR>      ------- occurance 0 to 1
<G200XYZ> </G200XYZ>      ------- occurance 0 to 1
<G500PPP>12</G500PPP>      ------- occurance 0 to 1
.................
</detail>
<detail>                        ------- occurance 0 to unbounded
<countryName>China</countryName>
<F123ABC></F123ABC>      ------- occurance 0 to 1
<F456PQR>2000</F456PQR>      ------- occurance 0 to 1
<G200XYZ>1</G200XYZ>      ------- occurance 0 to 1
<G500PPP></G500PPP>      ------- occurance 0 to 1
.................
</detail>

TARGET

<zdetail>
<countryName>India</countryName>
<format>F</format>
<sortation>123</sortation>
...................
..................
</zdetail>
<zdetail>
<countryName>India</countryName>
<format>G</format>
<sortation>500</sortation>
...................
..................
</zdetail>
<zdetail>
<countryName>China</countryName>
<format>F</format>
<sortation>456<sortation>
...................
..................
</zdetail>
<zdetail>
<countryName>China</countryName>
<format>G</format>
<sortation>200</sortation>
...................
..................
</zdetail>

So my question is how to make multiple entries of node <countryName> because for first occurance of <detail> it will be INDIA and it will remain india till we are duplicating the first occurance of <detail>. Then it will be China for next occurance of detail till it is duplicated.

Please reply at earliest...i have to finish it today only

Thanks

Naina

Former Member
0 Kudos

Can you send me the screen shot of your actual mapping (see my visiting card) . OR upload it on some site and provde the link here. I want to see the actual structure and field names.

Former Member
0 Kudos

Sarvesh

Please check ur mail ID that u have included in ur business card

have mailed u

Answers (1)

Answers (1)

Former Member
0 Kudos

thnks sarvesh for ur help

I did the mapping correctly now