‎2009 Jan 16 12:07 PM
I am encountering with a strange problem. I am checking for a relational operator after a 'IF' field. for eg
if a correct.
a jh b -
> incorrect ( because jh is not a relational operator)
My code is
if not itab-line CA '=,,<,>,<=,>=,eq,ne,lt,gt,le,ge,co,cn,ca,na,cs,ns,cp,np,between,is,in,not'.
RAISE INVALID_IF.
endif.
This code was working fine (raising exception) when I test it with special characters ( !,@,# etc ) but as soon as I tested it with characters it is passing all the test without raising exception for eg
a gth b, c ytl 100 --> it should ideally raise exception as gth,ytl are not relational operator....but still it is passing all the test.
What should I use instead of CA??
Edited by: priya singh on Jan 16, 2009 1:08 PM
‎2009 Jan 16 1:48 PM
CA '=,,<,>,<=,>=,eq,ne,lt,gt,le,ge,co,cn,ca,na,cs,ns,cp,np,between,is,in,not'
You're making the mistake to assume each operator in '=,,<,>,<=,>=,eq,ne,lt,gt,le,ge,co,cn,ca,na,cs,ns,cp,np,between,is,in,not' is validated, but it's not.
However, each separate character in that string is checked
So if your string would contain a single character from '=,,<,>,<=,>=,eq,ne,lt,gt,le,ge,co,cn,ca,na,cs,ns,cp,np,between,is,in,not' the check will pass your test as well.
You can test it out yourself:
data: lv_test1 type string,
lv_test2 type string.
lv_test1 = '>>'.
lv_test2 = 'gtttt'.
if lv_test1 ca '>,gt'.
write:/ 'contains operator'.
else.
write:/ 'does not contain operator'.
endif.
if lv_test2 ca '>,gt'.
write:/ 'contains operator'.
else.
write:/ 'does not contain operator'.
endif.So i don't think you will be able to do your check with CO CP CS and such.
A possible solution might be to create an internal table with each operator in an entry.;And then to check if you string holds one of the entries in your internal table.
Just an example:
types: begin of ty_operators,
value type string,
end of ty_operators,
begin of ty_split,
value(30) type c,
end of ty_split.
data: gv_text1(30) type c,
gv_text2(30) type c,
it_operators type table of ty_operators,
wa_operators type ty_operators,
it_split type table of ty_split,
wa_split type ty_split.
clear: it_operators[].
wa_operators-value = '='. append wa_operators to it_operators.
wa_operators-value = '<'. append wa_operators to it_operators.
wa_operators-value = '>'. append wa_operators to it_operators.
wa_operators-value = '<='. append wa_operators to it_operators.
wa_operators-value = '>='. append wa_operators to it_operators.
wa_operators-value = 'eq'. append wa_operators to it_operators.
* and so on for all your operators
gv_text1 = 'IF >>bla eq blabla'.
split gv_text1 at space into table it_split.
loop at it_split into wa_split.
read table it_operators into wa_operators with key value = wa_split-value.
if sy-subrc eq 0.
write: / gv_text1, 'contains operator', wa_operators-value.
endif.
endloop.
gv_text2 = 'IF bla eqeq blabla'.
split gv_text2 at space into table it_split.
loop at it_split into wa_split.
read table it_operators into wa_operators with key value = wa_split-value.
if sy-subrc eq 0.
write: / gv_text2, 'contains operator', wa_operators-value.
endif.
endloop.Maybe there are other solutions, but you just have to try harder to find them.
‎2009 Jan 16 12:10 PM
Hi priya,
Use contanis pattren 'CP'.
it may solve u r pblm.
Thanks,
‎2009 Jan 16 12:12 PM
Why dont you use
if not itab-line CN '=,,<,>,<=,>=,eq,ne,lt,gt,le,ge,co,cn,ca,na,cs,ns,cp,np,between,is,in,not'.
RAISE INVALID_IF.
endif.
Instead of
if not itab-line CA '=,,<,>,<=,>=,eq,ne,lt,gt,le,ge,co,cn,ca,na,cs,ns,cp,np,between,is,in,not'.
RAISE INVALID_IF.
endif.
Try it.
Regards,
Madan Mohan.
‎2009 Jan 16 1:02 PM
Hello Priya,
These !,@,# relational operator is Exception in SAP.
you can simply check this by writing a program for validation, your program will never work for these.
Infact I was searching its answer since long time but did not get any result and conclusion. if you get then please update this thread.
Have a Nice Day,
Regards,
Sujeet
‎2009 Jan 16 1:19 PM
Hi ,
The comparison operators takes into account evn the leading and triling blank values when comparision.
Contains Any: True, if operand1 contains at least one character from operand2.
Please refer the below link and choose a suitable operator:
http://help.sap.com/saphelp_nw70/helpdata/en/fc/eb3516358411d1829f0000e829fbfe/frameset.htm
Regards,
Radhika.
‎2009 Jan 16 1:48 PM
CA '=,,<,>,<=,>=,eq,ne,lt,gt,le,ge,co,cn,ca,na,cs,ns,cp,np,between,is,in,not'
You're making the mistake to assume each operator in '=,,<,>,<=,>=,eq,ne,lt,gt,le,ge,co,cn,ca,na,cs,ns,cp,np,between,is,in,not' is validated, but it's not.
However, each separate character in that string is checked
So if your string would contain a single character from '=,,<,>,<=,>=,eq,ne,lt,gt,le,ge,co,cn,ca,na,cs,ns,cp,np,between,is,in,not' the check will pass your test as well.
You can test it out yourself:
data: lv_test1 type string,
lv_test2 type string.
lv_test1 = '>>'.
lv_test2 = 'gtttt'.
if lv_test1 ca '>,gt'.
write:/ 'contains operator'.
else.
write:/ 'does not contain operator'.
endif.
if lv_test2 ca '>,gt'.
write:/ 'contains operator'.
else.
write:/ 'does not contain operator'.
endif.So i don't think you will be able to do your check with CO CP CS and such.
A possible solution might be to create an internal table with each operator in an entry.;And then to check if you string holds one of the entries in your internal table.
Just an example:
types: begin of ty_operators,
value type string,
end of ty_operators,
begin of ty_split,
value(30) type c,
end of ty_split.
data: gv_text1(30) type c,
gv_text2(30) type c,
it_operators type table of ty_operators,
wa_operators type ty_operators,
it_split type table of ty_split,
wa_split type ty_split.
clear: it_operators[].
wa_operators-value = '='. append wa_operators to it_operators.
wa_operators-value = '<'. append wa_operators to it_operators.
wa_operators-value = '>'. append wa_operators to it_operators.
wa_operators-value = '<='. append wa_operators to it_operators.
wa_operators-value = '>='. append wa_operators to it_operators.
wa_operators-value = 'eq'. append wa_operators to it_operators.
* and so on for all your operators
gv_text1 = 'IF >>bla eq blabla'.
split gv_text1 at space into table it_split.
loop at it_split into wa_split.
read table it_operators into wa_operators with key value = wa_split-value.
if sy-subrc eq 0.
write: / gv_text1, 'contains operator', wa_operators-value.
endif.
endloop.
gv_text2 = 'IF bla eqeq blabla'.
split gv_text2 at space into table it_split.
loop at it_split into wa_split.
read table it_operators into wa_operators with key value = wa_split-value.
if sy-subrc eq 0.
write: / gv_text2, 'contains operator', wa_operators-value.
endif.
endloop.Maybe there are other solutions, but you just have to try harder to find them.
‎2009 Jan 16 2:04 PM
Try using the SYNTAX-CHECK command. I have constructed this from the ABAP online help:
DATA: itab TYPE TABLE OF string,
mess TYPE string,
lin TYPE i,
wrd TYPE string,
dir TYPE trdir.
APPEND 'PROGRAM dummy.' TO itab.
APPEND 'DATA a type c.' TO itab.
APPEND 'DATA b type c.' TO itab.
APPEND 'IF a GHE b.' TO itab. "example, change as desired
APPEND 'ENDIF.' TO itab.
SYNTAX-CHECK FOR itab MESSAGE mess LINE lin WORD wrd
DIRECTORY ENTRY dir.
Check SY-SUBRC and the contents of "mess" to find out if your operator is supported.
Thomas
‎2009 Jan 16 2:06 PM