String Templates

A string template is enclosed by two characters ”|” and creates a character string. Literal text consists of all characters that are not in braces {}.

" Inline Declaration for lv_var
DATA(lv_var) = 1.

" String Template for building the string
DATA(lv_str) = | There can be more than { lv_var }.|.

"Result: lv_str = "There can be more than 1."

ALPHA

The ALPHA expressions calls the ALPHA Input/Output and therefor can be used to add/remove leading zeros.

DATA: lv_matnr TYPE matnr.

lv_matnr = 4711.
WRITE: |{ lv_matnr  ALPHA = IN }|.
"Result: 000000000000004711

WRITE: |{ lv_matnr  ALPHA = OUT }|.
"Result: 4711

The ALIGN expression aligns the string and outputs a new string. The optional WIDTH can specify the width of the new character und the PAD can be used to insert a padding character. Most importantly space characters are not omitted, which means that you might have to use an ALPHA expression to get rid of those first.

DATA: lv_matnr TYPE matnr,
      lv_pad   TYPE char1.

lv_pad = 'X'. "Padding Character

lv_matnr = 4711.
WRITE:/ |.{ lv_matnr ALIGN = LEFT WIDTH = 18 PAD = lv_pad }.|.
"Result: .             4711X.

WRITE:/ |.{ lv_matnr  ALIGN = RIGHT WIDTH = 18 }.|.
"Result: .              4711.

WRITE:/ |.{ |{ lv_matnr ALPHA = OUT }| ALIGN = LEFT PAD = lv_pad }.|.
"Result: .4711              .