Skip to content

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 

Character String Functions, cmax, cmin and segment

The example demonstrates the extremum functions cmax and cmin as well as the segment function segment.

Other versions: 7.31 | 7.40 | 7.54

Source Code

    DATA:  txt TYPE string,
           max TYPE string,
           min TYPE string,
           msg TYPE string.
    txt = `one two three four five six seven eight nine ten`.
    max = | |.
    min = ||.
    DO.
      TRY.
          max = cmax( val1 = max
                      val2 = segment( val   = txt
                                     index = sy-index sep = ` ` ) ).
          min = cmin( val1 = min
                      val2 = segment( val   = txt
                                     index = sy-index sep = ` ` ) ).
        CATCH cx_sy_strg_par_val.
          EXIT.
      ENDTRY.
    ENDDO.
    cl_demo_output=>display(
      |Maximum is { max } and minimum is { min }| ).

Description

The program determines the minimum and the maximum segment of a character string with reference to the current code page.