Skip to Content

Archived discussions are read-only. Learn more about SAP Q&A

String: How do I check if the character belongs to one of the characters?

I have a string. I want to know if the 1st characters of the string belongs to one of the character set or not.

For example, the character set is A, B, E, Z, T.

Right now, what I did was:

 IF str+0(1) EQ 'A' OR str+0(1) EQ 'B' OR
        str+0(1) EQ 'E' OR str+0(1) EQ 'Z' OR ......

Is there a shorter way to do it?

Please help and I will reward you.

Tags:
Former Member
Former Member replied

Hi,

Use CA operator

data : string1 type TABLE OF string WITH HEADER LINE.

APPEND 'ABCDEF' to string1.
APPEND 'BBCDEF' to string1.
APPEND 'CBCDEF' to string1.
APPEND 'DBCDEF' to string1.
APPEND 'EBCDEF' to string1.

LOOP AT string1.
  check string1+0(1) CA 'ABE'.
  write: / sy-tabix,'found'.
ENDLOOP.

Cheers,

jose.

0 View this answer in context

Helpful Answer

by
Not what you were looking for? View more on this topic or Ask a question