Skip to Content
avatar image
Former Member

to check that string contains space

Hi...

I have one char string, If that string contains any space then I want to display a message.

how to check that string contains 'space'.

Regards,

Rohit

Add comment
10|10000 characters needed characters exceeded

  • Follow
  • Get RSS Feed

6 Answers

  • avatar image
    Former Member
    Sep 17, 2008 at 12:47 PM

    IF CA ' '.

    should do the trick

    Add comment
    10|10000 characters needed characters exceeded

  • avatar image
    Former Member
    Sep 17, 2008 at 12:48 PM

    Hi, you can do a small work.

    you can split the char string into substrings at spaces.

    if there is space then it will be splitted and then you can check the sy-subrc.

    if sy-subrc = 0,

    then the char string had some space in it.

    regards

    jayati

    Add comment
    10|10000 characters needed characters exceeded

  • avatar image
    Former Member
    Sep 17, 2008 at 12:55 PM

    Hi ,

    You can use condense also on that string and sy-subrc will be set to 0 if any space is there.

    now check sy-subrc to know if any space is there or not.

    let me know if this is helpful?

    Add comment
    10|10000 characters needed characters exceeded

  • Sep 17, 2008 at 12:57 PM

    Hi

    Do like this.

    DATA: gv_str TYPE STRING VALUE 'HELLO THERE'.
    
    IF gv_str CA SPACE.
      MESSAGE 'ERROR' TYPE 'I'.
    ENDIF.

    Add comment
    10|10000 characters needed characters exceeded

  • avatar image
    Former Member
    Sep 17, 2008 at 12:58 PM

    hi,

    try to do like this

    data: str type string.

    define same way str1 and str2.

    split string at space into str1 str2.

    if sy-surc = 0.

    string contains space.

    else.

    process ur string for ur desired operation.

    endif.

    Add comment
    10|10000 characters needed characters exceeded

  • avatar image
    Former Member
    Sep 17, 2008 at 01:09 PM

    Hi,

    First of all try to SHIFT the string. Suppose your variable is named VAR:

    SHIFT var LEFT DELETING LEADING SPACE.

    IF var CA ' '.

    WRITE:/ 'FIND SPACE'.

    ENDIF.

    Good luck and kind regards,

    MMP.

    Add comment
    10|10000 characters needed characters exceeded