ABAP string length. The ABAP language has several expressions for dealing with the length of ABAP strings. Let’s analyze these features in more detail. All string manipulation functions have one unnamed argument and are used by ABAP developers. Using examples, I will analyze how to get the length of a string in various ways.
STRLEN ABAP example
I created simple ABAP program with using New ABAP syntax: inline declaration ABAP. You can use this ABAP code to test the string constructions work:
1 2 3 4 5 6 7 8 9 10 11 |
DATA(lv_str) = |abap-blog.com|. DATA(lv_strlen) = strlen( lv_str ). DATA(lv_charlen) = charlen( lv_str ). DATA(lv_dbmaxlen) = dbmaxlen( lv_str ). DATA(lv_numofchar) = numofchar( lv_str ). BREAK-POINT. |
As a result of executing this ABAP code, we will get the following values in variables:

I will describe the work of each design in more detail:
- strlen (abap) – This function returns the number of characters in the abap argument. Objects of type string respect trailing spaces, unlike other types. STRLEN ABAP is the most commonly used function for getting the length of a string.
- numoflen(abap) – This function will return the number of characters in the abap argument, ignoring trailing spaces for arguments of any type.
- harlen (abap) – Returns the length of the first character of the abap argument in the code page being used.
- dbmaxlen (abap) – Returns the maximum length of a string as described in the ABAP dictionary. If it is a string with unlimited length, the function returns the constant abap_max_db_string_ln or abap_max_db_rawstring_ln. Depending on the type of the passed argument.
ABAP string length example:
Examples of using STRLEN ABAP at work
- At the input from another system, we can get several types of documents in the same field and we can distinguish documents only by the length of the number. Therefore, the string length function in this case will help to unambiguously determine which document it is. This will write each document number in the correct field.
- When loading from Excel, we may receive a field of various lengths at the input, but, for example, it is important for us that it be no more than 33 characters long, otherwise we need to ignore this line as an error or display ABAP message on it. In this case, the length of the ABAP string will help weed out the unwanted ones.
- We need to get a part of the string ABAP, for example, from 11 to 21 characters, but these characters are not in each of the strings, some have a length of 10. If we refer to the 11th character of a string that has a length of 10 without checking, we will get an error. To prevent an error, you need to get and check the length of the ABAP string.
Other articles related to this: