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, Length

This example demonstrates how to specify a length for embedded expressions.

Other versions: 7.31 | 7.40 | 7.54

Source Code

    DATA result TYPE string.
    DO 26 TIMES.
      result = |{ substring( val = sy-abcde len = sy-index )
                  WIDTH = sy-index + 4 }<---|.
      WRITE / result FRAMES OFF.
    ENDDO.
    SKIP.
    DO 26 TIMES.
      result = |{ substring( val = sy-abcde len = sy-index )
                  WIDTH = strlen( sy-abcde ) / 2 } <---|.
      WRITE / result FRAMES OFF.
    ENDDO.

Description

Two DO loops perform the predefined function substring for the system field sy-abcde in an embedded expression of a string template. The first loop calculates the length from the length of the substring plus a fixed value. The second loop sets the length (constantly) as half the length of the full string. This means that this length is ignored if a longer substring is accessed.