One of the trickiest types of documents to map against in the EDI 856, which makes frequent use of a segment loop called HL (Hierarchical Loop).
HLLoops represent multiple elements that are part of a hierarchical structure at once. From the EDI standpoint, each HLLoop is treated like a sibling element, but the HLLoop is a representation of an element in a hierachy so two neighboring HLLoops can mean different things based on the values of HL01, HL02, and HL03:
HL01 is the index of the loop from the top of the document
HL02 is the index of the immediate parent to this loop
HL03 is the type of the loop
Let's look at a simplified 856:
HL*1**S~ <-- the root shipment
HL*2*1*O~ <-- the first order, child of the shipment
HL*3*2*I~ <-- the first item, child of the first order (index 2)
HL*4*2*I~ <-- the second item, child of the first order (index 2)
HL*5*1*O~ <-- the second order, child of the shipment
HL*6*5*I~ <-- the first item of the second order (index 5)
HL*7*5*I~ <-- the second item of the second order (index 5)
There is a feature in CData Arc that makes the transformation of EDI to XML a better representation of this hierarchy. Without nest master detail loops set, the XML output has all HLLoops at the same level, as siblings:
<HLLoop1 />
<HLLoop1 />
<HLLoop1 />
<HLLoop1 />
<HLLoop1 />
<HLLoop1 />
<HLLoop1 />
But if Nest Master Detail Loops is set to true in the Advanced tab of the EDI connector:
the X12 connector is able to output the HLLoops in a hierarchy, so you can loop over them as their type:
<HLLoop1> <-- each of these HLLoop1's at the root is a shipment -->
<HLLoop1> <-- each of these HLLoop1/HLLoop1's is an order -->
<HLLoop1> <-- each of these is HLLoop1/HLLoop1/HLLoop1's is an item -->
</HLLoop1>
<HLLoop1>
</HLLoop1>
</HLLoop1>
<HLLoop1>
<HLLoop1>
</HLLoop1>
<HLLoop1>
</HLLoop1>
</HLLoop1>
</HLLoop1>
You can also map out to this hierarchical structure when you are creating an outbound mapping. The best way to do this is to start with a document structure that matches the hierarchy of the data you are mapping to the 856 (for example, data extracted from linked shipments, orders, packages, and items tables), and map each parent loop to its corresponding child HLLoop in the destination.