Home > ABAP > Carriage Return and Line Feed in ABAP

Carriage Return and Line Feed in ABAP

April 20th, 2010 Leave a comment Go to comments

Carriage return and line feed combination separates lines in the ABAP text editor control and some other custom controls. In some other programming language like Java, these special characters are represented by escape characters.

Escape characters are part of the syntax for many programming languages, data formats and communication protocols. For a given alphabet an escape character’s purpose is to start character sequences (so named escape sequences) which have to be interpreted differently from the same characters occurring alone. An escape character may not have its own meaning, so all escape sequences are of 2 or more characters.

In ABAP language, these is no escape character syntax. If we debug the input string of text editor, the carriage return and line feed character is displayed as ‘##’. But if use below statement to separate the string, it will not work. Because ABAP uses character ‘#’ to represent invisible character.

REPLACE '##' with ' ' INTO LS_STRING.

SAP provides class CL_ABAP_CHAR_UTILITIES which is the standard utility class for processing characters. This is a constant in this class named CR_LF which represents carriage return and line feed. Below code snippet can be used to add carriage return and line feed into strings.

DATA: crlf(2) TYPE c.
DATA: l_html(4096)  TYPE C.
crlf = cl_abap_char_utilities=>;cr_lf.
CONCATENATE l_html crlf  '_FUNCTION'
              '30'
              'WWW_GET_REPORT'  INTO l_html.
  1. Mike
    May 28th, 2010 at 04:30 | #1

    Thanks so much. I’ve been looking for this for days.
    Mike

  2. Baz
    January 18th, 2011 at 23:37 | #2

    Hi! nice bit of code, however i am trying to use this in Split by, but very unsuccessful!!

    this does not work for me…

    SPLIT file_upload_itm-ltxa1 at cl_abap_char_utilities=>cr_lf into: str1 str2.

    any pointers on splitting a string by CR_LF??

  3. Asim
    February 1st, 2011 at 02:53 | #3

    Works like a charm! thanks!

  4. February 6th, 2011 at 20:19 | #4

    @Asim
    Thanks~

  5. Bhashitha
    August 17th, 2011 at 13:30 | #5

    thanx a lot, it works perfect…!!!

  6. Pritish
    September 20th, 2011 at 00:17 | #6

    Hi Andy,

    Thanks a lot for this information. I was stuck on this for many days due to dmee file generation with CR_LF.

    Kind Regards,
    Pritish

  1. No trackbacks yet.