How do string templates work, and what can you put inside the curly brackets?
Say your answer out loud first.
Practise another way
A string template is written between pipes, like |Total: { amount }|. Whatever is inside the braces is an ABAP expression, a variable, a method call or even COND, and its result is converted to a string.
I can add formatting options such as DATE = ISO or NUMBER = USER. It replaces CONCATENATE and WRITE TO. The result is always type string.
For plain text without braces I use a backquote literal instead, because a template is evaluated at runtime.
A string template builds a string from literal text and embedded expressions. Anything in { ... } must be convertible to string: data objects, functional method calls, built-in functions, even conditional expressions.
DATA(order_id) = '0000004711'.
DATA(amount) = CONV decfloat34( '1234.5' ).
DATA(msg) = |Order { order_id ALPHA = OUT } costs { amount NUMBER = USER } EUR\n| &&
|Status: { COND #( WHEN amount > 1000 THEN `high` ELSE `normal` ) }|.
DATA(plain) = `Plain text`.
Formatting options follow the expression inside the braces. Common ones: DATE = ISO | USER | RAW, TIME, TIMESTAMP, TIMEZONE, NUMBER, CURRENCY, ALPHA = OUT | IN, CASE = UPPER | LOWER.
They replace the old WRITE ... TO and conversion exit calls. Options can also be given dynamically.
Control and escape characters
\nis a line feed,\ta tab,\r\ncarriage return plus line feed.- To print a pipe, a brace or a backslash, escape it with a backslash:
\|,\{,\},\\.
Join templates with &&, as above, to keep long lines readable.
Pitfalls
- A template with no embedded expression is still evaluated at runtime. The cheat sheet recommends a backquote literal for pure text.
- Backquote literals have type string and keep trailing blanks; quote literals
'...'are type c. - The result is a string. If the target is a fixed-length field, it is cut to fit.
- Do not build SQL or dynamic code by gluing user input into a template. Use ABAP SQL host variables or the escape methods of CL_ABAP_DYN_PRG.
Release: string templates are available in ABAP Cloud and in all current releases.
Gives the syntax, three formatting options, the escape rules and the point that text without braces should be a literal.
Describes templates as 'a nicer concatenate' and does not mention formatting options or escaping.
Using a template for static text and thinking the result is char: it is always a string, and a template without braces still costs runtime.
- How do you print a literal pipe or brace?
- How is |{ x }| different from `x`?
- How would you format a date as ISO inside a template?
- Can you call a method inside the braces?
2 official pages. Confidence: medium. Checked 21 Nov 2026.
- Official page Backs the answer.
- Official page Backs the answer.