What is a line feed?
A line feed is a control character as defined in Wikipedia. In former times such control characters were used to mechanically feed a line in a teletype writer or to let the carriage literally return to the left of the paper. Nowadays, such control characters are mainly used to position cursors in outputs. Many output programs interpret the most important control characters for line feed, return, and tabulator according to their meaning. In source code, HTML or XML files, such control characters are handled as whitespace characters. They are not interpreted as part of the file but can help to make it more readable.
How to get a line feed character in ABAP?
If you search the Web for how to get a line feed character or another control character in ABAP, you mainly find the class CL_ABAP_CHAR_UTILITIES. And in fact, you can use its attribute CL_ABAP_CHAR_UTILITIES=>NEWLINE for that. By but why so complicated? Since Release 7.02, the string templates that are enclosed in |-delimiters, allow you to denote a line feed directly.
|....\n...| for a linefeed among other contents or |\n| for a single line feed character.
Other control characters supported by string templates are \r and \t. If you only need those, no need to use CL_ABAP_CHAR_UTILITIES. To prove that, run the following lines of code in your system:
ASSERT cl_abap_char_utilities=>newline = |\n|.
ASSERT cl_abap_char_utilities=>horizontal_tab = |\t|.
ASSERT cl_abap_char_utilities=>cr_lf = |\r\n|.
Where to use a line feed character in ABAP
First, where to use it not. You cannot use a line feed character or anyother control character in classical list programming. The following line
WRITE |aaaa\nbbbbb|.
produces an output like aaaa#bbbbb. The classical list processor does not recognize the control character and it does not treat it as a whitespace. It is an unknown character that is displayed as #. In classical list programming you have to use two (chained) WRITE-Statements:
WRITE: |aaaa|, / |bbbbb|.
Now where to use line feeds and other control characters? You use them,if you want to send them somewhere, where they are understood. E.g., writing to a file or sending to other displays than classical lists:
cl_demo_text=>show_string(
|<html>| &&
| <body>| &&
| Hello!| &&
| </body>| &&
|</html>| ).
cl_demo_text=>show_string(
|<html>\n| &&
| <body>\n| &&
| Hello!\n| &&
| </body>\n| &&
|</html>\n| ).
While the first output gives
<html> <body> Hello! </body></html>.
The second gives
<html>
<body>
Hello!
</body>
</html>
Last but not least:
cl_abap_browser=>show_html(
EXPORTING html_string =
|<html>\n| &&
| <body>\n| &&
| Hello!\n| &&
| </body>\n| &&
|</html>\n| ).
gives the exepected output, the browser ignores the line feeds.
That's all ...