Application Development 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: 

length of a string

Former Member
0 Kudos
127

hi,

A simple question:

How do you find the length of an string defined as characters (CHAR).

I want to check if a certain variable has the maximum length of 5.

thanks

1 ACCEPTED SOLUTION

Former Member
0 Kudos
85

Hi Baran

do you mean in declaration or at runtime.

In Runtime you can use

data i type i

data test(20).

I = strlen( test ).

Regards, Dieter

6 REPLIES 6

Former Member
0 Kudos
85

Hi,

Use STRLEN to calculate length. If helpful pl reward.

Cheers

Former Member
0 Kudos
86

Hi Baran

do you mean in declaration or at runtime.

In Runtime you can use

data i type i

data test(20).

I = strlen( test ).

Regards, Dieter

MichaelTe
Contributor
0 Kudos
85

Hello,

l_f_length = strlen( l_f_char ).

Hope this helps,

Michael

venkata_ramisetti
Active Contributor
0 Kudos
85

HI,

YOu can use STRLEN to get string length.

Check the below example from sap docu.

DATA: I1 TYPE I, I2 TYPE I, I3 TYPE I,

F1 TYPE F, F2 TYPE F,

WORD1(10), WORD2(20),

XSTR TYPE XSTRING,

ITAB TYPE TABLE OF SPFLI.

...

F1 = ( I1 + EXP( F2 ) ) * I2 / SIN( 3 - I3 ).

COMPUTE F1 = SQRT( SQRT( ( I1 + I2 ) * I3 ) + F2 ).

I1 = STRLEN( WORD1 ) + STRLEN( WORD2 ).

I2 = STRLEN( XSTR ).

IF LINES( ITAB ) > 0.

...

ENDIF.

Thanks,

Ramakrishna

Former Member
0 Kudos
85

Baran

To get the string length at runtime without the trailing spaces is using STRLEN.

llen = strlen( lval ).

but in case you need the define lenght of the field lval...you can use DESCRIBE command.

DESCRIBE FIELD lval LENGTH llen.

Former Member
0 Kudos
85

Hi,

data v_str(10) type c value 'test'.

v_len type i

v_len = strlen(v_str) .

if v_len > 5.

write 'string',v_len.

endif.

Regards

amole