Skip to content

ABAP Keyword Documentation →  ABAP − Reference →  Data Interfaces and Communication Interfaces →  ABAP and XML →  Transformations for XML →  asXML - Canonical XML Representation →  asXML - Mapping of ABAP Data Types 

asXML - Mapping of Enumerated Types

The asXML representation of enumerated types is used in XSL transformations and in Simple Transformations. In both cases, the elementary values with enumerated types or the elementary components of complex structures are converted in accordance with this mapping.

  • When the enumerated variable is deserialized, the XML representation must correspond to the name of an enumerated value of the enumerated type in uppercase letters. The enumerated variable is then assigned the enumerated value in the base type. If the XML representation does not correspond to a name, this results in the exception CX_SY_CONVERSION_NO_ENUM_VALUE, which is usually wrapped in CX_TRANSFORMATION_ERROR.

Other versions: 7.31 | 7.40 | 7.54


Example

The example shows the serialization of an enumerated variable planet to XML. Then, the name of the value VENUS is replaced by JUPITER and the result is deserialized to planet. planet then contains the value 4. A deserialization of the XML value earth, on the other hand, fails, because the name has to be specified in uppercase letters.

TYPES: 
  BEGIN OF ENUM planet, 
    mercury, 
    venus, 
    earth, 
    mars, 
    jupiter, 
    saturn, 
    uranus, 
    neptune, 
  END OF ENUM planet. 

DATA planet TYPE planet VALUE venus. 

DATA(out) = cl_demo_output=>new( ). 

DATA(xml) = ``. 
CALL TRANSFORMATION id SOURCE planet = planet 
                      RESULT XML xml. 
out->write_xml( xml ). 

REPLACE `VENUS` IN xml WITH `JUPITER` RESPECTING CASE. 
TRY. 
    CALL TRANSFORMATION id SOURCE XML xml 
                           RESULT planet = planet. 
    out->write( planet ). 
  CATCH cx_transformation_error INTO DATA(exc). 
    out->write( exc->previous->get_text( ) ). 
ENDTRY. 

REPLACE `JUPITER` IN xml WITH `earth` RESPECTING CASE. 
TRY. 
    CALL TRANSFORMATION id SOURCE XML xml 
                          RESULT planet = planet. 
    out->write( planet ). 
  CATCH cx_transformation_error INTO exc. 
    out->write( exc->previous->get_text( ) ). 
ENDTRY. 

out->display( ).