Skip to content

ABAP Keyword Documentation →  ABAP - Reference →  Processing Internal Data →  Character String and Byte String Processing →  Expressions and Functions for String Processing →  string_exp - String Expressions →  string_exp - String Templates →  Examples of string templates 

String Templates, asXML Format

The example demonstrates the specification of the format asXML for embedded expressions.

Other versions: 7.31 | 7.40 | 7.54

Source Code

    DATA result TYPE TABLE OF string.

    DATA: i          TYPE i            VALUE -123,
<span class="blue">*         int8       TYPE int8         VALUE -123,</span>
          p          TYPE p DECIMALS 2 VALUE `-1.23`,
          decfloat16 TYPE decfloat16   VALUE `123E+1`,
          decfloat34 TYPE decfloat34   VALUE `-3.140000E+02`,
          f         TYPE f            VALUE `-3.140000E+02`,
          c          TYPE c LENGTH 3   VALUE ` Hi`,
          string     TYPE string       VALUE ` Hello `,
          n          TYPE n LENGTH 6   VALUE `001234`,
          d          TYPE d            VALUE `20020204`,
          t          TYPE t            VALUE `201501`,
          x          TYPE x LENGTH 3   VALUE `ABCDEF`,
          xstring    TYPE xstring      VALUE `456789AB`.

    DEFINE write_template.
      APPEND |{ &1 width = 14  }| &&
             |{ &2 width = 30  }| &&
             |{ &2 xsd   = yes }| TO result.
    END-OF-DEFINITION.

    FORMAT FRAMES OFF.
    write_template `i`          i.
<span class="blue">*   write_template `int8`       int8.</span>
    write_template `p`          p.
    write_template `decfloat16` decfloat16.
    write_template `decfloat34` decfloat34.
    write_template `f`          f.
    APPEND `` TO result.
    write_template `c`          c.
    write_template `string`     string.
    write_template `n`          n.
    write_template `d`          d.
    write_template `t`          t.
    APPEND `` TO result.
    write_template `x`          x.
    write_template `xstring`    xstring.
    cl_demo_output=>display( result ).

Description

This program takes data objects of different types and generates the asXML formats shown under Mapping of Elementary ABAP Types. To make it clearer, the string template is shown in a macro.