# Mapping out to an EDI 856 (and HLLoops in general)

**URL:** <https://community.cdata.com/t/mapping-out-to-an-edi-856-and-hlloops-in-general/213>\
**Category:** CData Arc\
**Tags:** discussion\
**Created:** [June 13, 2023, 8:52pm UTC](https://community.cdata.com/t/mapping-out-to-an-edi-856-and-hlloops-in-general/213 "2023-06-13T20:52:16Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![James\_B](https://sea3.discourse-cdn.com/cdata/user_avatar/community.cdata.com/james_b/32/1688_2.png) [@James\_B](https://community.cdata.com/u/James_B)\
**Post date:** [June 13, 2023, 8:52pm UTC](https://community.cdata.com/t/mapping-out-to-an-edi-856-and-hlloops-in-general/213/1 "2023-06-13T20:52:16Z")

</div>

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&nbsp;HLLoop&nbsp;is treated like a sibling element, but the&nbsp;HLLoop&nbsp;is a representation of an element in a hierachy so two neighboring&nbsp;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:

```auto
HL*1**S~  <-- the root shipmentHL*2*1*O~  <-- the first order, child of the shipmentHL*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 shipmentHL*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&nbsp;HLLoops at the same level, as siblings:

```xml
<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:

![9ce589e8-2826-426c-84d0-3ed648682ea7.png](https://us1.discourse-cdn.com/cdata/original/1X/078fe3d0092b7143f113d56e6797636e6616e651.png)

the X12 connector is able to output the&nbsp;HLLoops in a hierarchy, so you can loop over them as their type:

```xml
<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&nbsp;structure when you are creating an outbound mapping. The best way to do this is to start with a&nbsp;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.

 ![6d6b4d1a-9905-4c88-bfa9-8e666b2fea19.png](https://us1.discourse-cdn.com/cdata/original/2X/f/f0d57eaa1af82f72ba242f138cf19f6df64d644a.png)

[856\_Out.zip](https://community.cdata.com/uploads/short-url/1SutrpBRrBWTAMCzQSb8cTdSt15.zip) (7.4 KB)

---

<div class="post-metadata">

**Author:** ![Prashanth](https://avatars.discourse-cdn.com/v4/letter/p/439d5e/32.png) [@Prashanth](https://community.cdata.com/u/Prashanth)\
**Post date:** [November 7, 2023, 5:54pm UTC](https://community.cdata.com/t/mapping-out-to-an-edi-856-and-hlloops-in-general/213/2 "2023-11-07T17:54:55Z")

</div>

Hi James,

I have a typical scenario where HL\_T loop should be created just once for each new value in the loop.

My input files has Tare level SSCC and Pack level SSCC at the same level but HL\_T should occur once for each label code. Is this a custom script or any standards setting available?

input:

E1EDL24

+E1EDL11

**PACK\_SCC - 084111111**

**PACK QTY&nbsp; - 1**

+ZE1EDL11-

**PALLET\_SSCC - T000001**

+E1EDL11

**PACK\_SCC - 084111112**

**PACK QTY&nbsp; - 1**

+ZE1EDL11-

**PALLET\_SSCC - T000001**

+E1EDL11

**PACK\_SCC - 084111113**

**PACK QTY&nbsp; - 1**

+ZE1EDL11-

**PALLET\_SSCC - T000001**

+E1EDL11

**PACK\_SCC - 084111114**

**PACK QTY&nbsp; - 1**

+ZE1EDL11-

**PALLET\_SSCC - T000002**

+E1EDL11

**PACK\_SCC - 084111115**

**PACK QTY&nbsp; - 1**

+ZE1EDL11-

**PALLET\_SSCC - T000002**

+&nbsp;E1EDL11

**PACK\_SCC - 084111116**

**PACK QTY&nbsp; - 1**

+ZE1EDL11-

**PALLET\_SSCC - T000002**

Output should&nbsp;be

HL\*T

MAN\*GM\*T000001

HL\*P

MAN\*GM\*084111111

MAN\*GM\*084111112

MAN\*GM\*084111113

HL\*T

MAN\*GM\*T000002

HL\*P

MAN\*GM\*084111114

MAN\*GM\*084111115

MAN\*GM\*084111116

Thank you1
