user3668036
user3668036

Reputation: 25

How to add column name while export .csv in Progress 4gl

I want to add a column name to .csv file while exporting data from Progress DB.

Code:

OUTPUT TO customer1.csv.
FOR EACH customer:
    EXPORT DELIMITER ";" customer .
END.
OUTPUT CLOSE.

Upvotes: 0

Views: 2018

Answers (1)

TheDrooper
TheDrooper

Reputation: 1217

You can use a buffer to loop through the fields dynamically and build a header row:

DEFINE VARIABLE hTable AS HANDLE NO-UNDO.
DEFINE VARIABLE iLoop AS INTEGER NO-UNDO.

hTable = BUFFER Customer:HANDLE.

OUTPUT TO customer1.csv.

/* Export header row. */
DO iLoop = 1 TO hTable:NUM-FIELDS:

    PUT UNFORMATTED hTable:BUFFER-FIELD(iLoop):NAME.

    IF iLoop < hTable:NUM-FIELDS THEN
        PUT UNFORMATTED ";".
END.

PUT SKIP.

/* Export records. */
FOR EACH Customer: 
    EXPORT DELIMITER ";" Customer. 
END.

OUTPUT CLOSE.

The first row in the file will be the field names as they are in the database.

Upvotes: 3

Related Questions