ABAP Search string: FIND Statement

  Define Data


The FIND Statement searches for whether a specific character is included, and if so, returns the position of that character.

Sample Code:Only Search


In this example, the FIND instruction is used to check if there is a character ‘FIND ‘from the variable: V_TEXT. System variable: SY-SUBRC returns ‘0’ if it can be found, and ‘4’ if it cannot be found. Describe each process after branching with IF statement etc. I can do things.

Sample Code:Return search position


In this example, the FIND command is used, and if the character “FIND” is found in the variable: V_TEXT, the position and length found will be returned. As in the previous case, the system variable: SY-SUBRC is checked, and if found, only the found character is cut out and output to the screen.

Sample Code:Multiple search


In this example, the FIND instruction is used to retrieve all the characters’FIND ‘from the variable: V_TEXT. In the example, the character FIND can be found twice, so the variable V_CNT is set to 2.

FIRST OCCURRENCES will be one search, ALL OCCURRENCES will be all searches. Although omitted in the above two examples, FIRST OCCURRENCES is used if the description is omitted.

Sample Code:Store result into internal table


Honestly, I can’t think of a use, but it is possible to store the result in an internal table by specifying an internal table after RESULTS. The first line stores the position of the first character found, the number of digits, etc., and the second line stores the position of the next character found, the number of digits, etc. You can loop through the internal table and process each character.

Sample Code:Search string from internal table


An internal table can also be specified as a search target as in the above example. It can be used as an internal table after reading the file. However, it is also possible to search for each line by looping, so it may be a syntax to use in consideration of performance and simplification of logic.


This time I introduced the FIND command, but there should be many requirements such as “I want to do this” only when there is a specific description from the characters. When dealing with XML etc., it is often used because it is often judged by the name of the tag. Also, each text (set on orders or purchase slips) can be used as a syntax for extracting a text input by the user and searching for a specific character when processing the text.