SEARCH dobj FOR pattern [IN {BYTE|CHARACTER}} MODE]
[STARTING AT p1] [ENDING AT p2]
[ABBREVIATED]
[AND MARK].
1. ... IN {BYTE|CHARACTER} MODE
2. ... [STARTING AT p1] [ENDING AT p2]
3. ... ABBREVIATED
4. ... AND MARK
This statement searches the data object dobj according to the search pattern specified in pattern. The additions allow to search subareas, shortened patterns and marking of places of finding.
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.
Search Pattern in pattern
The pattern in pattern can have the following forms (Upper or lower case is irrelevant in character chain processing):
A word in a character-type data object dobj is defined: 1. Enclosed by non-alphanumerical separators. 2. Located at beginning or end of a row.
During string processing with data objects dobj of fixed length, the closing empty character is taken into account, while with pattern it is not. If pattern is an empty string or is of type c, d, n or t and only contains empty characters, the search is never successful.System Fields
sy-subrc | Relevance |
0 | The search pattern was found in dobj. |
4 | The search pattern was not found in dobj. |
... IN {BYTE|CHARACTER} MODE
The optional addition IN { BYTE | CHARACTER } MODE determines whether
byte- or character chain processing will be executed. If the
addition is not specified, character chain processing will be executed. Depending on the processing
type, dobj and pattern must be either byte- or character-type.
... [STARTING AT p1] [ENDING AT p2]
With the additions STARTING AT and ENDING AT, you can restrict the search to a subarea of the data object dobj. For p1 and p2, data objects of the data objects of the data type i are expected.
The value in p1 specifies the first, the value in p2 specifies the last of the positions to be searched. Without specifiying STARTING AT p1, the data object dobj is searched from the first position to position p2. Without specifying ENDING AT p2, dobj is searched from position p1 to the end.
If the addition STARTING AT is specified, then sy-fdpos is set to the offset of the find location minus the offset of p1, provided that the search was successful. In the following cases, the search is not carried out, and sy-subrc is set to 4:
The term "position" is not equivalent to the term "offset". A byte or a character on position 1 has an offset of 0.
... ABBREVIATED
With the addition ABBREVIATED, you can specify a shortened
pattern in pattern. This addition is only possible with
character chain processing. A word is searched in dobj
that begins with the same character as the pattern in pattern
and contains the remaining characters of "pattern" in the same sequence, but at otherwise completely arbitrary positions of the word.
Search for an abbreviated pattern with SEARCH. The FIND statement has the same result and also specifies the find location.
DATA: text TYPE string VALUE `Roll over Beethoven`,
moff TYPE i,
mlen TYPE i.
SEARCH text FOR 'bth' ABBREVIATED.
FIND REGEX '\<(b[a-z0-9]*t[a-z0-9]*h[a-z0-9]*)\>' IN text
IGNORING CASE
MATCH OFFSET moff
MATCH LENGTH mlen.
... AND MARK
With the addition AND MARK, a character sequence found
in dobj or a found word, is converted to upper case. This
addition is only possible with character chain processing, and you are only allowed to specify changeable data objects for dobj when you use it.
The first two SEARCH-statements have the same effect. They find the first blank in text and set sy-fdpos to the value 4. The third SEARCH-statement finds the word "Beethoven" in the search area (beginning from position 6 of text ), sets sy-fdpos to the value 5, i.e., the offset of the place of finding in the search area and changes the content of text to "Roll over BEETHOVEN" .
DATA: text TYPE string VALUE `Roll over Beethoven`,
pos TYPE i.
SEARCH text FOR '. .'.
SEARCH text FOR ` `.
IF sy-subrc = 0.
pos = sy-fdpos + 2.
SEARCH text FOR 'bth' STARTING AT pos
ABBREVIATED AND MARK.
ENDIF.