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.

SAP ABAP | Mastering String Manipulation

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

Similar Reads

Introduction to String Manipulation in SAP ABAP

String manipulation involves performing operations on strings, which are sequences of characters. In SAP ABAP, strings are typically used to store and process textual information, such as names, addresses, or any other text-based data. Mastering string manipulation is essential for tasks like data cleansing, formatting, and creating dynamic outputs....

Basic String Operations in SAP ABAP

Here are a few basic string operations in SAP ABAP:...

1. Concatenation of String in SAP ABAP:

Concatenation of strings in SAP ABAP involves combining multiple strings into a single string. The CONCATENATE statement is commonly used for this purpose....

2. Substrings of String in SAP ABAP:

Extracting a portion of a string is known as creating a substring. The SUBSTRING statement allows you to get a specific part of a string based on the starting position and length....

3. Searching and Replacing of String in SAP ABAP:

3.1 Searching for Substrings of String in SAP ABAP :...

4. Formatting Strings of String in SAP ABAP

4.1 Uppercase and Lowercase of String in SAP ABAP:...

5. Advanced Operations of String in SAP ABAP

5.1 Splitting Strings of String in SAP ABAP:...

Conclusion

Mastering string manipulation in SAP ABAP is essential for effectively working with textual data. Whether you need to concatenate strings, search for substrings, or apply advanced regular expressions, a solid understanding of string manipulation techniques will significantly enhance your ABAP programming skills. Regular practice and experimentation with various string operations will help you become proficient in handling diverse data scenarios in SAP ABAP....