2006 Oct 23 1:50 PM
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
2006 Oct 23 1:54 PM
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
2006 Oct 23 1:53 PM
Hi,
Use STRLEN to calculate length. If helpful pl reward.
Cheers
2006 Oct 23 1:54 PM
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
2006 Oct 23 1:54 PM
Hello,
l_f_length = strlen( l_f_char ).
Hope this helps,
Michael
2006 Oct 23 1:54 PM
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
2006 Oct 23 1:57 PM
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.
2006 Oct 23 1:59 PM
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