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: 

No Carriage return required when outputting file

Former Member
0 Kudos

Hi All.

By default, SAP inserts an end-of-line character when transferring data to the "dataset". we do not want the empty line at the end.

Here is my code :

OPEN DATASET file_path FOR OUTPUT IN BINARY MODE

  • ENCODING DEFAULT

  • WITH SMART LINEFEED

MESSAGE msg.

IF sy-subrc = 0.

LOOP AT itab INTO wa.

l_off = STRLEN( wa ).

TRANSFER wa TO file_path LENGTH l_off NO END OF LINE.

ENDLOOP.

CLOSE DATASET file_path.

ELSE.

" Error that file_not_opened.

ENDIF.

As you see, I have tried all possible ways : Opening in binary format, text format, writing with length specification, no end of line - but a blank line is always coming at the end.

Any clues?

Thanks in adv.

Samant

1 ACCEPTED SOLUTION

former_member223537
Active Contributor
0 Kudos

Hi,

Try the following code :

data : l_string type string.

OPEN DATASET file_path FOR OUTPUT IN BINARY MODE

  • ENCODING DEFAULT

  • WITH SMART LINEFEED

MESSAGE msg.

IF sy-subrc = 0.

LOOP AT itab INTO wa.

concatenate wa l_string into l_string

separated by `09`.

ENDLOOP.

TRANSFER l_string TO file_path.

CLOSE DATASET file_path.

ELSE.

" Error that file_not_opened.

ENDIF.

Best regards,

Prashant

7 REPLIES 7

former_member223537
Active Contributor
0 Kudos

Hi,

Try the following code :

data : l_string type string.

OPEN DATASET file_path FOR OUTPUT IN BINARY MODE

  • ENCODING DEFAULT

  • WITH SMART LINEFEED

MESSAGE msg.

IF sy-subrc = 0.

LOOP AT itab INTO wa.

concatenate wa l_string into l_string

separated by `09`.

ENDLOOP.

TRANSFER l_string TO file_path.

CLOSE DATASET file_path.

ELSE.

" Error that file_not_opened.

ENDIF.

Best regards,

Prashant

0 Kudos

Solved it. Actually no problem in the code. I was using CG3Y to download file to local pc from app server, and i was transferring in ASC format due to which an additional line break was being inserted.

Thanks anyway for all your inputs.

Points awarded.

Former Member
0 Kudos

Hi !

You'll have to open it in TEXT MODE ... otherwise

you will not have a CF/LF at the end of any line.

Single CR/LF at the End-Of-File ?!?

It may help the check you "wa" if it's not initial...

Regards

Rainer

Some points would be nive if that helped a bit.

Former Member
0 Kudos

HI samant,

1. Probaby there might be some minor

mistake in your code.

2. Other wise BINARY mode

is the only way of making such file

without the line feed character.

regards,

amit m.

0 Kudos

Rainer, Prashant -> i think u misunderstood my requirements. I DO NOT want carriage return. It is being appended by default which we don't want because the file will be used to do a CRC Checksum type of thing and because of the carriage return, the checksum is coming wrong.

amit : That's the exact code I am using. Can you tell me where is it wrong? You can test it yourself. Itab can be like this:

DATA : BEGIN OF itab OCCURS 0 ,

text(140),

END OF itab.

APPEND 'test1234' TO itab.

then the remaining code which i pasted before.

Thanks again.

former_member223537
Active Contributor
0 Kudos

Hi Samant,

Here is the program, i have tested it and its working fine.

REPORT ztest1 .

DATA : BEGIN OF itab OCCURS 0 ,

text(140),

END OF itab.

DATA : wa TYPE itab,

file_path TYPE rlgrap-filename VALUE '/tmp/zt.txt',

l_off TYPE i.

APPEND 'test1234' TO itab.

APPEND 'abcdefghijklmnopqrstuvwxyz' TO itab.

APPEND 'test1234' TO itab.

OPEN DATASET file_path FOR APPENDING IN BINARY MODE.

  • ENCODING DEFAULT

  • WITH SMART LINEFEED

*MESSAGE msg.

IF sy-subrc = 0.

LOOP AT itab INTO wa.

l_off = strlen( wa ).

TRANSFER wa TO file_path LENGTH l_off.

ENDLOOP.

CLOSE DATASET file_path.

ELSE." Error that file_not_opened.

ENDIF.

Best regards,

Prashant

former_member552101
Discoverer
0 Kudos

Hi Samant,

I am facing similar issue like the check sum value is coming wrong !

File has to be in text mode in out case , still end of the line we are getting CR/LF and which is giving wrong checksum.

Will someone help me on this.

Regards,

Srini