cancel
Showing results for 
Search instead for 
Did you mean: 

Nested structure to flat structure in the PI mapping

Former Member
0 Kudos

Dear friends,

I've a issue regarding message mapping within PI 7.0

This is how my source structure looks like:

<?xml version="1.0" encoding="UTF-8"?>
<stop>
   <stopreference/>
   <action>
      <actionreference>1</actionreference>
      <shipment>
         <shipmentreference>11</shipmentreference>
         <goods>
            <goodsreference>111</goodsreference>
         </goods>
         <goods>
            <goodsreference>111</goodsreference>
         </goods>
      </shipment>
   </action>
   <action>
      <actionreference>2</actionreference>
      <shipment>
         <shipmentreference>22</shipmentreference>
         <goods>
            <goodsreference>222</goodsreference>
         </goods>
      </shipment>
   </action>
</stop>

The target structure looks like this:

<?xml version="1.0" encoding="UTF-8"?>
<Test>
   <STOPDETAILS>
      <item>
         <EXTERNAL_STOP/>
         <EXTERNAL_ACTION/>
         <EXTERNAL_SHIP/>
          <EXTERNAL_GOOD/>
        </item>
   </STOPDETAILS>
</Test>

In the source message the stop is the header and within a stop there can be 0 or more actions, within action there can be 0 or more shipments and within a shipment there can be 0 or more goods...

My target message is a flat XML structure...

The customer wants to see an Item target structure for every goods, the shipment, the action and the stop. If the there are no goods, they wants just to see the shipment, the action and the stop...and so on...

So its look like this:

stop 1 - action 1 - shipment 1 - good 1

stop 1 - action 1 - shipment 1 - good 2

stop 1 - action 1 - shipment 2 - good 1

stop 1 - action 1 - shipment 2 - good 2

stop 1 - action 2 - shipment 1 - good 1

stop 1 - action 2 - shipment 1 - good 2

And so on...

I've to solve this issue in the Graphical Mapping...

Do you have a suggestion how to do that?

Kind regards,

Kamran

Accepted Solutions (0)

Answers (5)

Answers (5)

Former Member
0 Kudos

Hi Kamran,

I believe this can be solved with some effort and careful context handling.

The foremost thing you need to understand well the logical relation between the target node (repeatable) and the source nodes in different hierarchies.

Then the logic goes like this:

1.The target item node repeats for as many times the goods node appears in your source structure. So map the target "item" node with goods node raised to its highest context.

Though not directly - use a FormatByExample with Shipment, then mapWithDefault(blank value) -> FormatByExample with action, then mapWithDefault -> then the same for Stop.

This gives you the correct number of occurance for the item node.

2. Map the target child nodes now with proper context handling, use "UseOneAsMany" here if required. With monitoring the Contexts in Display Queue and proper test data you can surely achieve the required results with Standard Functions only. Though I agree its quite an effort anticipate the contexts for different data conditions.

All the best. Hope it helps.

Regards,

Suddha

Former Member
0 Kudos

Hi Suddha,

"1.The target item node repeats for as many times the goods node appears in your source structure. So map the target "item" node with goods node raised to its highest context."

That's part of the case. The target item node has to repeats for as many timesas the action, shipment and goods nodes appear in the source structure. And all of these nodes are optional so it's possible that they don't appear in the source srtucture.

This is an example of how the source structure looks like...So with 1 action, 1 shipment and 2 goods so I have to create 4 Items in the target structure...

<?xml version="1.0" encoding="UTF-8"?>
<stop>
   <stopreference>0010000020_0006</stopreference>
   <action>
      <actionreference>0080004484</actionreference>
      <shipment>
         <shipmentreference>0080004484</shipmentreference>
         <goods>
            <goodsexternalreference>0080004484_0001</goodsexternalreference>
         </goods>
         <goods>
            <goodsexternalreference>0080004484_0002</goodsexternalreference>
          </goods>
      </shipment>
   </action>
</stop>

Former Member
0 Kudos

Hi Suddha,

Im going to try your solution and get back to you...

Thank you for your solution...

Regards,

Kamran

former_member181962
Active Contributor
0 Kudos

Hi Kamran,

YOu might have to use Use-One-As-Many function for your EXTERNAL_STOP/>

<EXTERNAL_ACTION/>

<EXTERNAL_SHIP/>

fields.

See usage here:

http://help.sap.com/saphelp_nwpi71/helpdata/en/ef/df564b6aa24fc9ab0d685460747de5/content.htm

For your Goods element, you can just use Remove Contexts and use splitByValue (One change of each value)

Regards,

Ravi

Former Member
0 Kudos

hi kamran,

Can you please clarify the question.?

As far i have understood you can go with xslt mapping.

thanks

Jai

Former Member
0 Kudos

Nobody has any idea???

Kind regards,

Kamran

Marçal_Oliveras
Active Contributor
0 Kudos

Can you give us an example of the target structure filled with the data of your sample source structure please?

Former Member
0 Kudos

Hi Marshal,

Hereby an example how the filled terget structure looks like:

