Application Development Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 

TRANSFER statment and CRLF

Former Member
0 Kudos

Hello!

I'm using the following line in my program to write a row from an itab to a file:

OPEN DATASET gv_outbfile FOR OUTPUT IN TEXT MODE ENCODING NON-UNICODE MESSAGE lv_errmsg.

When I download the file to my PC I notice that there's only a LF (0A) character at the end of the line. My functional guy wants a CR/LF pair at the end of each row so it will display properly in Notepad. How can I get the CRLF on the end of each row?

1 ACCEPTED SOLUTION

former_member194669
Active Contributor
0 Kudos

You need to check addition LINEFEED & SET in open dataset


DATA: file TYPE string VALUE 'test1.dat',
      pos  TYPE i,
      text TYPE string.

OPEN DATASET file FOR OUTPUT IN TEXT MODE
                             ENCODING DEFAULT
                             WITH SMART LINEFEED.

TRANSFER: 'Line1' TO file,
          'Line2' TO file,
          'Line3' TO file.

SET DATASET file POSITION 0.
READ DATASET file INTO text.
SET DATASET file POSITION END OF FILE.

TRANSFER: 'Line4' TO file,
          'Line5' TO file,
          'Line6' TO file.

CLOSE DATASET file.

6 REPLIES 6

Former Member
0 Kudos

Hi,

CONCATENATE
      'Username'
      'Password'
      'First Name'
      'Last Name'
      'Group Code'
      'Location'
      'Email'
      'PersonnelNumber'
      'DepartmentName'
      'EVP'
      'EVP-1'
      'Function'
    cl_abap_char_utilities=>CR_LF
    INTO lv_str

This statement will give you a carriage return at the end of line.

There are more attributes in the class CL_ABAP_CHAR_UTILITIES like Line feed, Tab etc etc.

Amandeep

0 Kudos

I'm getting the CRLF alright but now the file is truncated. It's supposed to be exactly 195 (each row is).

So, I added LENGTH 195 to the TRANSFER statement and re-ran. This causes the text to wrap in Notepad.

0 Kudos

Try to open dataset in binary mode and transfer each line with crlf at the end

former_member194669
Active Contributor
0 Kudos

You need to check addition LINEFEED & SET in open dataset


DATA: file TYPE string VALUE 'test1.dat',
      pos  TYPE i,
      text TYPE string.

OPEN DATASET file FOR OUTPUT IN TEXT MODE
                             ENCODING DEFAULT
                             WITH SMART LINEFEED.

TRANSFER: 'Line1' TO file,
          'Line2' TO file,
          'Line3' TO file.

SET DATASET file POSITION 0.
READ DATASET file INTO text.
SET DATASET file POSITION END OF FILE.

TRANSFER: 'Line4' TO file,
          'Line5' TO file,
          'Line6' TO file.

CLOSE DATASET file.

0 Kudos

I also found WITH WINDOWS LINEFEED which seems to work just fine. Any caveats with that one that you know of?

0 Kudos

No