[ABAP] In internen Tabellen suchen

Variante 1 (Teilstrings in String suchen)

DATA(lv_string) = |ABAP_ABAP|.
DATA(lv_search) = |BA|.

FIND ALL OCCURRENCES OF lv_search
  IN lv_string
  IGNORING CASE             " case insensitive
  RESULTS DATA(it_results). " TYPE match_result_tab

IF sy-subrc = 0.
  LOOP AT it_results ASSIGNING FIELD-SYMBOL(<r>).
    WRITE: / substring( val = lv_string off = <r>-offset len = <r>-length ).
  ENDLOOP.
ENDIF.

Variante 2 (erstes Auftreten eines String in der Liste)

DATA(it_strings) = VALUE stringtab( ( |ACCESS=true| )
                                    ( |SERVER_NAME='myserver'| )
                                    ( |SERVER_TIMEOUT=600| )
                                    ( |TOKEN='auzt76wwhbud8w8hs8'| ) ).

* erstes Auftreten des Teilstrings 'SERVER_' ermitteln, case-sensitive Suche
FIND FIRST OCCURRENCE OF SUBSTRING 'SERVER_'
  IN TABLE it_strings
  RESPECTING CASE          " case-sensitive
  MATCH LINE DATA(idx)     " Index
  MATCH OFFSET DATA(off)   " Offset
  MATCH LENGTH DATA(len).  " Länge

IF sy-subrc = 0.
  WRITE: / off.
  WRITE: / len.
  WRITE: / it_strings[ idx ].
ENDIF.

Variante 3 (alle gefundenen Strings in der Liste)

DATA(it_strings) = VALUE stringtab( ( |ACCESS=true| )
                                    ( |SERVER_NAME='myserver'| )
                                    ( |SERVER_TIMEOUT=600| )
                                    ( |TOKEN='auzt76wwhbud8w8hs8'| ) ).

FIND ALL OCCURRENCES OF SUBSTRING 'SERVER_'
  IN TABLE it_strings
  RESPECTING CASE           " case-sensitive
  RESULTS DATA(it_results). " Ausgabetabelle

IF sy-subrc = 0.
  LOOP AT it_results ASSIGNING FIELD-SYMBOL(<r>).
    WRITE: / it_strings[ <r>-line ], <r>-offset, <r>-length.
  ENDLOOP.
ENDIF.

Variante 4 (RegEx: alle gefundenen Strings in der Liste)

DATA(it_strings) = VALUE stringtab( ( |ACCESS=true| )
                                    ( |SERVER_NAME='myserver'| )
                                    ( |SERVER_TIMEOUT=600| )
                                    ( |TOKEN='auzt76wwhbud8w8hs8'| ) ).

* Alle Auftreten der Suchbegriffe NAME und TIMEOUT
FIND ALL OCCURRENCES OF REGEX 'NAME|TIMEOUT'
  IN TABLE it_strings
  RESPECTING CASE           " case-sensitive
  RESULTS DATA(it_results). " Ausgabetabelle

IF sy-subrc = 0.
  LOOP AT it_results ASSIGNING FIELD-SYMBOL(<r>).
    WRITE: / it_strings[ <r>-line ], <r>-offset, <r>-length.
  ENDLOOP.
ENDIF.

Links