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 →  Description Functions for Character-Type Arguments 

charlen, dbmaxlen, numofchar, strlen, char_off - Length Functions

Length functions exist for character-like arguments with both one unnamed argument and with multiple named arguments.

Other versions: 7.31 | 7.40 | 7.54

Length functions with one unnamed argument


... func( arg ) ...


The following table shows the length functions with one unnamed argument. The arguments arg of all length functions except dbmaxlen are character-like expression positions. The argument of dbmaxlen is a character-like functional operand position. The return code has the type i for all length functions.

Functionfunc Return Value
charlen Length of first character of arg in thecode page used: 1 for non-Unicode single-byte code; 1 or 2 for non-Unicodedouble-byte code; 1 forUnicode with simple Unicode character; 2 for Unicode withsurrogates;
dbmaxlen Maximum length of a string defined in ABAP Dictionary (RAWSTRING, SSTRING, STRING). If the stringis unrestricted, the constant abap_max_db_string_ln or abap_max_db_rawstring_ln from thetype group ABAPis returned. The latter is also returned for the predefined ABAP types string and xstring.
numofchar Number of characters in arg, where closing blanks are not counted indata objects with fixed lengths or in data objects with the type string. If you use a non-Unicode double-byte code, a character that uses two bytes is only counted once.
strlen Number of characters in arg, where closing blanks in data objects withfixed lengths are not counted. They are counted though in data objects with the type string.If you use a non-Unicode double-byte code, a character that uses two bytes is counted twice. The argument can be byte-like outside Unicode programs.

Length function with multiple named arguments


... char_off( val = text  add = pos [off = off] ) ...


The function returns the offset of the character in text that is pos places away from the character in the offset specified in off. The default value for off is 0. text is a character-type expression position. pos and off are numerical expression positions. The return code has the type i.

The value of pos can be positive and negative and has the appropriate number of places on the right or on the left. If pos identifies a positions outside of text, the function returns the value -1. If off is greater than the length of text, an exception of the class CX_SY_RANGE_OUT_OF_BOUNDS is raised.


The function char_off is suitable for finding the correct offsets of characters in non-Unicode double-byte systems.


The following call gets the offset off in a non-Unicode double-byte system, plus the number of bytes for the character located in the position of off.

... char_off( val =  text add = 1 off = off ) ...