Skip to Content
-2

How to set CR (Carriage Return) at end of line in ABAP?

Hi experts,

We are creating a flat file on the application server using 'open dataset'.

I need to place a CR at the end of each line.

I tried the below syntax, but it doesn't give a CR at end of line.

OPEN DATASET p_file FOR OUTPUT IN TEXT MODE ENCODING DEFAULT.
CONCATENATE l_data cl_abap_char_utilities=>cr_lf(1) INTO l_data.
TRANSFER l_data  TO p_file.

Please suggest how to set CR (Carriage Return)?

Thanks for your help in advance.

Lucy

Add comment
10|10000 characters needed characters exceeded

  • It is possible. You have problem somewhere else.

    Definition of l_data, not using NO END OF LINE, wrongly downloading file from application server...

  • Lucy Gray Tomas Buryanek

    I did try NO END OF LINE, but all it does is writing all the rows of the file in a single line.

    if I define any component of l_data as string, then it doesn't let me use TRANSFER DATASET.

    Which method other than CG3Y do you suggest for downloading?

  • Of course CR does not create new line in most windows editors/viewers. CR+LF is for creating new line, but you want CR at the end of each "data set" ( ~ line), don't you?CG3Y binary download is OK for testing.

  • Get RSS Feed

5 Answers

  • Best Answer
    May 03 at 12:01 PM

    It looks like you need to use NO END OF LINE addition to TRANSFER command (because you are adding it yourself) ?

    Add comment
    10|10000 characters needed characters exceeded

    • That looks rather outdated. Why do you clumsily use a class instead of using the corresponding string template directly? Why do you use CONCATENATE instead of string expressions?

  • May 03 at 05:57 PM
    ASSERT 
    cl_abap_char_utilities=>newline
     = |\n|. 
    ASSERT 
    cl_abap_char_utilities=>horizontal_tab
     = |\t|. 
    ASSERT 
    cl_abap_char_utilities=>cr_lf
     = |\r\n|.
    

    Add comment
    10|10000 characters needed characters exceeded

  • May 03 at 11:02 AM

    Is l_data a char or a string field, in first case the last character would be a space and not CR, CR would be the last non space character.

    Add comment
    10|10000 characters needed characters exceeded

  • May 03 at 05:31 AM

    Hi Lucy,

    The length of CR_LF is 2 charcters '##', Why are you using passing single character cl_abap_char_utilities=>cr_lf(1) instead of cl_abap_char_utilities=>cr_lf. Try below and check it.

    CONCATENATE l_data cl_abap_char_utilities=>cr_lf INTO l_data.

    Regards

    Rajkumar Narasimman

    Add comment
    10|10000 characters needed characters exceeded

  • May 03 at 01:24 PM

    There's a solution noted by the OP in a discussion from 2013, CL_ABAP_CHAR_UTILITIES=cr_lf - how to achieve just 'CR'?

    .

    Add comment
    10|10000 characters needed characters exceeded