cancel
Showing results for 
Search instead for 
Did you mean: 

Map fields from different context in source to single header in target

Former Member
0 Kudos

Hi All,

I am currently working on the following requirement for a mapping scenario, hope you can help me to resolve the issue and suggest the best alternative.

I am providing a test XML without mentioning the actual one to simplify the problem statement. One test XML could be as follows:

<Package>

<APackage>

<Parts>

<Part>

<a1>111</a1>

<b1>123</b1>

</Part>

<Part>

<a1>222</a1>

<b1>789</b1>

</Part>

</Parts>

<Docs>

<Doc>

<a1>111</a1>

<d1>xyz</d1>

<e1>131</e1>

</Doc>

</Docs>

</APackage>

</Package>

As mentioned above Parts and Docs are at the same level with Part and Doc as 0..Unbounded. Now fields 'a1' and 'b1' have to be mapped to fields 'p1' and 'q1' of the target structure Material (0..Unbounded). But if value of field 'a1' for a Part matches with the value of field 'a1' for a Doc (111 in this case), then fields 'd1' and 'e1' in that Doc have to be mapped to the same Material node which was mapped to Part. Hence the target structure would look sth like:

<CPackage>

<SCPackage>

<Materials>

<Material>

<p1>111</p1>

<q1>123</q1>

<r1> xyz</r1>

<s1>131</s1>

<Material>

<Material>

<p1>222</p1>

<q1>789</q1>

<Material>

<Materials>

<SCPackage>

<CPackage>

Hope my query is clear and I would really appreciate if somebody can give some pointers on how to proceed. Scenario is for PI 7.0.

Best Regards,

Pratik

Edited by: pratik_du on Mar 29, 2010 9:59 AM

Edited by: pratik_du on Mar 29, 2010 10:00 AM

Accepted Solutions (0)

Answers (3)

Answers (3)

Former Member
0 Kudos

Hi,

Now fields 'a1' and 'b1' have to be mapped to fields 'p1' and 'q1' of the target structure Material (0..Unbounded). But if value of field 'a1' for a Part matches with the value of field 'a1' for a Doc (111 in this case), then fields 'd1' and 'e1' in that Doc have to be mapped to the same Material node which was mapped to Part. Hence the target structure would look sth like:

Can u please specify the requirements clearly..

U can solve it also by using a simple UDF.. or using the inbuilt functions also.

Let us know...

1. But if value of field 'a1' for a Part matches with the value of field 'a1' for a Doc (111 in this case), then fields 'd1' and 'e1' in that Doc have to be mapped to the same Material node which was mapped to Part

Is that means occurence of Part and Doc in source is equal(number of Parts = no. of Docs).. or only one Doc for all parts???

2.then fields 'd1' and 'e1' in that Doc have to be mapped to the same Material node which was mapped to Part.

If equal then which element in target u r mapping to .. and how..

Please specify the requiremnts clearly.. so that any1 here can come up with answer...

Babu

Former Member
0 Kudos

Hi,

I tried to explain it clearly but may be it wasn't clear. Part and Doc don't have a 1:1 relationship. Some Package may send Doc information also. And the key to map Part to Doc is field 'a1' i.e. if Part.a1 = Doc.a1 the Doc is a document for that Part and some fields in this Doc have to be mapped to the target Material Node which was created for that part. I have given a sample output message in my initial post which makes it more clear.

What I am unable to achieve as of now is to move the fields under Doc node to the correct Material Node. There can be n Part nodes which will be mapped to n Material nodes, and then there can be some Doc nodes. Only those Doc nodes where Doc.a1=Part.a1 have to be mapped to the Material Node which was created for that specific part with value in a1 same as Doc.a1.

I will appreciate some pointers, I tried doing as per suggestions but could not achieve desired results as of now.

Best Regards,

Pratik

Edited by: pratik_du on Mar 29, 2010 6:51 PM

Former Member
0 Kudos

Hi Pratik

Try this.

Part----


>Material

Part/a1----


>Material/p1

Part/q1----


>Material/q1

For all elements(a1,d1,e1) below change the context to Parts

Part/a1 -


>

Docs/a1--- equals-->

Docs/d1----


> ifwithoutelse --->SplitByValue -


>Material/r1

Part/a1 -


>

Docs/a1--- equals-->

Docs/e1----


> ifwithoutelse --->SplitByValue -


>Material/s1

Former Member
0 Kudos

Hi Luis,

Thanks for your reply. Just one thing, in your reply you mentioned to have (a1,d1,e1) in context Parts but that won't be possible, as these could be changed to either context Docs or APackage and not Parts as its not present in that hierarchy. Please refer the structure again. Let me know if I miss something in what you suggested.

Best Regards,

Pratik

justin_santhanam
Active Contributor
0 Kudos

Pratik,

Can you try the below logic and let me know if it works? I tested it and working fine.

I'm on assumption that if there 3 parts and there will be 3 docs as well



Part --> Material

a1 --> p1
b1 -->q1

a1(part)
           --> equals --> If without else --> r1
a1(Doc) 
(in the above condition THEN --> pass d1(Doc))

a1(part)
           --> equals --> If without else --> s1
a1(Doc) 
(in the above condition  THEN --> pass e1(Doc))

If you have hard time in understanding the above logic, then let me know. Don't change any context's. It's working fine.

