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 → 

Character String Templates, Alignments, and Padding

This example demonstrates how to specify an alignment and how to pad embedded expressions.

Source Code

REPORT demo_string_template_align_pad.

CLASS demo DEFINITION.
  PUBLIC SECTION.
    CLASS-METHODS main.
ENDCLASS.

CLASS demo IMPLEMENTATION.
  METHOD main.

    DATA pad TYPE c LENGTH 1.
    cl_demo_input=>request( CHANGING field = pad ).

    cl_demo_output=>new(
      )->write( |{ 'Left'   WIDTH = 20 ALIGN = LEFT   PAD = pad }<---|
      )->write( |{ 'Center' WIDTH = 20 ALIGN = CENTER PAD = pad }<---|
      )->write( |{ 'Right'  WIDTH = 20 ALIGN = RIGHT  PAD = pad }<---|
      )->display( ).

  ENDMETHOD.
ENDCLASS.

START-OF-SELECTION.
  demo=>main( ).

Description

The alignment of three character string templates is declared statically. The character used to pad the superfluous places can be entered using an input field.