Show TOC

Syntax documentationLength Locate this document in the navigation structure

Use

You can use the attributes minLength and maxLength to specify a length length 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 length. 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 length.

Serialization

The minLength or length attribute defines the resulting XML value as representing at least the number of characters or bytes defined in length. 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 that is being deserialized contains more characters or bytes than specified by length, the exception CX_SY_CONVERSION_DATA_LOSS is raised (unless only closing blanks or zero bytes in a serialization to 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 length, 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 Note

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

End of the note.
Example

The following transformation performs serializations and deserializations with differing lengths:

Syntax Syntax

  1. <?sap.transform simple?>
  2. <tt:transform xmlns:tt="http://www.sap.com/transformation-templates">
  3.   <tt:root name="ROOT"/>
  4.   <tt:template>
  5.     <tt:serialize>
  6.       <Text>
  7.         <tt:value length="8" ref="ROOT"/>
  8.       </Text>
  9.     </tt:serialize>
  10.     <tt:deserialize>
  11.       <Text>
  12.         <tt:value length="4" ref="ROOT"/>
  13.       </Text>
  14.     </tt:deserialize>
  15.   </tt:template>
  16. </tt:transform>
End of the code.

The following ABAP program can call the transformation:

Syntax Syntax

  1. DATA: text        TYPE string VALUE `1234`,
  2.       xml_xstring TYPE string,
  3.       exc_trafo   TYPE REF TO cx_transformation_error,
  4.       exc_prev    TYPE REF TO cx_root.
  5. CALL TRANSFORMATION ... SOURCE root = text
  6.                         RESULT XML xml_xstring.
  7. cl_abap_browser=>show_xml( xml_string = xml_xstring
  8.                            modal       = 'X' ).
  9. TRY.
  10.     CALL TRANSFORMATION ... SOURCE XML xml_xstring
  11.                             RESULT root = text.
  12.   CATCH cx_st_deserialization_error INTO exc_trafo.
  13.     MESSAGE exc_trafo TYPE 'I' DISPLAY LIKE 'E'.
  14.     IF exc_trafo->previous IS NOT INITIAL.
  15.       exc_prev = exc_trafo->previous.
  16.       MESSAGE exc_prev TYPE 'I' DISPLAY LIKE 'E'.
  17.     ENDIF.
  18. ENDTRY.
End of the code.

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 packed in the exception CX_ST_DESERIALIZATION_ERROR.