3.4Bloom · ANot started

String templates

Reading depth

What you'll learn

String templates |...{ var }...| replace CONCATENATE and format inline with options like ALPHA, DATE = ISO, NUMBER = USER, and WIDTH/ALIGN/PAD.

  • |...{ var }...| inserts evaluated expressions into literal text.
  • ALPHA = IN/OUT handles alpha (leading-zero) conversion inline.
  • DATE = ISO / TIME = ISO render ISO date and time; NUMBER = USER formats per user settings.

String templates — written |...{ var }...| — replace CONCATENATE for assembling text. Literal text sits between the bars, and each { expression } is evaluated and inserted in place, so you read the final string left to right instead of mentally concatenating fragments and separators.

Inside the braces you can attach formatting options that used to require WRITE TO or conversion exits. ALPHA = IN/OUT applies the alpha conversion (leading-zero handling); DATE = ISO and the matching TIME = ISO render ISO-formatted dates and times; NUMBER = USER formats a number per the user's settings; and WIDTH, ALIGN, and PAD control fixed-width, padded, aligned output.

Because the formatting is declarative and type-safe at the point of use, templates remove a whole class of brittle WRITE-based conversions — and they are the Clean ABAP default, where CONCATENATE and WRITE-for-conversion are flagged as obsolete.

Key points

  • |...{ var }...| inserts evaluated expressions into literal text.
  • ALPHA = IN/OUT handles alpha (leading-zero) conversion inline.
  • DATE = ISO / TIME = ISO render ISO date and time; NUMBER = USER formats per user settings.
  • WIDTH / ALIGN / PAD give fixed-width, aligned, padded output.

Examples

BeforeCONCATENATE with manual separators

Fragment-by-fragment assembly with explicit SEPARATED BY — hard to read and easy to get spacing wrong.

ABAPconcatenate 'Order' lv_id 'total' lv_total
  into lv_msg separated by space.
AfterString template with formatting

ALPHA = OUT strips leading zeros and NUMBER = USER formats per the user; the result reads in order.

ABAPdata(lv_msg) =
  |Order { lv_id alpha = out } total { lv_total number = user }.|.
AfterISO date/time and padded width

ISO formatting and a padded, left-aligned fixed width, all inline.

ABAPdata(lv_iso) = |{ sy-datum date = iso } { sy-uzeit time = iso }|.
data(lv_pad) = |{ lv_name width = 20 align = left pad = '.' }|.

Source notes: clean-core-curriculum §3.4

Ask Claude

Build a prompt from this lesson + your question and open a fresh Claude chat with it pre-filled — handy for adapting a before/after pattern to your own object.