【问题标题】:Why does field value with space contain a new line when exporting to a text file in Progress 4GL?为什么在 Progress 4GL 中导出到文本文件时,带空格的字段值包含新行?
【发布时间】:2014-09-02 02:46:23
【问题描述】:

我可以将数据导出到文本文件,但文本文件中的格式不好。例如,当归档值中有空格时 - 它在文件中包含一个新行。

样本数据: 846438828|10121803||海因|凯蒂|270||卵石
溪|DR|||美国|GA|30605||7DAY|1|2| 842486060|1012||GUNTER|LEWELL|230||MCDUFFIE|DR|||雅典|GA|30605|7065430640|周五至周日|1|2| 889388948|101205||WEEKS|J D|183||MELL|ST|||雅典|GA|30605|7065481437|SUNONLY|1|2|

街道名称“PEBBLE”CREEK 字段的值,但在报告中它看起来像:

卵石

小溪

为什么会这样?

def var v-copies     as inte                     no-undo.
def var v-phone      as char format "x(16)"      no-undo.
def var v-loc        as char                     no-undo.
def var v-file       as char format "x(30)"      no-undo.
def var v-demoid     as char format "x(20)"      no-undo.
def var v-email      as char format "x(30)"      no-undo.
def var v-hostname as char format "x(20)" no-undo.

def var v-RouteIDs as  char no-undo.
def var v-Product  as  char no-undo.
def var v-ExDir    as char format "x(80)" no-undo.  
def var v-LookBack as int no-undo init 90.

{tools/altpubs/audit/var.i}
{tools/altpubs/audit/procedures.i}

def stream sout.

def temp-table tt-demo 
  field entityid as int format ">>>>>>>>>9"
  field answer like DemographicAnswer.Answer.


v-ConfigFile = search(v-ConfigFile). 
if v-ConfigFile = ? then do:
 message "config file config.csv was not found" view-as alert-box.
 RETURN "ERROR".
end. 

input from value(v-ConfigFile).
run ReadConfig.
input close.

for each tt-Config where tt-Config.Section = 'local' and
    tt-Config.SectionValue <> ?:
   v-loc = tt-Config.SectionValue.
  case tt-Config.SettingName:
    when 'ExchDir'   then v-ExDir       = tt-Config.SettingValue.
    when 'Product'   then v-Product     = tt-Config.SettingValue.
    when 'Routes'    then v-RouteIDs    = tt-Config.SettingValue.
    when 'LookBack'  then 
   do:
      v-LookBack  = integer(tt-Config.SettingValue) no-error.
       if error-status:error then v-LookBack = 90.
   end.
 end.
end.

v-ExDir = v-Exdir + lc(v-loc) + "/". 
file-info:file-name = v-ExDir.
if not( file-info:file-type begins "D")  or file-info:file-type = ? then
do:
  unix silent makedir value(v-ExDir) && chmod 777 value(v-ExDir).
  file-info:file-name = v-ExDir.
end.

assign
  v-File =  v-ExDir + lc(v-Product) + "Audit" +
    string(month(today),"99") + "-" +
    string(day(today),"99") + "-" +
     substring(string(year(today),"9999"),3) + ".txt".

for each DemographicAnswer where DemographicAnswer.DemographicId = v-RouteIDs 
  no-lock:
 create tt-demo.
 assign tt-demo.entityid = int(DemographicAnswer.EntityId)
        tt-demo.answer = DemographicAnswer.Answer.
 end.

output stream sout to value(v-file). 

put stream sout unformatted 
  "HEADER B2 "   string(today) skip. 

