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 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.
Source Code
REPORT demo_cmax_cmin.
CLASS demo DEFINITION.
PUBLIC SECTION.
CLASS-METHODS main.
ENDCLASS.
CLASS demo IMPLEMENTATION.
METHOD main.
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 }| ).
ENDMETHOD.
ENDCLASS.
START-OF-SELECTION.
demo=>main( ).
Description
The program determines the minimum and the maximum segment of a character string with reference to the current code page.