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
TYPES result TYPE TABLE OF string WITH EMPTY KEY.
cl_demo_output=>write(
VALUE result(
FOR j = 1 UNTIL j > strlen( sy-abcde )
( |{ substring( val = sy-abcde len = j )
WIDTH = j + 4 }<---| ) ) ).
cl_demo_output=>display(
VALUE result(
FOR j = 1 UNTIL j > strlen( sy-abcde )
( |{ substring( val = sy-abcde len = j )
WIDTH = strlen( sy-abcde ) / 2 } <---| ) ) ).
Description
Two iteration expressions loops perform the predefined
function substring
for the system field sy-abcde
in an embedded expression of a string template. The first iteration calculates the length from the length
of the substring plus a fixed value. The second iteration sets the length (constantly) as half the length of the full string and is ignored for longer substring accesses.