cancel
Showing results for 
Search instead for 
Did you mean: 

Mapping issue

Former Member
0 Kudos

Hello people,

Ive a mapping issue. This is how the situation is

Input file looks like this with occurrence <b>0..4</b>

<b>OrganisationFormattedName</b>

Output file looks like this:

<b>CompanyName1

CompanyName2</b>

The value of the first OrganisationFormattedName has to be filled in CompanyName1 and the second value of OrganisationFormattedName in CompanyName2.

Can anyone help me to the right direction?

Regards,

Kamran

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Hi,

you need to use constant function "copy value"

you need to map like

OrganisationFormattedName -><b>[copy value (0)]</b> -> CompanyName1

OrganisationFormattedName-><b>[copy value (1)]</b> -> CompanyName2

dont forget my points.

Regards

Pushkar

Former Member
0 Kudos

Ooops, if you only have one context you're mapping from, Pushkar's is definately the easiest solution.

Former Member
0 Kudos

Thanks Pushkar and others,

Pushkar, your solution was very helpfull and you will get definitly all my points. But when the source element doesn't have a OrganisationFormattedName tag I get the following error:

Cannot produce target element /mt_OrderBestand/PurchaseOrderHeader/ShipToAddress/CompanyName1. Check xml instance is valid for source xsd and target-field mapping fulfills requirements of target xsd

Any idea about that?

Regards,

Kamran

Message was edited by:

Kamran Vakili

Former Member
0 Kudos

Hi Kamran,

Before mapping, you use the node fn "exists"

followed by boolean fn "If without else"

exitst will check if we have any element in the source message.

if exists returns true (1), you map the source to the target using as mentioned above.

Regards

Pushkar

Former Member
0 Kudos

Pushkar and others,

Thank you very much for your help. Pushkar you got all of my points

Regards

Kamran

Former Member
0 Kudos

Thank ypu all,

null

Answers (5)

Answers (5)

Former Member
0 Kudos

Hi all,

Ive another question about the next situation, can I use the same function for the next situation?

Input file looks like this with occurrence 0..unbounded

<Item>

<ShipToLocation>

<Address>

<OrganisationFormattedName></OrganisationFormattedName>

</Address>

</ShipToLocation>

</Item>

Output file looks like this:

<LineItem>

<ShipToAddress>

<CompanyName1></CompanyName1>

<CompanyName2></CompanyName2>

</ShipToAddress>

</LineItem>

So for example there can be 2 Items in the source message therefore 2 OrganisationFormattedName.

In the target message we will have 2 LineItems and 2 CompanyName1 and 2 CompanyName2.

Regards,

Kamran

Former Member
0 Kudos

no, this is one where you would have to use a function like the one I provided above.

Or there is an easy way of using a Global count variable and each time you have your mapping with the copyvalue, in the copyvalue function use the global variable, and have a UDF increment that global variable right behind it.

If you need more elaboration, just ask.

Former Member
0 Kudos

Hi Paul,

Thank you very much for your help. I followed your approach and I didn't get the required result.

My example looks like this:

Input file:

<Item>

<ShipToLocation>

<Address>

<b><OrganisationFormattedName>AAAA</OrganisationFormattedName>

<OrganisationFormattedName>BBBB</OrganisationFormattedName></b></Address>

</ShipToLocation>

</Item>

<Item>

<ShipToLocation>

<Address>

<b><OrganisationFormattedName>CCCC</OrganisationFormattedName>

<OrganisationFormattedName>DDDD</OrganisationFormattedName></b></Address>

</ShipToLocation>

</Item>

Output file should looks like this:

<LineItem>

<ShipToAddress>

<b><CompanyName1>AAAA</CompanyName1>

<CompanyName2>BBBB</CompanyName2></b>

</ShipToAddress>

</LineItem>

<LineItem>

<ShipToAddress>

<b><CompanyName1>CCCC</CompanyName1>

<CompanyName2>DDDD</CompanyName2></b>

</ShipToAddress>

</LineItem>

I didnt get this result.

Can you help me?

Regards

Kamran

Former Member
0 Kudos

Hi Kamran,

did you try like this..

<Item> -> ....to... <LineItem>

<Address> ...to....<ShipToAddress>

