SAP NetWeaver AS ABAP Release 740, ©Copyright 2014 SAP AG. All rights reserved.
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.
Source Code
REPORT demo_string_template_width.
CLASS demo DEFINITION.
PUBLIC SECTION.
CLASS-METHODS main.
ENDCLASS.
CLASS demo IMPLEMENTATION.
METHOD main.
DATA result TYPE TABLE OF string.
DO 26 TIMES.
APPEND |{ substring( val = sy-abcde len = sy-index )
WIDTH = sy-index + 4 }<---| TO result.
ENDDO.
cl_demo_output=>write( result ).
CLEAR result.
DO 26 TIMES.
APPEND |{ substring( val = sy-abcde len = sy-index )
WIDTH = strlen( sy-abcde ) / 2 } <---| TO result.
ENDDO.
cl_demo_output=>display( result ).
ENDMETHOD.
ENDCLASS.
START-OF-SELECTION.
demo=>main( ).
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.