Thiru
Thiru

Reputation: 251

How to remove an empty lines while exporting the text files?

DEFINE VARIABLE cExportData AS CHARACTER NO-UNDO FORMAT 'X(250)'.
DEFINE VARIABLE cPath AS CHARACTER NO-UNDO.
DEFINE VARIABLE cExt  AS CHARACTER NO-UNDO.
DEFINE VARIABLE cSFTL AS CHARACTER NO-UNDO FORMAT 'X(150)'.
DEFINE VARIABLE cMessageDateTime AS CHARACTER NO-UNDO.

ASSIGN
      cPath  = "R:\Downloads\progress\".
      cExt   = ".Txt".
      cMessageDateTime = "123456789".



OUTPUT TO VALUE (cPath + cMessageDateTime + STRING(MTIME) + cExt ).   


     cExportData = "Data1" + CHR(10) + "Data2" + CHR(10) + "Data3" + CHR(10) + "END.".
     MESSAGE  cExportData.

OUTPUT TO CLOSE.

So when I see exported text file using notepad++ i could see first 3 for Data1,Data2,Data3 but 4th line is created with empty.How do I stop creating empty line.

Upvotes: 0

Views: 754

Answers (1)

Tom Bascom
Tom Bascom

Reputation: 14020

MESSAGE is not usually what you want to use for output to a file, it has many extra behaviors specific to interacting with users in the context of providing error messages etc. PUT is generally more appropriate for writing files. Embedding CHR(10) is also not a good idea -- that is a very OS specific line terminator. CHR(10) is a Unix style newline but you are clearly running on Windows (which uses CHR(10) + CHR(13).

I might re-write your code as follows:

DEFINE VARIABLE cExportData AS CHARACTER NO-UNDO FORMAT 'X(250)'.
DEFINE VARIABLE cPath AS CHARACTER NO-UNDO.
DEFINE VARIABLE cExt  AS CHARACTER NO-UNDO.
DEFINE VARIABLE cSFTL AS CHARACTER NO-UNDO FORMAT 'X(150)'.
DEFINE VARIABLE cMessageDateTime AS CHARACTER NO-UNDO.

/* the "." that you had at the ends of the ASSIGN sub statements
 * is turning it into 3 distinct statements, not one as your 
 * indentation shows
 */

ASSIGN
  cPath  = "R:\Downloads\progress\" 
  cExt   = ".Txt"
  cMessageDateTime = "123456789"
. /* end the ASSIGN statement */

/* if you are using MTIME because you imagine it will make your
 * filename unique then you are mistaken, on a multi-user or 
 * networked system it is trivial for 2 processes to create files
 * at the very same MTIME
 */

OUTPUT TO VALUE (cPath + cMessageDateTime + STRING(MTIME) + cExt ).   

/* usually some kind of looping structure would output each line
 * building the whole output by concatenating into a string will
 * eventually exhaust memory.
 */ 

put unformatted "Data1" skip "Data2" skip "Data3" skip "End." skip.

/* the final SKIP might not be needed - it is unclear to me
 * if that is a problem for your client
 */

/* as originally written this creates
 * an empty file called "CLOSE"
 */

OUTPUT /*** TO ***/ CLOSE.

Upvotes: 4

Related Questions