Skip to content

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, Numeric Texts

The example demonstrates how the format ALPHA is specified for embedded expressions.

Other versions: 7.31 | 7.40 | 7.54

Source Code

    DATA: textstring       TYPE string,
          resultstring_in  TYPE string,
          resultfield_in   TYPE REF TO data,
          resultstring_out TYPE string,
          resultfield_out  TYPE REF TO data.
    FIELD-SYMBOLS: <resultfield_in>  TYPE data,
                   <resultfield_out> TYPE data.
    CONCATENATE text `` INTO textstring RESPECTING BLANKS.
    CREATE DATA resultfield_in  TYPE c LENGTH length.
    CREATE DATA resultfield_out TYPE c LENGTH length.
    ASSIGN resultfield_in->* TO <resultfield_in>.
    ASSIGN resultfield_out->* TO <resultfield_out>.
    IF width = 0.
      resultstring_in   = |{ textstring ALPHA = IN  }|.
      output( title = `String, IN` text = resultstring_in ).
      <resultfield_in>  = |{ textstring ALPHA = IN  }|.
      output( title = `Field,  IN` text = <resultfield_in> ).
      resultstring_out  = |{ textstring ALPHA = OUT }|.
      output( title = `String, OUT` text = resultstring_out ).
      <resultfield_out> = |{ textstring ALPHA = OUT }|.
      output( title = `Field,  OUT` text = <resultfield_out> ).
    ELSE.
      resultstring_in   = |{ textstring ALPHA = IN  WIDTH = width }|.
      output( title = `String, IN` text = resultstring_in ).
      <resultfield_in>  = |{ textstring ALPHA = IN  WIDTH = width }|.
      output( title = `Field,  IN` text = <resultfield_in> ).
      resultstring_out  = |{ textstring ALPHA = OUT WIDTH = width }|.
      output( title = `String, OUT` text = resultstring_out ).
      <resultfield_out> = |{ textstring ALPHA = OUT WIDTH = width }|.
      output( title = `Field,  OUT` text = <resultfield_out> ).
    ENDIF.

Description

This program demonstrates the use of the formatting option ALPHA with the parameters IN and OUT on a text string textstring. This string always has a length of 20 and its content can be entered on the selection screen. The results of the formatting are assigned to target fields of the types string and c, where the length of the text field can also be entered on the selection screen. The length of the formatting option WIDTH can also be entered. If the length is 0, the formatting option is ignored.