如何使用Progress 4GL列出字段中的所有行

问题描述

“进度”数据库中的地址字段显然是多行。因此,如果我做一些简单的事情,例如:

for each customer where customer-number = "123" no-lock.

display customer-number
        customer-name
        customer-address.

我得到以下结果:

123  John Smith  123 Easy St.
                 c/o Jane Smith
                 Apartment C12

我想要以下结果:

 123  John Smith  123 Easy St.  c/o Jane Smith  Apartment C12

我尝试了Entry-但如果元素不存在,则会出现错误。我正在尝试导出为CSV,并希望每一行都是另一列,如果某列不存在,则为空白。

任何帮助将不胜感激!

解决方法

如果定界符是换行符,则应执行以下操作:

define variable n as integer no-undo.
define variable i as integer no-undo.

define variable address as character no-undo.

output to value( "customer.csv").
for each customer no-lock:
  address = "".
  n = num-entries( customer-address,"~n" ).
  do i = 1 to n:
    address = address + entry( i,customer-address,"~n" ) + " ".
  end.
  export delimiter "," customer-number customer-name trim( address ).  
end.
output close.

或者,如果您只需要在客户地址字段中更改定界符:

output to value( "customer.csv").
for each customer no-lock:
  export delimiter "," customer-number customer-name replace( customer-address,"~n","," ).  
end.
output close.

(实际上,我的原始代码实际上只是将〜n替换为空格,因此您也可以这样做...)