Kbase P8426: How to export data in .CSV format
Autor |
  Progress Software Corporation - Progress |
Acesso |
  Público |
Publicação |
  18/11/2010 |
|
Status: Verified
GOAL:
How to export data in .CSV format
GOAL:
How to export data in delimited format
GOAL:
How to export data in comma-separated value format
GOAL:
How to export data to a file (.csv) readable with MS Excel
FACT(s) (Environment):
Progress/OpenEdge Product Family
All Supported Operating Systems
FIX:
Option #1
&SCOPED-DEFINE my-table customer
/*Output location*/
DEF VAR lv-output-path AS CHAR INIT "c:\progress\wrk\" NO-UNDO.
/*Output file type */
DEF VAR lv-output-type AS CHAR INIT "csv" NO-UNDO.
/*comma sep list of fieldnames */
DEF VAR lv-headings AS CHAR NO-UNDO.
/*count of field extents */
DEF VAR lv-count AS INT NO-UNDO.
DEF STREAM data-export.
/* Make a list of field-headings */
FOR EACH _file
WHERE _file-name = "{&my-table}" NO-LOCK.
FOR EACH _field OF _file NO-LOCK BY _field._Order.
lv-count = 1.
IF _field._extent = 0 THEN
lv-headings = lv-headings + "," + _field._field-name.
ELSE lv-headings = lv-headings + "," + _field._field-name +"[1]".
REPEAT WHILE lv-count < _field._extent:
lv-count = lv-count + 1.
lv-headings = lv-headings + "," + _field._field-name + "[" + STRING(lv-count) + "]".
END.
END.
END.
/* Output the field-headings */
OUTPUT STREAM data-export TO VALUE(lv-output-path + "{&my-table}" + "." + lv-output-type).
PUT STREAM data-export UNFORMATTED LEFT-TRIM(lv-headings, ",") SKIP.
/* Output the table contents */
FOR EACH {&my-table} NO-LOCK.
EXPORT STREAM data-export DELIMITER "," {&my-table}.
END.
OUTPUT STREAM data-export CLOSE.
This code exports the data from the table 'customer' to a csv-file
Option #2
OUTPUT TO customer1.csv PAGE-SIZE 0.
EXPORT DELIMITER ";"
"Code"
"Name".
FOR EACH customer NO-LOCK:
EXPORT DELIMITER ";"
custnum
name.
END.
OUTPUT CLOSE.