Export table as .csv with column names and double quotes?

Posted by jmille25 on 09-Jul-2015 16:45

I'm trying to write a .p script that will export a table from a database as a csv. The following code creates the csv:

OUTPUT TO VALUE ("C:\Users\Admin\Desktop\test.csv").

FOR EACH table-name NO-LOCK:
    EXPORT DELIMITER "," table-name.
END.

OUTPUT CLOSE.
QUIT.

However, I can't figure how to encapsulate all of the fields with double quotes. Nor can I figure out how to get the first row of the .csv to have the column names of the table. How would one go about doing this?

I'm very new to Progress / 4GL. Originally I was using R and an ODBC connection to import and format the table before saving it as a csv. But I've learned that the ODBC driver I'm using does not work reliably...sometimes it will not return all the rows in the table. I've also used the DBTool utility to fix and any column widths, but the problem persists.

The ultimate goal is to pass an argument (table-name) to a .p script (from the command line) that will export the table as a csv. Then I can import the csv in R, manipulate / format the data and then export the table again as a csv.

Any advice would be greatly appreciated.

Additional Info:

  • The version of Progress I am using is 9.1D

  • Using the above code, the output might look like this...

    "ACME",01,"Some note that may contain carriage returns.\n More text",yes,"01A"
  • The reason for trying to encapsulate every field with double quotes is because some fields may contain carriage returns or other special characters. R doesn't always like carriage return in the middle of field. So the desired output would be...

    "ACME","01","Some note that may contain carriage returns.\n More text","yes","01A"

All Replies

Posted by TheMadDBA on 09-Jul-2015 17:09
This thread is closed