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

strlen problem

Former Member
0 Likes
1,417

hi

when i try to do strlen for

DATA lv_str2 TYPE string.
DATA lv_length2_str TYPE n.

lv_str2 = 'USER_AND_P' .

lv_length2 = strlen( lv_str2 ).


lv_length2_str = lv_length2.

lv_length2 = 10

and when i try to do the

lv_length2_str = lv_length2 stentment i dont get any value to lv_length2_str

wahy ?

Regards

chirs

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
885

Hi,

type n acts like a c..you need to define leght..



DATA lv_str2 TYPE string.
DATA lv_length2_str      TYPE n.  "old statement
 DATA lv_length2_str(3) TYPE n.  "new statemnet ..pass 3 in the bracket
      "or
DATA lv_length2 TYPE INT2. 

 lv_str2 = 'USER_AND_P' .
 
 lv_length2 = strlen( lv_str2 ).
 
 
 lv_length2_str = lv_length2.

Prabhudas

5 REPLIES 5
Read only

Former Member
0 Likes
886

Hi,

type n acts like a c..you need to define leght..



DATA lv_str2 TYPE string.
DATA lv_length2_str      TYPE n.  "old statement
 DATA lv_length2_str(3) TYPE n.  "new statemnet ..pass 3 in the bracket
      "or
DATA lv_length2 TYPE INT2. 

 lv_str2 = 'USER_AND_P' .
 
 lv_length2 = strlen( lv_str2 ).
 
 
 lv_length2_str = lv_length2.

Prabhudas

Read only

0 Likes
885

HI Prabhu,

it's work but why?

regards

Chris

Read only

0 Likes
885

When declared as TYPE N without the length specification, it will take the default length as only one. But the length you got was 10. So it must be storing only 1. When you declared it with length as 3, its taking the whole value as 10. Thats the difference

Read only

GauthamV
Active Contributor
0 Likes
885

Try this.


DATA lv_str2 TYPE string.
DATA lv_length2_str TYPE i.
DATA lv_length2 TYPE i.

lv_str2 = 'USER_AND_P' .

lv_length2 = strlen( lv_str2 ).


lv_length2_str = lv_length2.

write: lv_length2_str.

Read only

bpawanchand
Active Contributor
0 Likes
885
DATA lv_length2_str TYPE n.

Because you have declared the type as NUMERIC of size 1, so may be while you are trying to assign the varibale then you will not get the right value.