Skip to Content
author's profile photo Former Member
Former Member

length of a string

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

Add a comment
10|10000 characters needed characters exceeded

Assigned Tags

Related questions

6 Answers

  • Best Answer
    author's profile photo Former Member
    Former Member
    Posted on Oct 23, 2006 at 12: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

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Oct 23, 2006 at 12:53 PM

    Hi,

    Use STRLEN to calculate length. If helpful pl reward.

    Cheers

    Add a comment
    10|10000 characters needed characters exceeded

  • Posted on Oct 23, 2006 at 12:54 PM

    Hello,

    l_f_length = strlen( l_f_char ).

    Hope this helps,

    Michael

    Add a comment
    10|10000 characters needed characters exceeded

  • Posted on Oct 23, 2006 at 12: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

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Oct 23, 2006 at 12: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.

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Oct 23, 2006 at 12: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

    Add a comment
    10|10000 characters needed characters exceeded

Before answering

You should only submit an answer when you are proposing a solution to the poster's problem. If you want the poster to clarify the question or provide more information, please leave a comment instead, requesting additional details. When answering, please include specifics, such as step-by-step instructions, context for the solution, and links to useful resources. Also, please make sure that you answer complies with our Rules of Engagement.
You must be Logged in to submit an answer.

Up to 10 attachments (including images) can be used with a maximum of 1.0 MB each and 10.5 MB total.