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, Algebraic Sign

The example demonstrates the specification of the algebraic sign format for embedded expressions.

Other versions: 7.31 | 7.40 | 7.54

Source Code

    DATA:  num1    TYPE i VALUE -10,
           num2    TYPE i VALUE +10,
           results TYPE TABLE OF string,
           formats TYPE abap_attrdescr_tab,
           format  LIKE LINE OF formats.

    FIELD-SYMBOLS <sign> LIKE cl_abap_format=>s_left.

    formats =
      CAST cl_abap_classdescr(
             cl_abap_classdescr=>describe_by_name( 'CL_ABAP_FORMAT' )
             )->attributes.
    DELETE formats WHERE name NP 'S_*' OR is_constant <> 'X'.

    LOOP AT formats INTO format.
      ASSIGN cl_abap_format=>(format-name) TO <sign>.
      APPEND |{ format-name WIDTH = 16 }  | &
             |"{ num1 SIGN = (<sign>) }"  | &
             |"{ num2 SIGN = (<sign>) }"  | TO results.
    ENDLOOP.
    cl_demo_output=>display( results ).

Description

The six possible settings for upper/lower case of a character string template are dynamically specified.