‎2008 Jan 25 9:02 AM
Hi Experts,
How can i search for a symbol in the string.
For example in need to search wheather : is there or not in the following string
Euro:hi all
Thanks
‎2008 Jan 25 9:04 AM
Hi,
use cs statment in the if condition.
eg
if string cs ':'.
.....
endif.
regards,
Santosh Thorat
‎2008 Jan 25 9:05 AM
DATA: text TYPE string VALUE `Roll :over`,
SEARCH text FOR ':'.
The search ends at the first hit and sy-fdpos is set to the offset of the found pattern or to the word in the search area. If the pattern is not found, then sy-fdpos is set to value 0.
‎2008 Jan 25 9:08 AM
Hi,
To search a character field for a particular pattern, use the SEARCH statement as follows:
SEARCH <c> FOR <str> <options>.
The statement searches the field <c> for <str> starting at position <n1>. If successful, the return code value of SY-SUBRC is set to 0 and SY-FDPOS is set to the offset of the string in the field <c>. Otherwise, SY-SUBRC is set to 4.
<str>----
Function
<pattern>--
Trailing blanks are ignored.
.<pattern>.----
Searches for <pattern>. Trailing blanks are not ignored.
*<pattern>----
A word ending with <pattern> is sought.
<pattern>*----
Searches for a word starting with <pattern>.
Words are separated by blanks, commas, periods, semicolons, colons, question marks, exclamation marks, parentheses, slashes, plus signs, and equal signs.
<option> in the SEARCH FOR statement can be any of the following:
ABBREVIATED
Searches the field <c> for a word containing the string in <str>. The characters can be separated by other characters. The first letter of the word and the string <str> must be
the same.
STARTING AT <n1>
Searches the field <c> for <str> starting at position <n1>. The result SY-FDPOS refers to the offset relative to <n1> and not to the start of the field.
ENDING AT <n2>
Searches the field <c> for <str> up to position <n2>.
AND MARK
If the search string is found, all the characters in the search string (and all the characters in between when using ABBREVIATED) are converted to upper case.
Ex.
DATA STRING(30) VALUE 'This is a little sentence.'.
WRITE: / 'Searched', 'SY-SUBRC', 'SY-FDPOS'.
ULINE /1(26).
SEARCH STRING FOR 'X'.
WRITE: / 'X', SY-SUBRC UNDER 'SY-SUBRC',
SY-FDPOS UNDER 'SY-FDPOS'
SEARCH STRING FOR 'itt '.
WRITE: / 'itt ', SY-SUBRC UNDER 'SY-SUBRC',
SY-FDPOS UNDER 'SY-FDPOS'
SEARCH STRING FOR '.e .'.
WRITE: / '.e .', SY-SUBRC UNDER 'SY-SUBRC',
SY-FDPOS UNDER 'SY-FDPOS'.
SEARCH STRING FOR '*e'.
WRITE: / '*e ', SY-SUBRC UNDER 'SY-SUBRC',
SY-FDPOS UNDER 'SY-FDPOS'.
SEARCH STRING FOR 's*'.
WRITE: / 's* ', SY-SUBRC UNDER 'SY-SUBRC',
SY-FDPOS UNDER 'SY-FDPOS'.
To just compare if there is string like that, then do like this
IF STR CS ':'.
ENDIF.
Regards,
Satish