Start of Content Area

Syntax documentation Length  Locate the document in its SAP Library structure

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 lengthattribute 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 until it is of the specified length, for example 0x00, 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 in a deserialization to a data object with type c are affected).

 

 

Deserialization

The minLength attribute is ignored by deserialization. The maxLength or lengthattribute 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

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.

 

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
                           modal       = 'X' ).


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

 

 

 

 

 

 

 

 

 

 

 

End of Content Area