cancel
Showing results for 
Search instead for 
Did you mean: 

Flattening an IDOC via Graphical mapping

Former Member
0 Kudos

Hi,

I'm still new to the context mapping functions.

Though there are numerous examples to do parts of what I would like to do, none seems to address my scenario in such a way that I can combine the mapping methods.

My scenario

Source IDOC

<SEG1> (Occurs 1)

<PLANT>P1</PLANT>

</SEG1>

<SEG2> (Occurs 1..9999)

<MATERIAL>

<MATNR>M1</MATNR>

<MAKTX>D1</MAKTX>

<SEG3>

<UOM>U1</UOM>

<UOM>U2</UOM>

<UOM>U3</UOM>

</SEG3>

</MATERIAL>

<MATERIAL>

<MATNR>M2</MATNR>

<MAKTX>D2</MAKTX>

<SEG3>

<UOM>U4</UOM>

<UOM>U5</UOM>

<UOM>U6</UOM>

</SEG3>

</MATERIAL>

</SEG2>

Target flat structure

<Target> (Occurs 0 to unbounded)

<Plant/>

<Matnr/>

<Desc/>

<UOM/>

</Target>

What I'm looking for is :

<Target>

<Plant>P1</Plant>

<Matnr>M1</Matnr>

<Desc>D1</Desc>

<UOM>U1</UOM>

<Plant>P1</Plant>

<Matnr>M1</Matnr>

<Desc>D1</Desc>

<UOM>U2</UOM>

<Plant>P1</Plant>

<Matnr>M1</Matnr>

<Desc>D1</Desc>

<UOM>U3</UOM>

<Plant>P1</Plant>

<Matnr>M2</Matnr>

<Desc>D2</Desc>

<UOM>U4</UOM>

<Plant>P1</Plant>

<Matnr>M2</Matnr>

<Desc>D2</Desc>

<UOM>U5</UOM>

<Plant>P1</Plant>

<Matnr>M2</Matnr>

<Desc>D2</Desc>

<UOM>U6</UOM>

</Target>

and so on.

I can flatten the structure to get the <Plant><Material> part with the <removeContext> method

and

the <Matrial><Desc><UOM> with a <copyHeaderPerUOM> user function folowed by a <SplitByValue> assignment but I cannot seem to combine the two methods to get to resultant flat structure I'm looking for.

Any help will be appreciated.

Thanks

Andre

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Mapping:

UOM(WITH CONTEXT as ROOT)-->TARGET

-


PLANT--->|

UOM(WITH CONTEXT as ROOT)->|UseOneAsMany>SplitByValue-->Plant

UOM(WITH CONTEXT as ROOT)--->|

-


MATNR--->|

UOM(WITH CONTEXT as MATERIAL)->|UseOneAsMany>SplitByValue-->Matnr

UOM(WITH CONTEXT as MATERIAL)--->|

-


MAKTX--->|

UOM(WITH CONTEXT as MATERIAL)->|UseOneAsMany>SplitByValue-->Desc

UOM(WITH CONTEXT as MATERIAL)--->|

UOM>SplitByValue>UOM

InputData:

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

<ROOT>

<SEG1> (Occurs 1)

<PLANT>P1</PLANT>

</SEG1>

<SEG2> (Occurs 1..9999)

<MATERIAL>

<MATNR>M1</MATNR>

<MAKTX>D1</MAKTX>

<SEG3>

<UOM>U1</UOM>

<UOM>U2</UOM>

<UOM>U3</UOM>

</SEG3>

</MATERIAL>

<MATERIAL>

<MATNR>M2</MATNR>

<MAKTX>D2</MAKTX>

<SEG3>

<UOM>U4</UOM>

<UOM>U5</UOM>

<UOM>U6</UOM>

</SEG3>

</MATERIAL>

</SEG2>

</ROOT>

oUTPUT:

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

<ROOT>

<Target>

<Plant>P1</Plant>

<Matnr>M1</Matnr>

<Desc>D1</Desc>

<UOM>U1</UOM>

</Target>

<Target>

<Plant>P1</Plant>

<Matnr>M1</Matnr>

<Desc>D1</Desc>

<UOM>U2</UOM>

</Target>

<Target>

<Plant>P1</Plant>

<Matnr>M1</Matnr>

<Desc>D1</Desc>

<UOM>U3</UOM>

</Target>

<Target>

<Plant>P1</Plant>

<Matnr>M2</Matnr>

<Desc>D2</Desc>

<UOM>U4</UOM>

</Target>

<Target>

<Plant>P1</Plant>

<Matnr>M2</Matnr>

<Desc>D2</Desc>

<UOM>U5</UOM>

</Target>

<Target>

<Plant>P1</Plant>

<Matnr>M2</Matnr>

<Desc>D2</Desc>

<UOM>U6</UOM>

</Target>

</ROOT>

Regards,

KNS Kumar.

Answers (2)

Answers (2)

Former Member
0 Kudos

Hi Andre,

I believe following approach can fullfil your requirement

1)To get the total <target> tags:

<UOM> set the context to root, map this node to <target>

2)To get <plant> tag for all occurance of <target>:

Write a user defined function say e.g. 'AssignValue' which takes 2 inputs, write the code as

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

{

result.addValue(b[0]);

}

Now the 2 input nodes to the function will be,<UOM> with context set to the root and <plant> context set to 'SEG1' map output of the function to <plant>

3) To get <MATNR> tag for all occurance of <target>:

use the function 'AssignValue' with the inputs, <UOM>set the context to 'SEG2' and <MATNR> set the context to 'SEG2' then use 'SplitByValue' then map to target <MATNR>

4)To get <MAKTX> tag for all occurance of <target>:

use the function 'AssignValue' with the inputs, <UOM>set the context to 'SEG2' and <MAKTX> set the context to 'SEG2' then use 'SplitByValue' then map to target <MAKTX>

5)To get <UOM> tag for all occurance of <target>:

<UOM>set the contex to root then use 'SplitByValue' then map to target <UOM>

Regards,

Amulya

Message was edited by: Amulya Lewis

stefan_grube
Active Contributor
0 Kudos

Hi Andre,

This is not possible with graphical mapping tool. You cannot have alternating elements. Every element has to be in a sequence under the node.

Maybe it helps, when you try to create a structure like this:


<root>
<Target>
<Plant>P1</Plant>
<Matnr>M1</Matnr>
<Desc>D1</Desc>
<UOM>U1</UOM>
<b></Target>
<Target></b>
<Plant>P1</Plant>
<Matnr>M1</Matnr>
<Desc>D1</Desc>
<UOM>U2</UOM>
<b></Target>
<Target></b>
<Plant>P1</Plant>

...

<UOM>U6</UOM>
</Target>
</root>

If you want to use the content conversion of the (file) adapter, this will work as well.

Regards

Stefan