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: 

Remove blank line at the end of the file

Former Member
0 Kudos

Hi Abapers,

I'm writing a file to application server in text mode, when i download the file to .txt i'm seeing a blank line at EOF. when i press down arrow at the last line, its going to next blank line which i dont want.. Can you please share your thoughts on this?

Thanks.

1 ACCEPTED SOLUTION

SuhaSaha
Advisor
Advisor
0 Kudos

>

> When i download the file to .txt i'm seeing a blank line at EOF. when i press down arrow at the last line, its going to next blank line which i dont want..

How are you downloading the file from the app server ?

17 REPLIES 17

SuhaSaha
Advisor
Advisor
0 Kudos

>

> When i download the file to .txt i'm seeing a blank line at EOF. when i press down arrow at the last line, its going to next blank line which i dont want..

How are you downloading the file from the app server ?

Former Member
0 Kudos

We have a customized transaction to upload and download files from application server..

Former Member
0 Kudos

Hi,

Did you check the internal table where data is gettin passed to file?

Check the internal table in debuggin mode and observe last lines..if you

find that emply rows in internal table with only client id then delete it. It might

solve your problem.

Regards and Best wishes.

0 Kudos

>

> We have a customized transaction to upload and download files from application server..

So you upload the data from a text file on the local m/c using the custom tcode & download the same from the app server to the local m/c.

In the custom tcode when downloading the file to the local m/c you must be using GUI_DOWNLOAD. Can you check what is the value passed to the param WRITE_LF_AFTER_LAST_LINE ?

BR,

Suhas

Former Member
0 Kudos

I have used Open data set with text mode option and then transfered the record.. There is no blank line as such in my data before writing to Application server.. I tried using Open Dataset with binary mode option, But this is writing the data continuously..

Edited by: Premraj Cheguri on Apr 30, 2010 7:01 AM

Former Member
0 Kudos

Hi suhas,

Custom program is using FM: DOWNLOAD to download the file to PC. Please see below code snippet. I dont see option: WRITE_LF_AFTER_LAST_LINE in this FM. Please suggest what else i need to check?

0 Kudos

Where is your code snippet ? In the debug mode did you check if the table passed to DOWNLOAD is having no additional line at the end ?

Former Member
0 Kudos

Please find the code below - There is no blank line in TABL

CALL FUNCTION 'DOWNLOAD'

EXPORTING

  • BIN_FILESIZE = ' '

  • CODEPAGE = ' '

FILENAME = PCFILENAME

FILETYPE = 'ASC'

  • ITEM = ' '

  • MODE = ' '

  • WK1_N_FORMAT = ' '

  • WK1_N_SIZE = ' '

  • WK1_T_FORMAT = ' '

  • WK1_T_SIZE = ' '

  • FILEMASK_MASK = ' '

  • FILEMASK_TEXT = ' '

  • FILETYPE_NO_CHANGE = ' '

  • FILEMASK_ALL = ' '

  • FILETYPE_NO_SHOW = ' '

  • SILENT = 'S'

  • COL_SELECT = ' '

  • COL_SELECTMASK = ' '

IMPORTING

ACT_FILENAME = ACTPCFILENAME

  • act_filetype =

  • filesize =

CANCEL = CANCEL

TABLES

DATA_TAB = TABL

  • FIELDNAMES =

EXCEPTIONS

INVALID_FILESIZE = 1

INVALID_TABLE_WIDTH = 2

INVALID_TYPE = 3

NO_BATCH = 4

UNKNOWN_ERROR = 5

OTHERS = 6.

IF SY-SUBRC NE 0.

RC = SY-SUBRC.

EXIT.

ENDIF.

0 Kudos

Looks like standard download function modules behave this way i.e., add a Line Feed after the last line as well.

Can you check if a line is appended after the EOF for other files as well ?

Former Member
0 Kudos

Yes i checked other files existing in the application server.. Line feed exists for them as well.. But the file which im talking about this will be feed to third party system as an input and the issue is that the third party system is raising many errors because of blank line feed..

0 Kudos