If you think my assumption is wrong, then let me know.

~Raj.

Former Member
0 Kudos

Hi. Pratik

Yes you rigth . I made a mistake.

Change the context of Part1/a1 and Part1/b1 to Parts

Change the context of Docs/a1 and Docs/d1 to Package

Change the context of Docs/a1 and Docs/e1 to Package

it works!.

Former Member
0 Kudos

Hi,

This time it's almost clear.

What I am unable to achieve as of now is to move the fields under Doc node to the correct Material Node. There can be n Part nodes which will be mapped to n Material nodes, and then there can be some Doc nodes. Only those Doc nodes where Doc.a1=Part.a1 have to be mapped to the Material Node which was created for that specific part with value in a1 same as Doc.a1.

I will appreciate some pointers, I tried doing as per suggestions but could not achieve desired results as of now.

Is that means for some Part u will have DOC some u will not have??

If yes then the source is like

Part

Doc

Part //no doc here

Part

Doc

Am i right???

Babu

Former Member
0 Kudos

Hi ,

@Babu:Yes you are correct, for some Part there might be a Doc for others not. If there is a Doc for a Part then Part is fully mapped to Material and some fields of Doc are also mapped to the same Material Node, else if its only a Part and no Doc is there, then its direct mapping between Part and Material only and no attributes of Doc are added to Material Node.

@Luis: I tried with the solution suggested by you but it isn't working. May be that some of your assumptions are not correct. Please read by reply to Babu above for better clarity.

@Raj: Your assumption is incorrect. Part and Doc are not 1:1. There can be Parts for which no Doc is there. Again refer my reply above for Babu which would make it more clear.

Thanks all for your time and hope I get some other alternatives. Meanwhile I am trying to resolve it in parallel.

Best Regards,

Pratik

Edited by: pratik_du on Mar 30, 2010 7:59 AM

Former Member
0 Kudos

Hi,

Ok fine.. it's simple.

Map like this.

Part(0..unbounded)<------>Material(0..unbounded)

a1----


p1

a2----


q1

************************a1(DOC'sa1)---then*************************a1(Part)*******************a1(Doc's)---then**************

*******************************************************************EqualsS(Textfunction--


ifWithoutelse--


d1(Material)

DocExists-If*********************************(outputofif)----


(a1orConstant)*****************************************************************

*************************Constant----


else**

Lemme explain words.

1.Check if DOC is present.(Using Exists)

2.If present then get the Doc's a1(or what ever u want to map from Doc) else the Constant

3.Now compaere this Doc's a1 with Part's a1.

4.If equals then-- true...... map it to target

5.else don't map.

Do this for all the elements u map from the Doc to to Material.. using the same logic but changing the fields.

Note: Please make sure that the other fields u r mapping from the Doc to Matreial.... these firlds in material should be having occurence(0..1). If not it will give a problem.

Still any problm.. pl do post

Babu

Edited by: hlbabu123 on Mar 30, 2010 11:50 AM

Edited by: hlbabu123 on Mar 30, 2010 11:59 AM

stefan_grube
Active Contributor
0 Kudos

> Part and Doc are not 1:1. There can be Parts for which no Doc is there. Again refer my reply above for Babu which would make it more clear.

It is not possible to solve this with standard functions. You have to create UDF which goes through the contexts, compares the values and creates empty contexts.

Former Member
0 Kudos

Hi All,

The problem is resolved. Thanks Stefan for your suggestion. I tried with UDF and it has worked. The approach is as follows:

a1(Part)-------removeContext -


>

a1(Doc)-----removeContext---->

e1(Doc)----removeContext----->

-


>UDF (with above 3 inputs)--


>SplitByValue (Each Value)--


>r1 (Material)

UDF is defined as follows (empty values added for those Parts which don't have corresponding materials.

boolean flag =false;

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

flag =false;

for (int j= 0; j<aDoc.length;j++){

if (aPart<i>.equals (aDoc[j])){

flag =true;

result.addValue(eDoc[j]);

break;

}

}

if (!flag){

result.addValue(" ");

}

}

Best Regards,

Pratik

stefan_grube
Active Contributor
0 Kudos

It is not only the only solution to use an UDF, it is also very easy to handle it that way

> if (!flag){

> result.addValue(" ");

> }

You can use addSuppress() when you want to have no target element here.

Otherwise you have an empty target element.

Former Member
0 Kudos

Hi Stefan,

After posting my reply, I already realized and added the addSuppress() method instead of empty string. Thanks anyways for pointing it out.

Best Regards,

Pratik

Former Member
0 Kudos

Hi,

basically you need to put below condition in your mapping for each field e.g. p1, q1, r1 & s1

Use ifWithElse, Constant & equalS function in below mapping.

If a1 of Part equalS a1 of Doc then map a1 of Part to p1.
If a1 of Part equalS a1 of Doc then map b1 of Part to q1.
If a1 of Part equalS a1 of Doc then map d1 of Doc to r1.
If a1 of Part equalS a1 of Doc then map e1 of Doc to s1.

You may have to adjust the context, so just play around to get exact results.

Regards,

Sarvesh

Former Member
0 Kudos

Use the nodal functions

REMOVE CONTEXT

USE ONEAS MANY

Etc accoring to ur requirment

Regards,

Jude