Search code examples
openedgeprogress-4gl4gl

How to list all lines in a field with Progress 4GL


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!


Solution

  • 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...)