Basically the error is in the custom tcode used to download the file from the app server. I think the file present in the app server should be OK.

Can you not ask the 3rd party system to read the file directly from the app server or ask the Basis team to retrieve the file directly from the app server & send to the 3rd party system?

Former Member
0 Kudos

Yes suhas, I have debugged the custom program before calling download function module, internal table dont have any blank line appended to it.. so the issue is coming when we are downloading it.. Actually our client is using some FTP procedure which would send files from application servers to folders created in Winscp. Even that is having blank line..

Former Member
0 Kudos

You can SORT the itab and after DELETE itab WHERE field EQ space.

Best Regards,

Marcos Moreira.

0 Kudos

Hello Prem,

We had a similar problem with some bank file, they would not accept a line feed in the last line of the file.

I think this problem is generic to files of 'ASC' type (fellow SNDers correct me if i am wrong) so we decided to download 'BIN' file with the table lines separated by CRLF. A code snippet of what we did is given below:

DATA: itab TYPE STANDARD TABLE OF char16384,
      wa TYPE char16384,
      wa1 TYPE char16384.

DATA: v_string TYPE char16384,
      v_size TYPE i.

wa = `This is strange !!!`.

DO 4 TIMES.
  APPEND wa TO itab.
ENDDO.

LOOP AT itab INTO wa.

  wa1 = wa.

  AT FIRST.
    CONCATENATE wa1 cl_abap_char_utilities=>cr_lf INTO v_string.
    CONTINUE.
  ENDAT.

  AT LAST.
    CONCATENATE v_string wa1 INTO v_string.
    EXIT.
  ENDAT.

  CONCATENATE v_string wa1 cl_abap_char_utilities=>cr_lf
  INTO v_string.

ENDLOOP.

"In UC systems each character occupies 2bytes space 
"I did this just for a quick workaround. Please correct this step 
"if someone has better ideas
v_size = STRLEN( v_string ) * 2.

CLEAR itab.
APPEND v_string TO itab.

CALL FUNCTION 'GUI_DOWNLOAD'
  EXPORTING
   bin_filesize                    = v_size
   filename
   = 'C:\Users\Suhas Saha\Desktop\Test.txt'
   filetype                        = 'BIN'
  TABLES
    data_tab                        = itab
 EXCEPTIONS
   OTHERS                          = 22.
IF sy-subrc <> 0.
  MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
          WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ENDIF.

PS: Remember you cannot use an internal table of string type.

Edited by: Suhas Saha on Apr 30, 2010 10:49 PM

0 Kudos

Just a comment about this "blank line". As said above, it's just because ALL lines of the text file terminate with a LF (or CRLF for windows server) character. When you open it with any edit application, the cursor can go after the last LF character, which effectively corresponds to a blank line.

That makes sense to remove the last LF character but be very careful because you might be surprised if you want to open the file with SAP "OPEN DATASET" statement because it is usually coded in a way that, in the case the last LF has been removed, the last line won't be read!

In the code below, when the last line is read, "wa_line" will be set, but at the same time sy-subrc is set to 4 because EOF is reached, so it exits the loop and itab does not contain the last line. When the files contain LF in the last line, then this algo works well.


DO.
  READ DATASET ... INTO wa_line.
  IF sy-subrc = 0.
    EXIT.
  ENDIF.
  APPEND wa_line TO itab.
ENDDO.

If the LF doesn't exist in last line, you'll have to change the algorithm: use the LENGTH keyword of READ DATASET which tells how many characters have been read, and leave the loop only when length is zero (don't test sy-subrc anymore).

Former Member
0 Kudos

Hi Suhas,

I am also facing a similar problem of blank line at the end of txt file downloaded. I am using a file type 'IBM' in 4.6C, So , cannot use GUI_DOWNLOAD. Kindly suggest, how should i remove this blank line.

Thanks

Former Member
0 Kudos

Why not linefeed?

i.e OPEN DATASET * FOR OUTPUT IN TEXT MODE

ENCODING DEFAULT

WITH SMART LINEFEED.