for each tt-demo,
     each Subscription no-lock
  where Product = v-product 
    and SubscriptionID = tt-demo.entityid
    and Subscriber = yes
    and Getspaper  = yes:

  find last RouteSubscription of Subscription no-lock no-error.
  if available routeSubscription then do:

    for each Occupant of Subscription no-lock,                   
        each Address of Subscription no-lock:

  find OccupantPhone of Occupant no-lock no-error.
  if available OccupantPhone then 
    v-phone = OccupantPhone.AreaCode + OccupantPhone.Phone.
  else 
    v-phone = "".

  find last OccupantEmail of Occupant no-lock no-error.
  if available OccupantEmail then 
    v-email = OccupantEmail.EmailAddress. 
  else
    v-email = "".

  case DeliveryScheduleId:
    when "MON-FRI" then v-copies = RouteSubscription.Copies[2].
    when "FRI-SUN" then v-copies = RouteSubscription.Copies[1].
    when "SUNONLY" then v-copies = RouteSubscription.Copies[1].
    when "7DAY"    then v-copies = RouteSubscription.Copies[1].
    when "MON-SAT" then v-copies = RouteSubscription.Copies[2].
    when "THUONLY" then v-copies = RouteSubscription.Copies[5].
    when "WEDONLY" then v-copies = RouteSubscription.Copies[4].
    when "SATSUN"  then v-copies = RouteSubscription.Copies[1].
  end case.

  put stream sout unformatted
    tt-demo.Answer "|" 
    Subscription.SubscriptionId "|" 
    Subscription.Product "|"
    Occupant.LastName "|"
    Occupant.FirstName "|" 
    trim( Address.HouseNumber) "|" 
    trim(Address.Postdirectional) "|" 
    trim(Address.StreetName) "|" 
    trim(Address.StreetSuffixId) "|" 
    trim(Address.postdirectional) "|" 
    trim(Address.UnitDesignatorID + trim(Address.UnitNumber)) "|"
    Address.CityId "|" 
    Address.StateId "|"
    Address.ZipCode "|"
    v-phone "|" 
    Subscription.DeliveryScheduleId "|"           
   v-copies "|"
    "2" "|"
    v-email skip.
    end.
  end.
end.
put stream sout unformatted
 "TRAILER ".
output stream sout close.

【问题讨论】:

  • 如何导出?可以贴代码吗?

标签: formatting progress-4gl openedge


【解决方案1】:

这实际上可能只取决于几件事,但如果没有看到您的代码就很难回答。

1) 那里确实没有新行。它只是看起来像它,因为您的文本编辑器在您打开文件时会换行。如果是这种情况,最大化/更改编辑器的窗口大小会改变新行的显示位置。

2) 该领域确实有一条新路线。那将被导出。如果您使用 EXPORT 导出值,您可以尝试执行以下操作来替换换行符:

EXPORT REPLACE(streetname, "~n","").

如果这有效,您的数据库中有新行。

3) 您导出数据的方式有问题。由于您没有发布示例代码(这样做总是一个好主意),我们无法知道这一点。

我的赌注是数字 1 或 2。如果您使用像 EXPORT 这样简单的导出方法,您真的不应该遇到麻烦...

【讨论】:

  • 我可以使用 put 流。
  • 那么我仍然很确定你只是在编辑器中看到新行或者它真的在那里......不过最好发布确切的代码......
【解决方案2】:

Jens 说的差不多(我会留下这个作为评论,但 Stack Overflow 不会让我......)。

尝试在 Notepad++ 中打开文件并禁用 View->Wrap,或使用您选择的编辑器执行类似操作。 换行符很可能“不存在”。

【讨论】:

    【解决方案3】:

    前段时间我也遇到过同样的问题。问题出在数据字段的内容中,其中有 CHR(10)(换行)和 CHR(13)(回车)字符由用户用键输入。我找到了一个简单的解决方案,通过创建一个函数将这些字符转换为 '' 并将其与 PUT 语句一起使用。例如,我将使用您的两个字段...

    FUNCTION stringExport RETURNS CHAR
        ( INPUT p-input AS CHAR ):
    
        RETURN TRIM(REPLACE(REPLACE(p-input,CHR(13),''),CHR(10),'')).
    
    END FUNCTION. /* stringExport */
    
    PUT STREAM sout UNFORMATTED 
        stringExport(Occupant.FirstName) "|"
        stringExport(Address.HouseNumber) "|" SKIP. 
    

    这样做也许可以解决您的问题。显然你可以用''代替''。这取决于您的需求。

    希望对你有帮助。

    【讨论】:

    • 这是我在第二点的回答:CHR(10) (换行) + CHR(13) (回车) 被替换为 "~n" 为 ""。
    • 谢谢@Jensd!我不知道 "~n" 和 "CHR(10) + CHR(13)" 是一回事。
    • ~n 是通用的“换行符”。在 UNIX 上是 chr(10) 在 Windows 上是 chr(10) + chr(13)。
    【解决方案4】:

    看起来您遇到问题的字段是address.postdirectional。正如其他人所说,首先要检查的是数据中没有隐藏的换行符。

    在程序编辑器/tramlines 中,尝试一些简单的操作,例如:

    for each address no-lock: 
        display procedure.postdirectional.
    end.
    

    此时您也应该在数据中看到任何换行符。

    【讨论】:

      猜你喜欢
      • 2014-09-26
      • 2021-04-16
      • 2021-11-12
      • 2018-06-04
      • 2016-01-17
      • 2013-09-02
      • 1970-01-01
      • 2021-02-26
      • 2015-04-02
      相关资源
      最近更新 更多