So in the source structure Ive 2 actions and in the second action Ive two goods...So in the target structure I must have 3 items...

Filled Target structure:

Edited by: Kamran Vakili on Aug 3, 2009 1:27 PM

Former Member
0 Kudos
<?xml version="1.0" encoding="UTF-8"?>

   <STOPDETAILS>
      <ITEM>
         <MANDT/>
         <EXTERNAL_STOP>0010000020_0006</EXTERNAL_STOP>
         <ADRNZ>0026858089</ADRNZ>
         <TIMESTAMP>20090721121900 </TIMESTAMP>
         <TIMESTAMPSTART>20090721121600 </TIMESTAMPSTART>
         <TIMESTAMPSTOP>20090721121700 </TIMESTAMPSTOP>
         <ID_STOP>40</ID_STOP>
         <DESCR_STOP>Done</DESCR_STOP>
         <EXTERNAL_ACTION>0080004483</EXTERNAL_ACTION>
         <TIMESTAMP_ACTION>20090721121900 </TIMESTAMP_ACTION>
         <ID_ACTION>30</ID_ACTION>
         <DESCR_ACTION>Partly Done</DESCR_ACTION>
         <EXTERNAL_SHIP/>
         <ID_SHIPM/>
         <DESC_SHIPTYPE/>
         <EXTERNAL_GOOD/>
         <ID_GOOD/>
         <DESCR_GOOD/>
      </ITEM>
      <ITEM>
         <MANDT/>
         <EXTERNAL_STOP>0010000020_0006</EXTERNAL_STOP>
         <ADRNZ>0026858089</ADRNZ>
         <TIMESTAMP>20090721121900 </TIMESTAMP>
         <TIMESTAMPSTART>20090721121600 </TIMESTAMPSTART>
         <TIMESTAMPSTOP>20090721121700 </TIMESTAMPSTOP>
         <ID_STOP>40</ID_STOP>
         <DESCR_STOP>Done</DESCR_STOP>
         <EXTERNAL_ACTION>0080004484</EXTERNAL_ACTION>
         <TIMESTAMP_ACTION>20090721121900 </TIMESTAMP_ACTION>
         <ID_ACTION>deelbewerking</ID_ACTION>
         <DESCR_ACTION>Done</DESCR_ACTION>
         <EXTERNAL_SHIP>0080004484</EXTERNAL_SHIP>
         <ID_SHIPM>20</ID_SHIPM>
         <DESC_SHIPTYPE>Planned</DESC_SHIPTYPE>
         <EXTERNAL_GOOD>0080004484_0001</EXTERNAL_GOOD>
         <ID_GOOD>40</ID_GOOD>
         <DESCR_GOOD/>
      </ITEM>
      <ITEM>
         <MANDT/>
         <EXTERNAL_STOP>0010000020_0006</EXTERNAL_STOP>
         <ADRNZ>0026858089</ADRNZ>
         <TIMESTAMP>20090721121900 </TIMESTAMP>
         <TIMESTAMPSTART>20090721121600 </TIMESTAMPSTART>
         <TIMESTAMPSTOP>20090721121700 </TIMESTAMPSTOP>
         <ID_STOP>40</ID_STOP>
         <DESCR_STOP>Done</DESCR_STOP>
         <EXTERNAL_ACTION>0080004484</EXTERNAL_ACTION>
         <TIMESTAMP_ACTION>20090721121900 </TIMESTAMP_ACTION>
         <ID_ACTION>40</ID_ACTION>
         <DESCR_ACTION>Done</DESCR_ACTION>
         <EXTERNAL_SHIP>0080004484</EXTERNAL_SHIP>
         <ID_SHIPM>20</ID_SHIPM>
         <DESC_SHIPTYPE>Planned</DESC_SHIPTYPE>
         <EXTERNAL_GOOD>0080004484_0002</EXTERNAL_GOOD>
         <ID_GOOD>40</ID_GOOD>
         <DESCR_GOOD/>
      </ITEM>
   </STOPDETAILS>
Marçal_Oliveras
Active Contributor
0 Kudos

Hi Kamran, I think Ravi Kanth solution is good, or at least is the way. You must do a lot of test and error to get the final solution...

I think this pdf will help you, read from page 26:

[Advanced Message Mapping|https://www.sdn.sap.com/irj/scn/elearn?rid=/library/uuid/be05e290-0201-0010-e997-b6e55f9548dd&overridelayout=true]

Former Member
0 Kudos

Hi Ravi and Marshal,

I've already used useOneAsMany, but I think there also has to be a counter or a loop to see how many times the elements action, shipment and goods will appear... Right?

Regards,

Kamran

Edited by: Kamran Vakili on Aug 3, 2009 2:17 PM

Former Member
0 Kudos

This message was moderated.

Former Member
0 Kudos

Hi Sunil,

I'm familiar with standard XI graphical functions and I believe it's not possible to solve it with standard XI graphical functions. Or do you have an idea how to solve it with standard XI graphical functions?

Ive already tried useOneAsMany but it's doesn't do what I want...

Regards,

Kamran