Programs for various string operations.
CONCATENATE – Combines 2 or more strings into one string.
Example-1:
Report z01
DATA: s1(10) VALUE 'Hello',
s2(10) VALUE 'ABAP',
s3(10) VALUE 'World',
result1(30),
result2(30).
CONCATENATE s1 s2 s3 INTO result1.
CONCATENATE s1 s2 s3 INTO result2 SEPARATED BY '-'.
WRITE / result1.
WRITE / result2.
Output:
SPLIT – Splits a string into 2 or more smaller strings.
Example-2:
Report z02
DATA: s1(10), s2(10), s3(10),
source(20) VALUE 'abc-def-ghi'.
SPLIT source AT '-' INTO s1 s2 s3.
WRITE:/ 'S1 - ', s1.
WRITE:/ 'S2 - ', s2.
WRITE:/ 'S3 - ', s3.
Output:
SEARCH – Searches for a sub string in main string. If found then sy-subrc is set to 0, else set to 4.
Example-3:
Report z03
DATA: string(30) VALUE 'SAP ABAP Development',
str(10) VALUE 'ABAP'.
SEARCH string FOR str.
IF sy-subrc = 0.
WRITE:/ 'Found'.
ELSE.
WRITE:/ 'Not found'.
ENDIF.
Output:
REPLACE – Replaces the sub string with another sub string specified, in the main string. If replaced successfully then sy-subrc is set to 0, else set to 4.
Example-4:
Report z04
DATA: string(30) VALUE 'SAP ABAP Development',
str(10) VALUE 'World'.
REPLACE 'Development' WITH str INTO string.
WRITE:/ string.
Output: