In SAP ABAP, you can append strings using different methods depending on your ABAP version. Here are the common ways:
1. Using CONCATENATE
DATA: lv_string TYPE string VALUE 'Hello'.
CONCATENATE lv_string ' ABAP' INTO lv_string.WRITE: lv_string. " Output: Hello ABAP
- This method overwrites
lv_string
with the new concatenated value.
2. Using &&
Operator (ABAP 7.40+)
DATA: lv_string TYPE string VALUE 'Hello'.
lv_string = lv_string && ' ABAP'.WRITE: lv_string. " Output: Hello ABAP
- This method is shorter and easier to read.
3. Using STRING_CONCATENATE
(ABAP 7.50+)
DATA: lv_string TYPE string VALUE 'Hello'.
lv_string = STRING_CONCATENATE( val1 = lv_string val2 = 'ABAP' separator = ' ' ).WRITE: lv_string. " Output: Hello ABAP
- Useful when you need a dynamic separator.
4. Appending Strings in an Internal Table
If you’re appending multiple strings and storing them in an internal table:
DATA: lt_strings TYPE TABLE OF string, lv_result TYPE string.
APPEND 'Hello' TO lt_strings.APPEND 'ABAP' TO lt_strings.
CONCATENATE LINES OF lt_strings INTO lv_result SEPARATED BY space.WRITE: lv_result. " Output: Hello ABAP
- This is useful when dealing with multiple values dynamically.
Best Practice
- Use
&&
for simple cases (ABAP 7.40+). - Use
CONCATENATE
if working with older ABAP versions. - Use internal tables for handling dynamic multiple strings.