<OrganisationFormattedName> -


<CompanyName1> using copy value.

Our Sandbox is down.so cant check.. . will get back to you as soon as it gets up...

Regards

Pushkar Anand

Former Member
0 Kudos

Hi Pushkar,

I just tried that it didn't work.

I get this result:

<LineItem>

<ShipToAddress>

<CompanyName1>AAAA</CompanyName1>

<CompanyName2>BBBB</CompanyName2>

</ShipToAddress>

</LineItem>

<LineItem>

<ShipToAddress>

<CompanyName1>AAAA</CompanyName1>

<CompanyName2>BBBB</CompanyName2>

</ShipToAddress>

</LineItem>

Regards,

Kamran

Message was edited by:

Kamran Vakili

justin_santhanam
Active Contributor
0 Kudos

Kamran,

Check the mapping in the below URL, and let us know whether it suits your reqmt.

Mapping

http://www.flickr.com/photo_zoom.gne?id=1181884663&size=o

Result

http://www.flickr.com/photo_zoom.gne?id=1181884681&size=o

Best regards,

raj.

Former Member
0 Kudos

Kamran, combine my mapping with what Pushkar said, where he said to use copy value, use my method with the copyvalue + UDF. Then your second set of values should not be the same.

Since I assume you are using two copyvalue functions with their definitions 0 and 1, you will always just pull the first two elements of the element your mapping from, with the global variable I told you to define, each time you call an element with the copyvalue function it will set the variable one higher, so the next time you call the copyvalue function it will get the next element from the element your mapping from.

Former Member
0 Kudos

Hello,

Maybe I wasn't very clear so hereby a print screen of the mapping:

http://www.flickr.com/photo_zoom.gne?id=1182207125&size=o

In the mapping you see that Item in the source message is 0...unbounded.

And the mapping is:

Item to LineItem

Address toShipToAddress

OrganisationFormattedName to CompanyName1

OrganisationFormattedName to CompanyName2

Here you can see an example:

http://www.flickr.com/photo_zoom.gne?id=1182207137&context=photostream&size=o

There are 2 Items and 4 OrganisationFormattedName. And the result has to be:

CompanyName1 : AAAA

CompanyName2 : BBBB

CompanyName1 : CCCC

CompanyName2 : DDDD

And I dont get that...

Regards,

Kamran

Former Member
0 Kudos

Paul,

Thank you again for your reply.

I used your solution for my issue. And I didn't get the required result.

When I use this structure as my mapping:

OrganisationFormattedName <-CopyValue [0] -


UDFIncrement--> CompanyName1

OrganisationFormattedName <-CopyValue [1] -


UDFIncrement--> CompanyName2

The output will be like this if I have 2 Item tags:

CompanyName1: AAAA

CompanyName2: BBBB

CompanyName1: AAAA

CompanyName2: BBBB

And with this stucture the result is:

OrganisationFormattedName <-CopyValue [counter] -


UDFIncrement--> CompanyName1

OrganisationFormattedName <-CopyValue [counter] -


UDFIncrement--> CompanyName2

CompanyName1: AAAA

CompanyName2: AAAA

CompanyName1: AAAA

CompanyName2: AAAA

Did I do something wrong?

Regards,

Kamran

Former Member
0 Kudos

For some reason it looks like the counter isn't getting incremented.

did you initialize it correctly, it may be in the java section,

in global variables you put;

int counter =0;

instead of just

int counter;

you don't declare it as 0 there or it will always stay as 0;

make sure it's exactly like the second picture in my previous post.

http://i161.photobucket.com/albums/t207/Reimius/CopyHelp2.jpg

also check the UDFIncrement to make sure it has counter++; in it.

Former Member
0 Kudos

okay, I just checked it, and it doesn't work, the copyvalue function will only call once, and that's why you get the same values over an over. It looks like you'll need a special UDF for this, I'll make it for you when I find time, probably have it done in couple hours.

justin_santhanam
Active Contributor
0 Kudos

Kamran,

I hope this time the mapping logic will meet ur reqmt. If not kindly reply back.

I had assumed that for particular Item in source u will have only two company names. For Particular Line Item in taregt u will have only two company names.

Also source must have two companynames for each Item its mandatory!!

