Hierarchical String Syntax |
A hierarchical string syntax is a string that describes the location of a data segment in a document tree. A document tree is the tree structure of an EDI document that shows all parent-child-sibling relationships between data segments.
Every data segment in an EDI document belongs to a certain loop (or group) of segments. So the position of any data segment in the hierarchy tree can be uniquely defined by their loop tags. The syntax of a hierarchy string is a combination of loop tags that starts with the outermost loop (lowest) tag to the innermost (highest) tag, separated with a back slash (\), and then ending the string of loop tags with a data segment ID. For example, the data segment BEG in the X12 850 version 4010 has a hierarchy string definition of \ISA\GS\ST\BEG.
Note that the ID of the first data segment inside a loop (group) is used as the loop ID in the hierarchy string syntax. Also, the ISA, GS and ST are considered loops. Therefore, the hierarchy syntax of the ISA segment is \ISA\ISA (and not just \ISA); and for the GS segment it would be \ISA\GS\GS, and for the ST segment it would be \ISA\GS\ST\ST.
When there are multiple instances for a given loop area, the instance of the loop is specified by a number enclosed in parenthesis after the loop tag. For example, a data segment BEG in the second transaction set of an EDI document is referenced using the hierarchy syntax definition \ISA\GS\ST(2)\BEG. If the loop instance is not specified, then the loop instance is always assumed to be the first one.
Also, if a segment is repeated, but is not in a loop, the instance of the second segment must be specified in the hierarchy syntax by specifying the instance number enclosed in parenthesis after the segment tag. For example, the hierarchy syntax for the second DTM would be \ISA\GS\ST\DTM(2).
The instance of a segment in a hierarchy tree always starts with a 1 with every instance of a loop. For example, the hierarchy syntax of the segment CTA (highlighted below) is \UNB\UNH\NAD(3)\CTA\CTA. (Note that CTA is a loop).
In cases where similar segment IDs, in the hierarchy tree, fall in the same level, but belong in different areas of the transaction set (message), the segment or loop in reference would be depicted with a pound (#) and the area number after it. For the example below, the TAX segment in area 3 (highlighted) would have the hierarchy syntax of \UNB\UNH\TAX#3\TAX. If the #3 is not denoted, then by default, the first TAX segment of the first TAX loop will be referenced.
Data Elements
Data elements can be included in the hierarchy string by enclosing the data element ID with a < and > sign. For example, the hierarchy syntax for the first element of the DTM segment is DTM<374>
Composite elements are entered with their sub-element after the element ID. E.g. in segment RFF, its second sub-element of its composite element C506, would have a hierarchy syntax of RFF\RFF<C506,1154>.
If there are multiple instances of the data element in a segment, then the instance number must be entered in parentheses inside the < > signs. For example, the second instance of the data element I05 in segment ISA would have a hierarchy syntax of \ISA\ISA<I05(2)>.