FIND

Basic form


FIND p IN [SECTION OFFSET off LENGTH len OF] text.

Extras:


1. ... IGNORING CASE.



2. ... RESPECTING CASE.



3. ... IN BYTE MODE.



4. ... IN CHARACTER MODE.



5. ... MATCH OFFSET off.



6. ... MATCH LENGTH len.




Effect

Searches the target field text for the search string p. If p is a type C field, the system searches only for the occupied length at runtime.

If you use the SECTION OFFSET off LENGTH len OF addition, the system searches in text only from the position off in the length len. The keyword SECTION expects the parameter OFFSET or LENGTH or both. The default value for OFFSET = 0. The default for LENGTH = -1, where -1 marks the remaining length of the target field.

Example

DATA: text TYPE STRING.
text = 'Everyone knows this'.
FIND 'know' IN text.

The search was successful. The field sy-subrc is set to 0.

System values

sy-subrc = 0

The search string was found in the target field.


sy-subrc = 4

The search string was not found in the target field.


sy-subrc = 8

This return value occurs only in systems with a multi-byte code page. The content of the search string in this case is an invalid multi-byte string.



Notes

Depending on whether byte or character string processing is carried out, the operands can only be byte-type or character-type (see Overview).See Character-Type Data Objects.

The syntax check performed in an ABAP Objects context is stricter than in other ABAP areas.See You can only use character-type fields in string processing.

In some cases, the syntax rules that apply to Unicode programs are different than those for non-Unicode programs.See String Processing.

Addition 1

... IGNORING CASE.

Effect

Use this addition to make the system ignore the case of characters.

Example

DATA:
  c    TYPE STRING,
  p(2) TYPE C.

c = 'Everyone knows this'.
p = 'NO'.
FIND p IN c IGNORING CASE.

After the search, sy-subrc = 0.



Addition 2

... RESPECTING CASE.

Effect

The system matches the case of the string p and the target field c.

Example

DATA:
  c    TYPE STRING,
  p(2) TYPE C.

c = 'Everyone knows this'.
p = 'NO'.
FIND p IN c RESPECTING CASE.

After the search, sy-subrc  = 4.

Note

The RESPECTING CASE addition is the default setting, so you can omit it.



Addition 3

... IN BYTE MODE.

Unless both p and the target field c have the type X or XSTRING, the system returns a runtime error. This addition cannot be used with either IGNORING CASE or RESPECTING CASE.



Addition 4

... IN CHARACTER MODE.

This addition is optional. It is the default setting.



Addition 5

... MATCH OFFSET off.

Effect

If the search string p is found in the target field c, the position in the string where it first occurred is stored in off.

Example

DATA:
  c    TYPE STRING,
  p(2) TYPE C,
  off  TYPE I.

c = 'Everyone knows this'.
p = 'ne'.
FIND p IN c MATCH OFFSET off.

After the search, off = 7 and sy-subrc = 0.



Addition 6

... MATCH LENGTH len.

Effect

The length of the search string p is stored in the field len.

Example

DATA:
  c    TYPE STRING,
  p(2) TYPE C,
  off  TYPE I,
  len  TYPE I.

c = 'Everyone knows this'.
p = 'ne'.
FIND p IN c MATCH OFFSET off MATCH LENGTH len.

After the search, sy-subrc = 0, off = 7, len = 2.

Exceptions

Catchable Exceptions

CX_SY_RANGE_OUT_OF_BOUNDS

Related

SEARCH