Application Development and Automation Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

Differnce between STRLEN and NUMOFCHAR

Former Member
0 Likes
2,274

Hello All,

Can anybody tell the difference between STRLEN and NUMOFCHAR.

Which is better to use and why to use the better one.

Can anybody explain me in detail. I will reward you with points.

Thanks,

Karan

8 REPLIES 8
Read only

Former Member
Read only

Former Member
0 Likes
1,324

Hi,

Function STRLEN works only with character type field and returns the length in characters.

Function NUMOFCHAR returns the number of characters in a string or a character-type field.

This function behaves like STRLEN in single byte code page.

Regards

Sandipan

Read only

Former Member
0 Likes
1,324

hi,

STRLEN:

Returns the length of a character-type field in characters. With c-fields, as opposed to fields with type STRING, only the actual length used is relevant because blanks at the end are not counted.

NUMOFCHAR.

Returns the number of characters of a character-type field. In Unicode systems and non-Unicode systems with single-byte codepages, this function behaves like STRLEN. In non-Unicode systems with double-byte codepages, characters that take up more than one byte are counted with length 1, while STRLEN returns length 2.

just refer ABAPDOCU for more information.

reward if useful,

regards,

bharathi.

Read only

Former Member
0 Likes
1,324

Hi,

NUMOFCHAR : It gives the total length of the variable irrespect of

the number of chars in the cvariable.

Ex : v_num(30). means "30" is thge result.

STRLEN : It gives the nuber of chars present in that variable.

Ex: v_num(30) TYPE c value 'abcdef'.

result is '6'

Read only

0 Likes
1,324

Hello MuraliKrishna,

Thanks for the reply. Can you tell me which is better to use.

Thanks,

Karan

Read only

0 Likes
1,324

Hi,

it depends.

Some times in program you need to find the length of the variable,based on that you have to caluculate some thing, that time you have to use STRLEN().Here if you use NUMOFCHAR() your result will be wrong.

So use based on requirement use above functions.

Read only

0 Likes
1,324

Hi Murali,

In a scenario if we want to find the length by using STRLEN each character takes 2 bytes. But for NUMOFCHAR it takes only 1 byte.

Can you tell me an example for STRLEN which takes 1 character as 2 bytes.

thanks,

Karan