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,
result TYPE string,
cldescr TYPE REF TO cl_abap_classdescr,
formats TYPE abap_attrdescr_tab,
format LIKE LINE OF formats.
FIELD-SYMBOLS <sign> LIKE cl_abap_format=>s_left.
cldescr ?= cl_abap_classdescr=>describe_by_name( 'CL_ABAP_FORMAT' ).
formats = cldescr->attributes.
DELETE formats WHERE name NP 'S_*' OR is_constant <> 'X'.
LOOP AT formats INTO format.
ASSIGN cl_abap_format=>(format-name) TO <sign>.
result = |{ format-name WIDTH = 20 }| &
|"{ num1 SIGN = (<sign>) }" | &
|"{ num2 SIGN = (<sign>) }" |.
WRITE / result.
ENDLOOP.
Description
The six possible settings for upper/lower case of a character string template are dynamically specified.