SAP ST TT ATTRIBUTE



Get Example source ABAP code based on a different SAP table
  


• attribute ABAP_ST_ELEMENT

ABAP_ST - tt:attribute, Non-Literal Attributes

ABAP_SYNTAX
< tt:attribute name='attr' $[ref='node'$]>
...
< /tt:attribute>

What does it do?
The non-literal attributes of an ST program are defined using the statement tt:attribute. A non-literal attribute is assigned to an attribute of an XML element of the XML data. In serializations, the content of the non-literal attribute sets the value of the attribute in the XML data. In deserializations, the value of the attribute in the XML data is read and processed.
This statement can be specified one or more times within a literal XML element before its subelements. Each statement defines a non-literal attribute of the current XML element with the name attr specified in name. The optional attribute ref sets the current node node for the context of the non-literal attribute attr.

Serializing Non-Literal Attributes
During serialization, the name attr of the attribute is written together with =' or =' into the definition of the current XML element. After that, the content of tt:attribute is serialized and the result is written after attr=' or attr=' . The result of the serialization must not be structured, which means that it must not contain subelements. Finally, the attribute is completed with ' or '.



Latest notes:

In valid XML data, the names of the attributes of an XML element must be unique. For performance reasons, this is not checked in serializations of non-literal attributes. Instead, it must be done by the application developers themselves.
NON_V5_HINTS
ABAP_HINT_END

Deserializing Non-Literal Attributes
In deserializations, the name of the attribute is compared to the attributes of the current XML element in the source XML data. The order of the attributes is not relevant. The deserialization fails if the attribute does not exist in the inbound stream. After that, the value of the attribute is deserialized according to the content of tt:attribute and the closing character is compared. The deserialization fails if not the entire content of the attribute is deserialized. Surplus attributes of the inbound stream are ignored.

Special Form of Non-Literal Attributes

ABAP_SYNTAX
< tt:attribute name='attr' value-ref='node'
$[map=...$] />

What does it do?
This special form of non-literal attributes combines the tt:value statement with the general syntax shown above.
This special form is a short form of:
< tt:attribute name='attr'>
< tt:value ref='node' $[map=...$] />
< /tt:attribute>
This allows the simple formulation of the frequent use case of expressing an elementary value as the content of an attribute.

ABAP_EXAMPLE_VX5
In the ST program DEMO_ST_ATTRIBUTE1 below, the values of the data roots ROOT1 and ROOT2 are serialized as values of the attributes attr1 and attr2 of element X or are deserialized from them.
TRNS DEMO_ST_ATTRIBUTE1
If the values Text1 and Text2 are passed to ROOT1 and ROOT2, the result of a serialization is: < X attr1='Text1' attr2='Text2'>
< Y > ... < /Y>
< /X>
To deserialize the above result again, the ST program DEMO_ST_ATTRIBUTE2 below is used, even though the sequence of the attributes is different.
TRNS DEMO_ST_ATTRIBUTE2
ABAP_EXAMPLE_END