If my assumption is correct.Then follow the logic.

Mapping:

http://www.flickr.com/photo_zoom.gne?id=1196198164&size=o

http://www.flickr.com/photo_zoom.gne?id=1196198180&size=o

UDF :

http://www.flickr.com/photo_zoom.gne?id=1196198190&size=o

Results:

http://www.flickr.com/photo_zoom.gne?id=1196198210&size=o

http://www.flickr.com/photo_zoom.gne?id=1196198194&size=o

Best regards,

raj.

Former Member
0 Kudos

yeah, Raj's solution is exactly what I'd do. Beat me again raj... until next time!

justin_santhanam
Active Contributor
0 Kudos

Paul,

<i>Beat me again raj... until next time!</i>

Paul you are seriously working on this issue. Really appreciate your time!!!

Surely Paul next time u will beat me...

Don't consider me as ur opponent rather consider me as friend, we are suggesting the the solution to our friends , am I right? There is no competition though!!

Cheers mate

@Kamran : In the solution I suggested please remove one input (Index) and run the same. Coz I'm not using that parameter inside UDF.

Best regards,

raj.

Former Member
0 Kudos

Raj and Paul,

Its working now. I dont know how to thank you. I dont have enough points to give for all of your efforts. Really appreciate it.

Kind regards,

Kamran

Former Member
0 Kudos

Kamran:

I worked same you working on..my scenario is SRM -XI-FTP... the mapping was done from PurchaseOrderRequest_out to xCML file... i used the following simple mapping with one UD "GetValue"

<b>Org.Name > Map with Default Value> Get Value--->Company Name</b>

Code for Simple UD " Get Value"


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

 if(i==0)
  result.addValue(a<i>);
}

if you want first element give i == 0

second element give i == 1..

thats it

Former Member
0 Kudos

HI Guru,

Ive the same scenario with the same input and output. Ill try this and let you know.

Regards,

Kamran

Former Member
0 Kudos

My documentation on the TakeWhich Function will solve whatever you need...

The TakeWhich function-

Use this function if you have an xml document with entries with the same xml tag in order, but you only want a certain entry for mapping. This will also work if you want a certain entry for many contexts of entries.

Function inputs are the node you want to map from, the number of the entry that you want, and the total number of entries in the context.

Example:

Function inputs- data, 3, 4

Source-

<row>

<data>test1</data>

<data>test2</data>

<data>test3</data>(we want this one)

<data>test4</data>

</row>

<row>

<data>test5</data>

<data>test6</data>

<data>test7</data>(and this one)

<data>test8</data>

</row>

Destination-

<destination>test3</destination>

<destination>test7</destination>

public void TakeWhich (String[] a,String[] b,String[] c,ResultList result,Container container){

/**

*This function is used to grab certain entries from series of entries with the same xml

*tag

*a- node with same xml tags, b- which node you want, c-number of nodes in a context

*Created by Paul Schroeder July 2007

*/

int i = Integer.parseInt(b[0]);

int i2 = Integer.parseInt(c[0]);

int count=1;

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

{

if(count==i)

{

result.addValue(a[j]);

result.addContextChange();

}

if(count==i2)

{

count=0;

}

count++;

}

}

take out the result.addContextChange(); if you have your destination entries in the same context, which it looks like you do.

and in teh mapping use the XI provided function removeContexts before this function

Former Member
0 Kudos

Actually, leave teh addContextChange in there.... I was thinking it was for somethign else

lol, Vijay, I just put the implementation of exactly what you said.

Former Member
0 Kudos

For your case you need to create the 2 UDF for each Company name to filer the first value and second value. You can't do this with Standard functions according to my knowledge.

Create the UDF which always return the first element of OrganisationFormattedName and another UDF which always return the second element of OrganisationFormattedName map to CompanyName1 and CompanyName2 respectively.

Warm Regards,

Vijay

laurent_touillaud
Contributor
0 Kudos

Hi Kamran,

I suggest you to use the two following mappings :

- UseOneAsMany

- Split by value

This would look like

OrganisationFormattedName -> UseOneAsMany ->Split by value ->CompanyName

You will have as many nodes created as there are occurences in your source field.

Regards,

Laurent.

Reward points if helpfull.