如何在导出文本文件时删除空行?

时间:2019-06-01 10:14:39

标签: openedge progress-4gl

我已经编写了一个用于生成文本文件格式的程序,但是在创建最后一行为空时遇到了问题。因此,用于生成文本文件的程序会给出空行错误。如您所知,我们可以在解析时删除空行,但客户端表示在生成文本文件时无需创建空行。因此,请帮助此案例以帮助您创建空行。让我分享一些示例查询供您参考

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.

因此,当我看到使用NOtepad ++导出的文本文件时,我可以看到Data1,Data2,Data3的前3个,但第4行创建为空。所以我需要停止创建第四行。

1 个答案:

答案 0 :(得分:2)

MESSAGE通常不是您要用于输出到文件的内容,它具有许多额外的行为,这些行为特定于在提供错误消息等情况下与用户进行交互。PUT通常更适合于写入文件。嵌入CHR(10)也不是一个好主意-这是一个非常特定于OS的行终止符。 CHR(10)是Unix风格的换行符,但是您显然在Windows上运行(使用CHR(10)+ CHR(13)。

我可能会按照以下方式重新编写您的代码:

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.
相关问题