1

An address field in a Progress database evidently is multiple lines. So if I do something simple like:

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

display customer-number
        customer-name
        customer-address.

I get results of:

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

I want results of:

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

I've tried Entry - but get an error if an element does not exists. I am trying to export to CSV and want each line to be another column and if a column does not exists then it is blank.

Any help will be MUCH appreciated!

Tom Bascom
  • 11,421
  • 2
  • 25
  • 31
Trey
  • 13
  • 2

1 Answers1

2

If the delimiter is a newline then something like this should work:

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.

or, if you just need to change the delimiter within the customer-address field:

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

(And, actually, my original code is really just replacing ~n with a space so you could do that too...)

Tom Bascom
  • 11,421
  • 2
  • 25
  • 31
  • Thank you so much for your help. Now I am only getting the first line in the export. The result is: 123 John Smith 123 Easy St. – Trey Nov 10 '20 at 19:52
  • I also think I need a comma to delimit each element in the ENTRY. – Trey Nov 10 '20 at 20:00
  • There is a slight error... I forgot to add the delimiter to num-entries(). I'll fix that above. – Tom Bascom Nov 10 '20 at 21:55
  • If you want to replace the newlines with commas then a simpler approach would be to use the REPLACE() function rather than looping through the entries. – Tom Bascom Nov 10 '20 at 21:57
  • You are a lifesaver! Thank you so much! – Trey Nov 10 '20 at 23:49