ABAP predefined length functions STRLEN and NUMOFCHAR

 Many a time when traversing a text, you would want to know the actual length of the text. in today's predefined function series post, I wanted to welcome you with ABAP length predefined functions: strlen, numofchar.

While strlen is pretty well-known, numofchar is relatively unknown so I thought we should take a look at its feature and usage as well.

Let's dive right in.

STRLEN:

Syntax: STRLEN( arg ).

Features:

 It returns the number of characters in arg.

 If the data object is of fixed length then trailing blanks are ignored.

 If the data object is of type string, then trailing blanks are also counted.

Example:

NUMOFCHAR:

Syntax: NUMOFCHAR( arg ).

Features:

 It returns the number of characters in arg.

 Trailing blanks are ignored regardless of the data object type.

Example:

As you would have noticed from the examples, 

numofchar always ignores the trailing blanks whereas strlen behaves differently according to the data object, you might say that numofchar treats the input as ABAP text literal and strlen treats the input as either string literal or text literal depending upon the data object( string or char).

I hope you keep that in mind and use this info in your day-to-day work.

Popular posts from this blog

ABAP convert internal table to excel (.xlsx) format and Send email or download

ABAP read excel(.XLSX) file to internal table in ABAP using CL_FDT_XL_SPREADSHEET

Application Logging in ABAP