SAP NetWeaver AS ABAP Release 740, ©Copyright 2014 SAP AG. All rights reserved.
ABAP Keyword Documentation → ABAP − Reference → Obsolete Language Elements → Obsolete character string and byte string processing →Obsolete Syntax
SEARCH dobj FOR pattern [IN {CHARACTER|BYTE} MODE]
[STARTING AT p1] [ENDING AT p2]
[ABBREVIATED]
[AND MARK].
Extras:
1. ... IN {CHARACTER|BYTE} MODE
2. ... [STARTING AT p1] [ENDING AT p2]
3. ... ABBREVIATED
4. ... AND MARK
Effect
This statement searches the data object dobj according to the search pattern specified in pattern. The additions allow you 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-like data object dobj is defined: Enclosed by non-alphanumerical separators.
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 | Meaning |
0 | The search pattern was found in dobj. |
4 | The search pattern was found in dobj. |
Notes
... IN {CHARACTER|BYTE} MODE
Effect
The optional IN {CHARACTER|BYTE} MODE addition determines whether
character string or byte string processing
is carried out. If the addition is not specified, character string processing is carried out. Depending
on the processing type, dobj and pattern must be either character-like or byte-type.
... [STARTING AT p1] [ENDING AT p2]
Effect
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:
Note
The term "position" is not equivalent to the term "offset". A byte or a character on position 1 has an offset of 0.
... ABBREVIATED
Effect
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.
Example
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
Effect
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.
Example
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. In other words, 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.