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 to skip blank line (EOF char) at the end of the file while creating ?

Former Member
0 Kudos

Hi,

In my program I have to create a file in Text mode using OPEN DATASET statement. This file is being sent to a third party system for their processing. I came to know while creating the file using OPEN DATASET, one LF character is inserted end of the file resulting a blank line end of the file. Thus if my internal table contains 5 reocrds, in the created text file I can see 6 lines where last is a blank. My question is how to remove this blank line which is causing issue in the thirdparty system.

Here is the Code I have used.

TRY.

  • Write the file in Text Mode

OPEN DATASET lv_outpf FOR OUTPUT IN TEXT MODE ENCODING NON-UNICODE

  • WITH SMART LINEFEED

MESSAGE lv_msg.

*

IF lv_msg IS NOT INITIAL.

WRITE / lv_msg.

EXIT.

ENDIF.

LOOP AT itab_new INTO st.

TRANSFER st TO lv_outpf.

ENDLOOP.

CLOSE DATASET lv_outpf.

CATCH cx_root. "#EC No Handler

ENDTRY.

3 REPLIES 3

franois_henrotte
Active Contributor
0 Kudos

an effective way to do it:

open your dataset in binary mode, transfer the records but between each record transfer the LF (or CRLF according to your need)

after the last record you don't transfer the LF

Former Member
0 Kudos

Hi,

Try to use DELETE ALL OCCURANCE statement and delete the last line.

thanks,

Khush

Former Member
0 Kudos

Thnks Guys. Using binary mode with LF char is really worked for me.