ABAP Keyword Documentation →  ABAP − Reference →  Processing Internal Data →  Character String and Byte String Processing →  Expressions and Functions for String Processing →  String Functions →  Examples of String Functions → 

String Functions, shift and substring

This example demonstrates the string functions shift and substring.

Source Code

REPORT demo_shift_substring.

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

CLASS demo IMPLEMENTATION.
  METHOD main.
    DATA result TYPE string VALUE `            oo            `.
    DATA output TYPE TABLE OF string.
    output = VALUE #( ( result  ) ).
    DO strlen( result ) / 2 - 1 TIMES.
      result =
        shift_left(  val = substring( val = result
                                      len = strlen( result  ) / 2 )
                     circular = 1 ) &&
        shift_right( val = substring( val = result
                                      off = strlen( result  ) / 2 )
                     circular = 1 ).
      APPEND result TO output.
    ENDDO.
    DO strlen( result ) / 2 - 1 TIMES.
      result =
        shift_right( val = substring( val = result
                                      len = strlen( result  ) / 2 )
                     circular = 1 ) &&
        shift_left(  val = substring( val = result
                                      off = strlen( result  ) / 2 )
                     circular = 1 ).
      APPEND result TO output.
    ENDDO.
    cl_demo_output=>display( output ).
  ENDMETHOD.
ENDCLASS.

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

Description

The program creates a diamond in a classical list.