cancel
Showing results for 
Search instead for 
Did you mean: 

Map Field names to target side

Former Member
0 Kudos

Hi Gurus,

I have a critical Requiremnet where in i need to map the field names from Source structute to the target structure..

For Example:

My Source structure:

<matnr> 123</matnr>

<maktn>XYZ</maktn>

Expected Target structure:

<Node>

<Fieldname>matnr </DFieldname>

<Fieldvalue>123</Fieldvalue>

</Node>

<Node>

<Fieldname>maktn </DFieldname>

<Fieldvalue>XYZ</Fieldvalue>

</Node>

Any Blog on this is highly Appreciated.

Best regards,

Sainath Chutke

Edited by: Sainath Chutke on Feb 23, 2009 8:42 PM

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Hi,

I am not sure if it is possible in Graphical Mapping, you have to look for some Parser related Java code & use them in your mapping as UDFs

In XSLT there is a name() function, which can be used for this purpose.

but above all, while you do the mapping, you already know the name of your source field, so why dont you use constants. Not sure if it is all that worthy to do find a suitable coding, which only adds to your performance or are you trying any kind of recursive mapping?? explain your scenario to be able to get simpler solution

Regards

Vishnu

Former Member
0 Kudos

VIshnu,

My client does not want to use XSLT mapping....Can you tell me How to proceed with java mapping in this case.

BR,

sai

Former Member
0 Kudos

Sai

Can you provide your source and target structures with occurrences...

Answers (6)

Answers (6)

Former Member
0 Kudos

Hardcoded the values manually

Former Member
0 Kudos

Sainath,

If your client don't want to use XSL, the possibilities are limited.

Have you discussed the reason for not using XSL. this is the most commonly used mapping structures.

If you want to use a java mapping (not a UDF) you need to import the org.w3c.dom.* API in order to read the XML data.

you can convert the stream to an xmlDocument and determine all elements in there. So you can also dynamically choose the elementNames.

But whenever you use the fields as static fields (and your input XML will not change) then i'd suggest you use the constant function within the graphical mapper and use duplicate subtree at taget side in order to get the Correct elements pointing to the correct targetstructures.

If you need some assistance let me know ok.

greets

markangelo_dihiansan
Active Contributor
0 Kudos

Hi Sainath,

This is possible using graphical mapping with the help of UDF.

A simplified mapping will look like this:

For Fieldname

constant: MATNR --> useOneAsMany --> 1. UDF -


> Fieldname

MATNR --> removeContext --> /

MATNR --> removeContext --> /

constant: MAKTN --> useOneAsMany --> 2.

MATNR --> removeContext --> /

MATNR --> removeContext --> /

where 1 and 2 are the inputs to the UDF.

For Fieldvalue

MATNR --> removeContext --> 1. UDF --> Fieldvalue

MAKTN --> removeContext --> 2.

Note that you can eliminate the node removeContext just make sure that you set the context to the topmost level of the hierarchy.

The UDF that will be used is of context type: There are two input arguments, input1 and input2:

Here is the code:

StringBuffer e = new StringBuffer();

String b = null;

for (int a = 0; a<input1.length; a++){ e = e.append( "/" + input1[a]);}

for (int a = 0; a<input2.length; a++){ e = e.append( "/" + input2[a]);}

e = new StringBuffer(e.substring(1,e.length())); b = e.toString();

String c[] = b.split("/");

for (int a = 0; a<c.length; a++){result.addValue(c[a]);}

What this UDF does is to add the contexts of the input, it is also taken into consideration multiple occurrences of the MATNR and MAKTN e.g.

MATNR = 12,1234

MAKTN = XYW,XYZ

The output for Fieldname is MATNR,MATNR,MAKTN,MAKTN

The output for Fieldvalue is 12, 1234, XYW, XYZ

Hope this helps,

Former Member
0 Kudos

Hi Sainath,

There is a way in PI 7.1

While passing the field from source structure, use 'Return as XML' way on the field (Just right click on the field in mapping and select this option). That passes the value of the field in an XML format like

<?xml version="1.0" encoding="UTF-8"?><KEY_NAME>Key_Value</KEY_NAME>

Pass this to your custom function and parse the XML string and get the key name (here it is 'KEY_NAME').

Hope this will solve your problem.

-Vijendra

Former Member
0 Kudos

Hi,

This seems static XML data, why not use constants here.

Also when creating XSL mappings you can use the name() function.

I don't think the Graphical mapper will provide you the possibility.

GReets

Former Member
0 Kudos

HI Sainath,

You must be having fixed number of input fields, so as Vishnu mentioned, you could try to map the field names (constant) to your target fields, instead of writing a code to fetch the input field names.

thanks,

Pooja Pandey