cancel
Showing results for 
Search instead for 
Did you mean: 

Mapping issue with context again

Former Member
0 Kudos

I again need help with a mapping issue. I don’t know how to handle the contexts to get this working in the xi graphical mapping tool. I have previously logged a question regarding this structure but the requirements have now changed.

I have a source document that has multiple delivery line items and for each delivery line item, there are multiple handling units. Each handling unit contains the line number of the delivery line item it belongs to. This structure has been simplified below.

<b><u>Source Sample</u></b>

<DOCUMENT>

<DELIVERY_LINEITEM>

<LINENUMBER>10</LINENUMBER>

<MATERIAL>mat 1</MATERIAL>

</DELIVERY_LINEITEM >

<DELIVERY_LINEITEM >

<LINENUMBER>20</LINENUMBER>

<MATERIAL>mat 2</MATERIAL>

</DELIVERY_LINEITEM >

<HANDLING_UNITS>

<HU_LABEL>123</HU_LABEL>

<HU_ITEM>

<LINENUMBER>10</LINENUMBER>

</HU_ITEM>

</HANDLING_UNITS>

<HANDLING_UNITS>

<HU_LABEL>456</HU_LABEL>

<HU_ITEM>

<LINENUMBER>10</LINENUMBER>

</HU_ITEM>

</HANDLING_UNITS>

<HANDLING_UNITS>

<HU_LABEL>789</HU_LABEL>

<HU_ITEM>

<LINENUMBER>20</LINENUMBER>

</HU_ITEM>

</HANDLING_UNITS>

</DOCUMENT>

<u><b>Source Structure</b></u>

DOCUMENT 1..1

-


DELIVERY_LINEITEM 1..unbounded

-


LINENUMBER 1..1

-


MATERIAL 1..1

-


HANDLING_UNITS 1..unbounded

-


HU_LABEL 1..1

-


HU_ITEM 1..1

-


LINENUMBER 1..1

In the target structure, I need to output each handling unit along with the corresponding DELIVERY_LINEITEM material. Target structure has been simplified below:

<u><b>Target Sample</b></u>

<DOCUMENT>

<ROW>

<PACKAGING>

<HU_LABEL>123</HU_LABEL>

</PACKAGING>

<PACKAGING_ITEM>

<LINENUMBER>10</LINENUMBER>

<MATERIAL>mat 1</MATERIAL>

</PACKAGING_ITEM>

</ROW>

<ROW>

<PACKAGING>

<HU_LABEL>456</HU_LABEL>

</PACKAGING>

<PACKAGING_ITEM>

<LINENUMBER>10</LINENUMBER>

<MATERIAL>mat 1</MATERIAL>

</PACKAGING_ITEM>

</ROW>

<ROW>

<PACKAGING>

<HU_LABEL>789</HU_LABEL>

</PACKAGING>

<PACKAGING_ITEM>

<LINENUMBER>20</LINENUMBER>

<MATERIAL>mat 2</MATERIAL>

</PACKAGING_ITEM>

</ROW>

</DOCUMENT>

<u><b>Target Structure</b></u>

DOCUMENT 1..1

-


ROW 1..unbounded

-


PACKAGING 1...1

-


HU_LABEL 1..1

-


PACKAGING_ITEM 1..1

-


LINENUMBER 1..1

-


MATERIAL 1..1

Note, 1 ROW in the target structure = 1 HANDLING_UNITS from the source structure.

Can anyone help me to achieve this? I do not know how to map the relevant DELIVERY_LINEITEM\MATERIAL from the source structure to the target structure.

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Hi JM,

I would advise for you to create a Context user defined function which takes three values LinNumber, Material and KeyLinNumber(for the linenumber you are looking for).

Here's the simlified code:

String ret;

for (int ind = 0; ind<LinNumer.length; ind++)

if (LinNumber[ind].equals(KeyLinNumber[0]))

ret = Material[ind];

result.addValue(ret);//

Pass LINENUMBER, MATERIAL(these from DELIVERY_LINEITEM), and LINENUMBER (from HU_ITEM) to this function and map it to MATERIAL.

Former Member
0 Kudos

Hi Yaghya,

I have tried this solution prior to posting this question. My issue with this is that it only works for the first handling unit, i.e the first call of the function. The problem is that on subsequent calls, LINENUMBER (from the delivery_lineitem) is empty.

For example, I have two delivery line items. On the first call to the function, both line items are passed to the function. On the second call, no line items are passed to the function. Seems to be an issue with context again. Do you know how to work around this?

justin_santhanam
Active Contributor
0 Kudos

JM,

Please find the solution. Reply back if it helps or not

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

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

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

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

<b>Code used:</b>

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

{

for(int k=0;k<Delivery_Linenum.length;k++)

{

if(Handling_Linenum[j].equals(Delivery_Linenum[k]))

{

result.addValue(""Material[k]"");

result.addContextChange();

}

}

}

Best regards,

raj.

Former Member
0 Kudos

Hi Raj,

Yes that has worked!

Thank you once again for solving another of my mapping problems. I greatly appreciate the time and effort you have taken to solve this and explain the solution to me clearly.

Answers (1)

Answers (1)

justin_santhanam
Active Contributor
0 Kudos

JM,

I have a doubt.Is there a criteria that, u need to group Delivery_Lineitem LINENUMBER with Handling_Units LINENUMBER . In your example the source has two Delivery Line_Item and the target has been grouped with according to Line number, is my understanding correct?

Please clear this!!

Best regards,

raj.

Former Member
0 Kudos

Hi Raj,

Yes I think your understanding is correct.

To clarify: In the target structure, I am outputting the Handling_units. However, I also need to output the material number from the delivery_lineitem. To get the correct material number for the handling_unit, I need to get the one where the LINENUMBER of the delivery_lineitem equals the handling_unit LINENUMBER that is being output

I hope this clears it up. Please feel free to ask me more questions if not clear.