How to do search for a string on another string or internal table in ABAP programming. Here is the keyword for that SEARCH. It is really a useful keyword in ABAP provides any type of search with simple additions in the statement. If the search is successful the system field SY-SUBRC value will be zero ( if failure it will be 4 ). We can do the search in a string or internal table with search term.
Basic Syntax
- SEARCH string_field FOR search_term.
- SEARCH itab FOR search_term.
Getting the position of search term
- When we search a string on another string the system field SY-FDPOS will store the position value ( offset ) where the occurrence of search term found.
- When we search in internal table the system field SY-TABIX will contain the table index ( line number ) where the search term found.
Additions used with this statement are
- ABBREVIATED
Don’t need to be exactly the search term . It will return success even if there is another characters between the search term characters.
For example “SEARCH ‘123456’ FOR ‘14’ ABBREVIATED” will return success - STARTING AT n1 ( specify a position of main string from which search should start)
- ENDING AT n2 ( specify a position of main string from which search should end)
- AND MARK ( To show the entire string in Capital letter , where the search term found )
See a sample source code and output with SEARCH statement