Searching and Replacing of String in SAP ABAP
3.1 Searching for Substrings of String in SAP ABAP :
You can check if a substring exists within a string using the CS and NS keywords.
Example 1:
DATA: str1(30) VALUE 'SAP ABAP',
str2(30) VALUE 'SAP'.
SEARCH str1 FOR str2.
IF sy-subrc =0.
WRITE:/ 'YES FOUND'.
ELSE
WRITE:/ 'NOT FOUND'.
ENDIF.
Output:
YES FOUND
3.2 Replacing Substrings of String in SAP ABAP:
To replace occurrences of a substring within a string, you can use the REPLACE statement.
DATA: str1(30) VALUE 'GFG WORLD',
str2(30) VALUE 'GFG'.
REPLACE 'SAP' WITH str2 INTO str1
WRITE: / str1
Output:
SAP WORLD
SAP ABAP | Mastering String Manipulation
String manipulation is a fundamental skill in SAP ABAP programming language, and it’s crucial for dealing with various types of data processing, text formatting, and building dynamic content. This article aims to guide you through mastering string manipulation in SAP ABAP, providing insights, best practices, and code examples.
Table of Content
- Introduction to String Manipulation in SAP ABAP
- Basic String Operations in SAP ABAP
- 1. Concatenation of String in SAP ABAP:
- 2. Substrings of String in SAP ABAP:
- 3. Searching and Replacing of String in SAP ABAP:
- 4. Formatting Strings of String in SAP ABAP
- 5. Advanced Operations of String in SAP ABAP
- Conclusion