In SAP ABAP, you can add new lines (line breaks) to strings using specific methods. These line breaks are often represented by the Carriage Return (CR) and Line Feed (LF) characters, which you can use to create new lines in your strings.

1. Using cl_abap_char_utilities=>cr_lf (Best Practice)

The class cl_abap_char_utilities provides the constants for Carriage Return (CR) and Line Feed (LF) which are combined as CR_LF to represent a new line.

DATA: lv_string TYPE string.
lv_string = 'Hello ABAP' && cl_abap_char_utilities=>cr_lf &&
'This is a new line in ABAP.'.
WRITE: / lv_string.

2. Using CONCATENATE with cl_abap_char_utilities=>cr_lf

If you’re constructing a string by concatenating multiple parts, you can include a newline between them.

DATA: lv_string TYPE string.
CONCATENATE 'Hello ABAP' cl_abap_char_utilities=>cr_lf
'This is a new line in ABAP.' INTO lv_string SEPARATED BY space.
WRITE: / lv_string.

3. Using && for Concatenation with CR_LF

You can also use && to concatenate strings and include the newline character.

DATA: lv_string TYPE string.
lv_string = 'Hello ABAP' && cl_abap_char_utilities=>cr_lf &&
'This is another line.'.
WRITE: / lv_string.

4. Creating Multiline Strings Using the TEXT Option (ABAP 7.40 and Above)

In ABAP 7.40 and later, you can create a multiline string directly using the TEXT option in the DATA statement.

DATA(lv_string) = `Hello ABAP
This is a new line in ABAP.`.
WRITE: / lv_string.

5. Displaying Newlines in Reports or Logs

When you print or display strings that contain newlines, the line breaks are respected, and the text will be displayed on multiple lines.

DATA: lv_string TYPE string.
lv_string = 'Hello ABAP' && cl_abap_char_utilities=>cr_lf &&
'This is a new line in ABAP.'.
WRITE: / lv_string.

6. Adding a Newline at the End of a String

If you need to append a newline character at the end of an existing string, you can use the same method.

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

Best Practices for Adding Newlines

MethodBest ForVersion
cl_abap_char_utilities=>cr_lfHandling newlines in stringsAll versions
TEXT option (ABAP 7.40 and above)Defining multiline strings in a clean wayABAP 7.40 and above
CONCATENATE with CR_LFConcatenating strings with line breaksAll versions
&& (concatenation) with CR_LFAdding newlines directly when concatenatingAll versions

Display Considerations