Home /  Guides / 

HL loops

An HL loop encodes hierarchical data. That hierarchy is often hard to see in a typical implementation guide. Stedi Guides allows you to make the hierarchy explicit. Every time you enable an HL segment in your guide, it will have another HL segment at the bottom that you can use as the next level of the hierarchy.

Need for hierarchy

An example of a hierarchy is the packing information in an 856 Ship Notice. A shipment consists of packages, a package contains items, an item relates to an order.

A hierarchy of package, item, order.
A valid way to structure packing information.

Well, that’s one way to do it, but you may prefer a different hierarchy.

A hierarchy of package, item, order.
An equally valid way to structure packing information.

Which one works better for you depends on your business needs. Because of this, EDI doesn’t enforce a specific hierarchy. Instead, it gives you a generic way of building any hierarchy you need.

Hierarchy with the HL segment

Say we have the following information and we want to encode it in an HL loop.

A hierarchy. ORD02208 has child Package #1, which has child Milk. ORD02296 has child Package #2, which has children Peanut Butter and Milk.

At the highest level of the hierarchy, we have an order.

HL*1**O*1~
PRF*ORD02208***20220815~

The HL segment has four elements.

ElementNameDescription
HL-01ID NumberIdentifies this entry of the HL loop. This will become relevant in a moment.
HL-02Parent ID NumberThis entry has no parent, so this element is empty.
HL-03Level CodeSpecifies the type of the entry. In this case, an order.
HL-04Child CodeSpecifies whether this entry has children. 1 means yes.

The order itself is described by the segment that follows: PRF.

The order is turned into a package.

HL*2*1*P*1~
TD1*CTN*1~
REF*CN*1B487311569~
ElementNameDescription
HL-01ID NumberIdentifies this entry of the HL loop.
HL-02Parent ID NumberThe ID Number of the order that this package relates to.
HL-03Level CodeSpecifies the type of the entry. In this case, a package.
HL-04Child CodeSpecifies whether this entry has children. 1 means yes.

The package itself is described by the segments that follow: TD1 and REF.

The item is related to an order.

HL*3*2*I*0~
LIN*D002*BN*75206331361~
SN1**1*EA~
PID*F*TRN***MILK~
ElementNameDescription
HL-01ID NumberIdentifies this entry of the HL loop.
HL-02Parent ID NumberThe ID Number of the package that contains this item.
HL-03Level CodeSpecifies the type of the entry. In this case, an item.
HL-04Child CodeSpecifies whether this entry has children. 0 means no.

The item itself is described by the segments that follow: LIN, SN1, and SLN.

The other package and its contents are encoded the same way.

HL*4**O*1~
PRF*ORD02208***20220815~
HL*5*4*P*1~
TD1*CTN*1~
REF*CN*1B6189321462~
HL*6*5*I*0~
LIN*F001*BN*9780672313615~
SN1**1*EA~
PID*F*TRN***PEANUT BUTTER~
HL*7*5*I*0~
LIN*F003*BN*0672313618~
SN1**1*EA~
PID*F*TRN***BLUEBERRY JAM~

Stedi Guides

When you add an HL loop to your Stedi guide, you do so one level at a time. Suppose you have the following hierarchy.

A hierarchy of order, package, item.

First, you enable an HL segment for the package-level. You need to specify the type of entry that lives at this level. In this case, that’s O for order.

At the bottom of that HL loop, you see another HL segment. Enable that one for the item-level. You need to specify the type of entry that lives at this level. In this case, that’s P for package.

At the bottom of that HL loop, you see another HL segment. Enable that one for the order-level. You need to specify the type of entry that lives at this level. In this case, that’s I for item.

If you’re using Stedi Mappings to create an EDI document, you don’t have to worry about the details of the HL segment. You just map the packages, items, and orders (or whatever is in your document) and Stedi Mappings will take care of the HL segments.

Variations

Sometimes, an implementation guide allows for variations of a hierarchy. For example, if a ship notice only has one package, you are allowed to leave out the package information.

Two hierarchies. On the left: order, package, item. On the right: order, item.

You can handle this by creating two Stedi guides: one for the hierarchy on the left, and one for the hierarchy on the right.

Need for hierarchyHierarchy with the HL segmentStedi Guides