‎2007 May 11 7:51 AM
Hi,
can anyone explain me how this code is working and what is the use of CS.
DATA: text1(30) TYPE c VALUE 'This is the first text',
text2(30) TYPE c VALUE 'This is the second text',
text3(30) TYPE c VALUE 'This is the third text',
string(5) TYPE c VALUE 'eco'.
IF text1 CS string.
WRITE / 'Condition 1 is fulfilled'.
ELSEIF text2 CS string.
WRITE / 'Condition 2 is fulfilled'.
ELSEIF text3 CS string.
WRITE / 'Condition 3 is fulfilled'.
ELSE.
WRITE / 'No condition is fulfilled'.
ENDIF.
regards
vivek
‎2007 May 11 7:54 AM
Hi,
this will return 'Condition 2 is fulfilled'.
The CS command stands for contains string.
<b>
CS (Contains String):
c1 contains the character string c2.
Trailing blanks in c1 and c2 are ignored if the respective field is of type C.
An empty string c2 (i.e., only blanks with type C, or empty string with type STRING) is included in any string c1, including the empty string itself. On the other hand, there is no non-empty string c2 included in an empty string c1.
If the result of the comparison is positive, the system field SY-FDPOS contains the offset of the first character of c2 in c1.
If the result of the comparison is negative, the system field SY-FDPOS contains the length of c1.
The comparison is not case-sensitive.
Examples:
'ABCDE' CS 'CD' is true; SY-FDPOS = 2.
'ABCDE' CS 'XY' is false; SY-FDPOS = 5.
'ABAAA' CS 'AB ' is true; SY-FDPOS = 0.
' ABC' CS ' AB' is true; SY-FDPOS = 1.
'ABC DEF' CS ' ' is true; but: SY-FDPOS = 0,
since ' ' is interpreted as a trailing blank and is thus
ignored.
</b>
‎2007 May 11 7:53 AM
Hi Vivek,
CS IS NOTHING BUT CONTAIN STRING.
i text1 value contains string ,it will return true else false.
now output is 'no condition....'.
‎2007 May 11 7:54 AM
Hi,
this will return 'Condition 2 is fulfilled'.
The CS command stands for contains string.
<b>
CS (Contains String):
c1 contains the character string c2.
Trailing blanks in c1 and c2 are ignored if the respective field is of type C.
An empty string c2 (i.e., only blanks with type C, or empty string with type STRING) is included in any string c1, including the empty string itself. On the other hand, there is no non-empty string c2 included in an empty string c1.
If the result of the comparison is positive, the system field SY-FDPOS contains the offset of the first character of c2 in c1.
If the result of the comparison is negative, the system field SY-FDPOS contains the length of c1.
The comparison is not case-sensitive.
Examples:
'ABCDE' CS 'CD' is true; SY-FDPOS = 2.
'ABCDE' CS 'XY' is false; SY-FDPOS = 5.
'ABAAA' CS 'AB ' is true; SY-FDPOS = 0.
' ABC' CS ' AB' is true; SY-FDPOS = 1.
'ABC DEF' CS ' ' is true; but: SY-FDPOS = 0,
since ' ' is interpreted as a trailing blank and is thus
ignored.
</b>
‎2007 May 11 7:54 AM
Hi,
CS means contains string.
So the code is checking, if the value of string (eco) is used in text1, 2 and 3.
It will be found in text2 (sECOnd line).
Regards
Frank
‎2007 May 11 7:55 AM
Hi ,
sorry I didnt saw that string.
string having value 'eco'.that is there in text2,so the output is 'condition2.....
‎2007 May 11 7:58 AM
Hi,
CS means contain String.
CS Contains String: True if the content of operand2 is contained in operand1. Upper/lower case is not taken into account, trailing blanks of the left operand are taken into account. If operand1 is of type string and initial, or of type c and contains only blank characters, the logical expression is false, unless operand2 is also of type string and initial, or of type c and only contains blank characters. In this case the logical expression is always true. If the result of the comparison is true, sy-fdpos contains the offset of operand2 in operand1. If the result of the comparison is negative, sy-fdpos contains the length of operand1.
Regards,
Ajith V