03-24-2008 4:04 AM
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.
03-24-2008 4:17 AM
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.
03-24-2008 4:17 AM
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.
03-24-2008 4:19 AM
Hi,
Try
str+0(1) CA 'ABEZT'.
CA Contains Any:
True, if operand1 contains at least one character from operand2. Upper/lower case and trailing blanks are taken into account for both operands. If operand1 or operand2 is of type string and initial, the logical expression is always false. If result of the comparison is positive, sy-fdpos contains the offset of the first character in operand1 that is also contained in operand2. If the result of the comparison is negative, sy-fdpos contains the length of operand1.
Hope this helps.
Thanks,
Balaji
03-24-2008 4:25 AM
Hi,
say your charector set is
v_vharset = 'A, B, E, Z, T'.
your string is
v_string = 'Elephant'.
1. IF v_string+0(1) CA 'A,B,E,Z,T' .
ELSE.
ENDIF.
2.
IF v_string+0(1) IN 'A,B,E,Z,T' .
ELSE.
ENDIF.