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: 

How do I TRANSFER a blank line to a dataset?

former_member210148
Participant
0 Kudos

Hey everyone,

Learning all about datasets today, and it seems clear enough. What I'm doing is outputting a "report" of sorts to a dataset during a batch process. I'm reporting on whether or not each transaction processes successfully, as well as providing a summary at the end.

I'd like to put a blank line in a few places, but when I try to TRANSFER what I believe should be a blank line, I don't see a blank line in the resulting file.

Here is my OPEN command:

OPEN DATASET w_dsn FOR OUTPUT IN TEXT MODE ENCODING DEFAULT.

I suppose if worse comes to worse, I can always output a "blank" line with some small character, such as a period.

Any ideas? Thanks so much!

1 ACCEPTED SOLUTION

Former Member
0 Kudos

Hi dave,

1. Simple

2. it works normal.

3.

TRANSFER 'PPP' TO FNAME.

TRANSFER '3333' TO FNAME.

TRANSFER '' TO FNAME. <----


blank line.

TRANSFER '555' TO FNAME.

TRANSFER '66' TO FNAME.

4. then if u go and see in al11,

it will show blank line

between 333333 and 555555.

5. I tried this just now and it works fine.

regards,

amit m.

10 REPLIES 10

FredericGirod
Active Contributor
0 Kudos

Hi,

maybe try to open your file in binary mode.

Rgd

Frédéric

Former Member
0 Kudos

Hi dave,

1. Simple

2. it works normal.

3.

TRANSFER 'PPP' TO FNAME.

TRANSFER '3333' TO FNAME.

TRANSFER '' TO FNAME. <----


blank line.

TRANSFER '555' TO FNAME.

TRANSFER '66' TO FNAME.

4. then if u go and see in al11,

it will show blank line

between 333333 and 555555.

5. I tried this just now and it works fine.

regards,

amit m.

0 Kudos

I assumed that it worked how Amit has suggested, if not, have you tried using a CR. Check the code below for cl_abap_char_utilities=>cr_lf.



report zrich_0001.

parameters: d1 type localfile default '/usr/sap/TST/SYS/Data1.txt'.


data: begin of itab occurs 0,
      rec(200) type c,
      end of itab.

start-of-selection.

  itab-rec = 'This is record number 1'. append itab.
  itab-rec = 'This is record number 2'. append itab.

  open dataset d1 for output in text mode ENCODING DEFAULT.
  loop at itab.
    transfer itab to d1.
    transfer <b>cl_abap_char_utilities=>cr_lf</b> to d1.
  endloop.
  close dataset d1.

Regards,

Rich Heilman

0 Kudos

Rich, thank you -- that worked for me. I saw a # character where the blank line was, but if I saved it as a local text file and pulled it up, it was truly a blank line.

Amit, I gave yours a shot as well, but it didn't put a blank line in -- strange. That's two single quotes together, no spaces between, correct? While Rich's sample worked for me, for my own education, I'd like to get yours working as well. I'm hoping I've simply coded something incorrect.

0 Kudos

Dave, this is working for me as well.




report zrich_0001.

parameters: d1 type localfile default '/usr/sap/NSP/SYS/Data1.txt'.
data: begin of itab occurs 0,
       rec(200) type c,
      end of itab.

start-of-selection.

  itab-rec = 'This is record number 1'.  append itab.
  itab-rec = 'This is record number 2'.  append itab.
  open dataset d1 for output in text mode encoding default.
  loop at itab.
    transfer itab to d1.
<b>    transfer ' '  to d1.</b>

  endloop.
  close dataset d1.

There is a space between the quotes here.

You can also use the keyword space.



  loop at itab.
    transfer itab to d1.
<b>    transfer space  to d1.</b>
  endloop.

REgards,

Rich Heilman

0 Kudos

Hi

this example works fine in my system:

OPEN DATASET 'test.txt' FOR OUTPUT IN TEXT MODE ENCODING DEFAULT.

TRANSFER 'MAX' TO 'test.txt'.

TRANSFER space TO 'test.txt'.

TRANSFER 'MAX' TO 'test.txt'.

CLOSE DATASET 'test.txt'.

You have to replace '' with system variable SPACE, anyway you can also use an empty variable:

DATA: NO_DATA(1) TYPE C.

OPEN DATASET 'test.txt' FOR OUTPUT IN TEXT MODE ENCODING DEFAULT.

TRANSFER 'MAX' TO 'test.txt'.

TRANSFER NO_DATA TO 'test.txt'.

TRANSFER 'MAX' TO 'test.txt'.

CLOSE DATASET 'test.txt'.

The value of costant cl_abap_char_utilities=>cr_lf is a special chararcter and means: The end of record and new line.

Max

0 Kudos

Hi again,

1. u are right. (there are no spaces between the quotes)

2. how are u checking the output of the file ?

in AL11 tcode ?

regards,

amit m.

0 Kudos

Amit, yes, I was checking the output via AL11.

Former Member
0 Kudos

hi,

I tried for inserting blank line in the file.

transfer 'ABC' to p_file.

transfer space to p_file.

transfer 'DEF' to p_file.

I got blank line between ABC and DEF in Enterprise Edition. But I dint get any blank lines in 3.1H version.

We can not use cl_abap_char_utilities in 3.1H.

Is there any other way to get it?

Regards,

Sailaja.

former_member210148
Participant
0 Kudos

Hmmm...wow, that's strange. See, I originally tried just moving SPACE. And when that didn't work, I tried ' ', '', and a few other things. When those didn't work and I couldn't find a good answer after doing an SDN search, I posted my question.

The only thing that seems to work for me is Rich's suggestion to use cl_abap_char_utilities=>cr_lf.