ABAP provides various string operators to manipulate and compare strings efficiently. Below is a categorized list of commonly used string operators in ABAP.


1. Concatenation Operators

Using && (ABAP 7.40 and later)

Concatenates two or more strings.

DATA: lv_string TYPE string.
lv_string = 'Hello' && ' ' && 'ABAP'.
WRITE: lv_string. " Output: Hello ABAP

Using CONCATENATE

Concatenates multiple strings with an optional separator.

DATA: lv_string TYPE string.
CONCATENATE 'Hello' 'ABAP' INTO lv_string SEPARATED BY space.
WRITE: lv_string. " Output: Hello ABAP

2. Comparison Operators

ABAP supports comparison operators to compare strings.

OperatorDescriptionExample
=Equal to'ABAP' = 'ABAP'
<Less than'A' < 'B'
>Greater than'B' > 'A'
<>Not equal'ABAP' <> 'JAVA'
<=Less than or equal'A' <= 'A'
>=Greater than or equal'B' >= 'A'
DATA: lv_str1 TYPE string VALUE 'ABAP',
lv_str2 TYPE string VALUE 'SAP'.
IF lv_str1 < lv_str2.
WRITE: 'ABAP comes before SAP'.
ELSE.
WRITE: 'SAP comes before ABAP'.
ENDIF.

3. Substring & Searching Operators

Using FIND (Check if substring exists)

Finds a substring within a string.

DATA: lv_string TYPE string VALUE 'Hello ABAP',
lv_substring TYPE string VALUE 'ABAP',
lv_pos TYPE i.
FIND lv_substring IN lv_string MATCH OFFSET lv_pos.
IF sy-subrc = 0.
WRITE: 'Found at position', lv_pos.
ELSE.
WRITE: 'Not found'.
ENDIF.

Using CS (Contains)

Checks if a string contains a substring.

DATA(lv_string) = 'Hello ABAP'.
IF lv_string CS 'ABAP'.
WRITE: 'Substring found!'.
ENDIF.

Using CP (Pattern Matching with Wildcards)

Checks if a string follows a certain pattern.

DATA(lv_string) = 'ABAP123'.
IF lv_string CP 'ABAP*'.
WRITE: 'Pattern matches!'.
ENDIF.

4. Checking String Properties

Check if a String is Numeric (IS NUMERIC)

Checks if a string contains only numbers.

DATA: lv_string TYPE string VALUE '12345'.
IF lv_string IS NUMERIC.
WRITE: 'The string is numeric'.
ELSE.
WRITE: 'Not a numeric string'.
ENDIF.

Check if String Starts or Ends with a Substring

ABAP does not have a direct STARTSWITH or ENDSWITH function, but you can use FIND or offsets.

Check if String Starts with a Specific Value

DATA(lv_string) = 'ABAP Programming'.
IF lv_string+0(4) = 'ABAP'.
WRITE: 'Starts with ABAP!'.
ENDIF.

Check if String Ends with a Specific Value

DATA(lv_string) = 'SAP ABAP'.
IF lv_string+strlen( lv_string ) - 4(4) = 'ABAP'.
WRITE: 'Ends with ABAP!'.
ENDIF.

5. String Modification Operators

Convert to Uppercase (TRANSLATE ... TO UPPER CASE)

DATA(lv_string) = 'hello abap'.
TRANSLATE lv_string TO UPPER CASE.
WRITE: lv_string. " Output: HELLO ABAP

Convert to Lowercase (TRANSLATE ... TO LOWER CASE)

DATA(lv_string) = 'HELLO ABAP'.
TRANSLATE lv_string TO LOWER CASE.
WRITE: lv_string. " Output: hello abap

Replace Part of a String (REPLACE)

DATA: lv_string TYPE string VALUE 'I love ABAP'.
REPLACE 'ABAP' WITH 'SAP' INTO lv_string.
WRITE: lv_string. " Output: I love SAP

6. String Length Operators

Find the Length of a String (STRLEN)

DATA: lv_string TYPE string VALUE 'ABAP Programming',
lv_length TYPE i.
lv_length = STRLEN( lv_string ).
WRITE: 'Length:' lv_length. " Output: Length: 16

7. Escape and Special Characters

Using Escape Characters in Strings

DATA(lv_string) = 'Hello \'ABAP\' World!'.
WRITE: lv_string. " Output: Hello 'ABAP' World!

Using Line Breaks (cl_abap_char_utilities=>cr_lf)

DATA: lv_string TYPE string.
lv_string = 'Hello ABAP' && cl_abap_char_utilities=>cr_lf && 'New Line!'.
WRITE: / lv_string.

Summary of Key String Operators in ABAP

OperationOperator / FunctionExample
Concatenation&& / CONCATENATE'ABAP' && ' SAP''ABAP SAP'
Comparison= < > <> <= >='ABAP' < 'SAP'
Substring CheckFIND / CS / CP'ABAP' CS 'BA'
String LengthSTRLEN( string )STRLEN( 'ABAP' ) = 4
Replace TextREPLACEREPLACE 'ABAP' WITH 'SAP'
Uppercase/LowercaseTRANSLATE TO UPPER/LOWERTRANSLATE lv_string TO UPPER CASE
Numeric CheckIS NUMERIC'1234' IS NUMERIC
Newline Charactercl_abap_char_utilities=>cr_lf'Hello' && cr_lf && 'World'

🚀 Conclusion