7.5 Nesting of Data Sets
Prev | 7 The Data Set | Next

## 7.5 Nesting of Data Sets

The VR identified "SQ" shall be used for Data Elements with a Value consisting of a Sequence of zero or more Items, where each Item contains a set of Data Elements. SQ provides a flexible encoding scheme that may be used for simple structures of repeating sets of Data Elements, or the encoding of more complex Information Object Definitions often called folders. SQ Data Elements can also be used recursively to contain multi-level nested structures.

Items present in an SQ Data Element shall be an ordered set where each Item may be referenced by its ordinal position. Each Item shall be implicitly assigned an ordinal position starting with the value 1 for the first Item in the Sequence, and incremented by 1 with each subsequent Item. The last Item in the Sequence shall have an ordinal position equal to the number of Items in the Sequence.

### Note

1. This clause implies that item ordering is preserved during transfer and storage.

2. An IOD or Module Definition may choose to not use this ordering property of a Data Element with VR of SQ. This is simply done by not specifying any specific semantics to the ordering of Items, or by not specifying usage of the referencing of Items by ordering position.

The definition of the Data Elements encapsulated in each Item is provided by the specification of the Data Element (or associated Attribute) of Value Representation SQ. Items in a sequence of Items may or may not contain the same set of Data Elements. Data Elements with a VR of SQ may contain multiple Items but shall always have a Value Multiplicity of one (i.e., a single Sequence).

There are three special SQ related Data Elements that are not ruled by the VR encoding rules conveyed by the Transfer Syntax. They shall be encoded as Implicit VR. These special Data Elements are Item (FFFE,E000), Item Delimitation Item (FFFE,E00D), and Sequence Delimitation Item (FFFE,E0DD). However, the Data Set within the Value Field of the Data Element Item (FFFE,E000) shall be encoded according to the rules conveyed by the Transfer Syntax.

### 7.5.1 Item Encoding Rules

Each Item of a Data Element of Value Representation SQ shall be encoded as a DICOM Standard Data Element with a specific Data Element Tag of Value (FFFE,E000). The Item Tag is followed by a 4 byte Item Length field encoded in one of the following two ways:

1. Explicit Length: The number of bytes (even) contained in the Sequence Item Value (following but not including the Item Length Field) is encoded as a 32-bit unsigned integer value (see Section 7.1). This length shall include the total length of all Data Elements conveyed by this Item. This Item Length shall be equal to 00000000H if the Item contains no Data Set.

2. Undefined Length: The Item Length Field shall contain the value FFFFFFFFH to indicate an undefined Item length. It shall be used in conjunction with an Item Delimitation Data Element. This Item Delimitation Data Element has a Data Element Tag of (FFFE,E00D) and shall follow the Data Elements encapsulated in the Item. No Value shall be present in the Item Delimitation Data Element and its Length shall be 00000000H. An Item containing no Data Set is encoded by an Item Delimitation Data Element only.

The encoder of a Data Set may choose either one of the two ways of encoding. Both ways of encoding shall be supported by decoders of Data Sets. Data Element Tags (FFFF,eeee) are reserved by this standard and shall not be used.

Each Item Value shall contain a DICOM Data Set composed of Data Elements. Within the context of each Item, these Data Elements shall be ordered by increasing Data Element Tag value and appear only once (as Data Set is defined in Section 7.1). There is no relationship between the ordering of the Data Elements contained within an Item and the ordering of the Data Element Tag of SQ Value Representation that contains that Item. One or more Data Elements in an Item may be of Value Representation SQ, thus allowing for recursion.

Data Elements with a group of 0000, 0002 and 0006 shall not be present within Sequence Items.

### Note

The use of Transfer Syntax UID (0002,0010) in particular is forbidden, since were it to differ from the Transfer Syntax of the enclosing Data Set then a change in encoding would be implied, which is not allowed.

Section 7.8 specifies rules for incorporating Private Data Elements into Sequence Items.

### 7.5.2 Delimitation of The Sequence of Items

Delimitation of the last Item of a Sequence of Items, encapsulated in a Data Element of Value Representation SQ, shall be in one of the two following ways:

1. Explicit Length: The number of bytes (even) contained in the Data Element Value (following but not including the Data Element Length Field) is encoded as a 32-bit unsigned integer value (see Section 7.1). This length shall include the total length resulting from the sequence of zero or more items conveyed by this Data Element. This Data Element Length shall be equal to 00000000H if the sequence of Items contains zero Items.

2. Undefined Length: The Data Element Length Field shall contain a Value FFFFFFFFH to indicate an Undefined Sequence length. It shall be used in conjunction with a Sequence Delimitation Item. A Sequence Delimitation Item shall be included after the last Item in the sequence. Its Item Tag shall be (FFFE,E0DD) with an Item Length of 00000000H. No Value shall be present. A Sequence containing zero Items is encoded by a Sequence Delimitation Item only.

The encoder of a Sequence of Items may choose either one of the two ways of encoding. Both ways of encoding shall be supported by decoders of the Sequence of Items.

### Note

The Sequence Delimitation Item Tag (FFFE,E0DD) is different from the Item Delimitation Tag (FFFE,E00D) introduced above in that it indicates the end of a Sequence of Items whose Length was left undefined. If an undefined length Item is the last Item of a Sequence of Items of undefined length, then an Item Delimitation Tag will be followed by a Sequence Delimitation Tag.

For an example of an SQ Data Element of Explicit Length encapsulating Items of Explicit Length see Table 7.5-1.

For an example of an SQ Data Element of Undefined Length encapsulating Items of Explicit Length see Table 7.5-2.

For an example of an SQ Data Element of Undefined Length encapsulating Items of both Explicit and Undefined Length see Table 7.5-3.

Table 7.5-1. Example of a Data Element with Implicit VR Defined as a Sequence of Items (VR = SQ) with Three Items of Explicit Length

Data Element Tag | Data Element Length | Data Element Value
--- | --- | ---
(gggg, eeee) with VR of SQ | 0000 0F00H | First Item | Second Item | Third Item
Item Tag (FFFE, E000) | Item Length 0000 04F8H | Item Value Data Set | Item Tag (FFFE, E000) | Item Length 0000 04F8H | Item Value Data Set | Item Tag (FFFE, E000) | Item Length 0000 04F8H | Item Value Data Set
4 bytes | 4 bytes | 4 bytes | 4 bytes | 04F8H bytes | 4 bytes | 4 bytes | 04F8H bytes | 4 bytes | 4 bytes | 04F8H bytes

Table 7.5-2. Example of a Data Element with Explicit VR Defined as a Sequence of Items (VR = SQ) of Undefined Length, Containing Two Items of Explicit Length

Data Element Tag | Value Representation | Data Element Length | Data Element Value
(gggg, eeee) with VR of SQ | SQ | 0000H Reserved | FFFF FFFFH undefined length | First Item | Second Item | Sequence Delimitation Item
Item Tag (FFFE, E000) | Item Length 98A5 2C68H | Item Value Data Set | Item Tag (FFFE, E000) | Item Length B321 762CH | Item Value Data Set | Seq. Delim. Tag (FFFE, E0DD) | Item Length 0000 0000H
4 bytes | 2 bytes | 2 bytes | 4 bytes | 4 bytes | 4 bytes | 98A5 2C68H bytes | 4 bytes | 4 bytes | B321 762CH bytes | 4 bytes | 4 bytes

### Note

The Data Set within the Item Values in Table 7.5-2 have VRs Explicitly defined.

Table 7.5-3. Example of a Data Element with Implicit VR Defined as a Sequence of Items (VR = SQ) of Undefined Length, Containing Two Items Where One Item is of Explicit Length and the Other Item is of Undefined Length

Data Element Tag | Data Element Length | Data Element Value
(gggg, eeee) with VR of SQ | FFFF FFFFH undefined length | First Item | Second Item | Sequence Delimitation Item
Item Tag (FFFE, E000) | Item Length 0000 17B6H | Item Value Data Set | Item Tag (FFFE, E000) | Item Length FFFF FFFFH undefined length | Item Value Data Set | Item Delim. Tag (FFFE, E00D) | Length 0000 0000H | Seq. Delim. Tag (FFFE, E0DD) | Item Length 0000 0000H
4 bytes | 4 bytes | 4 bytes | 4 bytes | 17B6H bytes | 4 bytes | 4 bytes | undefined length | 4 bytes | 4 bytes | 4 bytes | 4 bytes

### 7.5.3 Sequence Inheritance

An encapsulated Data Set shall only include the Specific Character Set (0008,0005) data element if the Attribute Specific Character Set is defined in the IOD for that sequence of items.

### Note

An encapsulated Data Set does not include the Specific Character Set data element unless the Specific Character Set Attribute is defined as part of the IOD for that sequence.

If an encapsulated Data Set includes the Specific Character Set Attribute, it shall apply only to the encapsulated Data Set. If the Attribute Specific Character Set is not explicitly included in an encapsulated Data Set, then the Specific Character Set value of the encapsulating Data Set applies.

Prev | Up | Next
7.4 Data Element Type | Home | 7.6 Repeating Groups