Skip to content

ABAP Keyword Documentation →  ABAP - Reference →  Data Interfaces and Communication Interfaces →  ABAP and XML →  Transformations for XML →  ST - Simple Transformations →  ST - Serialization and Deserialization →  ST - Transformation of ABAP Values →  ST - tt:value, Elementary Data Objects 

ST - length, minLength, maxLength, Length Specification

Other versions: 7.31 | 7.40 | 7.54

Syntax


... length="len" ... 
... minLength="len" ...
... maxLength="len" ...

Effect

You can use the attributes length, minLength and maxLength to specify a length len for tt:value, tt:write, and tt:read. This restricts the length of the data passed in serializations and deserializations.

You can specify positive whole numbers for len. Lengths can be specified for data nodes or variables with the ABAP types c, x, string, and xstring. Any other data types ignore any lengths specified.

Specifying the length attribute always affects tt:value and tt:write as if minLength and maxLength were executed at the same time with the value specified for len.

Serialization

The minLength or length attribute defines the resulting XML value as representing at least the number of characters or bytes defined in len. If a passed value contains fewer characters, or bytes, it is filled to the right with blank spaces or "0x00" until it is of the specified length and an XML value is created. The maxLength or length attribute defines the maximum number of characters or bytes that can be passed. If the XML value being serialized contains more characters or bytes than specified by len, the exception CX_ST_CONSTRAINT_ERROR is raised (unless only closing blanks or zero bytes in a serialization of a data object with type c or x are affected).

Deserialization

The minLength attribute is ignored by deserialization. The maxLength or length attribute defines the maximum number of characters or bytes expected in the XML value. If the XML value that is being deserialized contains more characters or bytes than specified by len, the exception CX_ST_CONSTRAINT_ERROR is raised (unless only closing blanks or zero bytes in a deserialization to a data object with type c or x are affected).


Note

Exception CX_ST_CONSTRAINT_ERROR cannot be caught directly during the call of CALL TRANSFORMATION, instead it is wrapped in CX_ST_SERIALIZATION_ERROR or CX_ST_DESERIALIZATION_ERROR.


Example

The following transformation performs serializations and deserializations with differing lengths:

<?sap.transform simple?>
<tt:transform
  xmlns:tt="http://www.sap.com/transformation-templates">
  <tt:root name="ROOT"/>
  <tt:template>
    <tt:serialize>
      <Text>
        <tt:value length="8" ref="ROOT"/>
      </Text>
    </tt:serialize>
    <tt:deserialize>
      <Text>
        <tt:value length="4" ref="ROOT"/>
      </Text>
    </tt:deserialize>
  </tt:template>
</tt:transform>

The following ABAP program can call the transformation:

DATA: text        TYPE string VALUE `1234`,
      xml_xstring TYPE string,
      exc_trafo   TYPE REF TO cx_transformation_error,
      exc_prev    TYPE REF TO cx_root.

CALL TRANSFORMATION ... SOURCE root = text
                        RESULT XML xml_xstring.

cl_abap_browser=>show_xml( xml_string = xml_xstring ).
TRY.
    CALL TRANSFORMATION ... SOURCE XML xml_xstring
                            RESULT root = text.
  CATCH cx_st_deserialization_error INTO exc_trafo.
    MESSAGE exc_trafo TYPE 'I' DISPLAY LIKE 'E'.
    IF exc_trafo->previous IS NOT INITIAL.
      exc_prev = exc_trafo->previous.
      MESSAGE exc_prev TYPE 'I' DISPLAY LIKE 'E'.
    ENDIF.
ENDTRY.

The result of the transformation is:

<Text>1234    </Text>

Since more characters are passed by the deserialization than expected, the exception CX_ST_CONSTRAINT_ERROR is raised, which is wrapped in the exception CX_ST_DESERIALIZATION_ERROR.