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 →  Processing Functions for Character-Like Arguments 

cmax, cmin - Character-Like Extreme Value Functions

Other versions: 7.31 | 7.40 | 7.54

Syntax Forms

... cmax|cmin( val1 = text1  val2 = text2
              [ val3 = text3] ... [val9 = text9] ) ...

Effect

These functions return the value of the biggest or the smallest of the character-like arguments text1, text2, ... passed. The content of the arguments is compared from left to right in the evaluation. The first different character from the left decides which operand is bigger or smaller on the basis of the sequence in the code page used.

At least two arguments, text1 and text2, and a maximum of nine arguments must be passed. Here, the optional input parameters val3 through val9 must be filled in ascending order without gaps.

The return code has the type string.


Notes

  • The extreme functions nmax and nmin can be used to determine numeric extreme values.
  • Character-like extreme functions, like numeric extreme functions, can be traced back to the equivalent control structures using relational operators. Remember that, unlike with the usual ABAP comparison rules, shorter arguments of fixed lengths are not padded to the length of longer arguments by entering blanks.
  • As with comparisons with relational operators, the current locale is not significant when determining the extreme values.

Example

The example demonstrates how the smallest and largest letters of a random set are found, represented here by the rows of an internal table. Of course, in this case the result can also be achieved by sorting the internal table, which is done here for verification.

TYPES itab TYPE TABLE OF char1 WITH EMPTY KEY. 

DATA(rnd) = cl_abap_random_int=>create( 
  seed = CONV i( sy-uzeit ) min = 0 max = strlen( sy-abcde ) - 1 ). 

DATA(itab) = VALUE itab( FOR i = 1 UNTIL i > 9 
                        LET off = rnd->get_next( ) IN 
                         ( sy-abcde+off(1) ) ). 

DATA(min) =  cmin( val1 = itab[ 1 ] 
                   val2 = itab[ 2 ] 
                   val3 = itab[ 3 ] 
                   val4 = itab[ 4 ] 
                   val5 = itab[ 5 ] 
                   val6 = itab[ 6 ] 
                   val7 = itab[ 7 ] 
                   val8 = itab[ 8 ] 
                   val9 = itab[ 9 ] ). 

DATA(max) =  cmax( val1 = itab[ 1 ] 
                   val2 = itab[ 2 ] 
                   val3 = itab[ 3 ] 
                   val4 = itab[ 4 ] 
                   val5 = itab[ 5 ] 
                   val6 = itab[ 6 ] 
                   val7 = itab[ 7 ] 
                   val8 = itab[ 8 ] 
                   val9 = itab[ 9 ] ). 

SORT itab BY table_line. 

ASSERT min = itab[ 1 ]. 
ASSERT max = itab[ lines( itab ) ].

Executable Example

String functions cmax, cmin, and segment.