It is ages since i wrote this bit
and this code works good on progress 8. Not sure if this would work in openedge. Will require customization in terms of database name, hostname etc.,
Best of luck
/* Purpose: Code to extract data from a given database */
/* Pre-connect the database before executing this code */
DEF TEMP-TABLE ttTables NO-UNDO
FIELD ttTable AS CHAR
FIELD ttProg AS CHAR
FIELD ttFile AS CHAR.
DEF VAR cDbName AS CHAR NO-UNDO.
DEF VAR cDbFile AS CHAR NO-UNDO.
DEF VAR cProgDir AS CHAR NO-UNDO.
DEF VAR cDumpDir AS CHAR NO-UNDO.
DEF VAR cDumpExt AS CHAR NO-UNDO.
DEF VAR cDelimiter AS CHAR NO-UNDO.
DEF VAR cDbConnectString AS CHAR NO-UNDO.
DEF VAR cUseConnectString AS CHAR NO-UNDO.
DEF VAR i AS INT NO-UNDO.
DEF VAR cErrString AS CHAR NO-UNDO.
ASSIGN cDbName = "dbname":U
/* Define Variables */
DEF TEMP-TABLE ttTables NO-UNDO
FIELD ttTable AS CHAR
FIELD ttProg AS CHAR
FIELD ttFile AS CHAR.
DEF VAR cDbName AS CHAR NO-UNDO.
DEF VAR cDbFile AS CHAR NO-UNDO.
DEF VAR cProgDir AS CHAR NO-UNDO.
DEF VAR cDumpDir AS CHAR NO-UNDO.
DEF VAR cDumpExt AS CHAR NO-UNDO.
DEF VAR cDelimiter AS CHAR NO-UNDO.
DEF VAR cDbConnectString AS CHAR NO-UNDO.
DEF VAR cUseConnectString AS CHAR NO-UNDO.
DEF VAR i AS INT NO-UNDO.
DEF VAR cErrString AS CHAR NO-UNDO.
ASSIGN cDbName = "dbname":U
cDbFile = "<path>\dbname.db":U
cDbConnectString = "-1":U
/* Code to extract gets generated in this folder */
cProgDir = "c:\progms\":U
/* csv dumps gets generated in this folder */
cDumpDir = "c:\tpdata\":U
cDumpExt = ".csv":U
cDelimiter = ",":U
/* Change the hostname as required */
cUseConnectString = "-S <dbname> -N tcp -H <hostname>".
/* Disconnect and re-establish the connection */
DO WHILE CONNECTED(LDBNAME(1)):
DISCONNECT VALUE(LDBNAME(1)) NO-ERROR.
END.
CONNECT VALUE(cDbFile) VALUE(cUseConnectString) NO-ERROR.
/* Raise exception if connection fails */
IF NOT CONNECTED(cDbName) THEN DO:
DO i = 1 TO ERROR-STATUS:NUM-MESSAGES:
ASSIGN cErrString = cErrString + string(ERROR-STATUS:GET-NUMBER(i)) + " ":U + ERROR-STATUS:GET-MESSAGE(i) + "~n":U.
END.
MESSAGE "Connect failed" SKIP cErrString VIEW-AS ALERT-BOX TITLE cDbFile.
END.
CREATE ALIAS DICTDB FOR DATABASE VALUE(cDbName) NO-ERROR.
/* Initiate the array object */
FOR EACH DICTDB._file WHERE DICTDB._file._File-Number > 0
AND NOT DICTDB._file._file-name BEGINS "SYS":U NO-LOCK:
CREATE ttTables.
ASSIGN ttTables.ttTable = DICTDB._file._file-name.
END.
/* loop through tables to generate the extract code */
FOR EACH ttTables:
RUN GenProgtoExtract.
END.
QUIT.
RETURN.
PROCEDURE GenProgtoExtract:
/* Assign the tablename and extract file */
ASSIGN ttTables.ttProg = cProgDir + ttTables.ttTable + ".p":U
ttTables.ttFile = cDumpDir + ttTables.ttTable + cDumpExt.
/* Initiate program output file and redirect the output to this file */
OUTPUT TO VALUE(ttTables.ttProg).
PUT UNFORMATTED "find _file no-lock where _file-name = '" ttTables.ttTable "'. ~n"
"OUTPUT TO " ttTables.ttFile ". ~n"
"for each _field no-lock of _file break by _order: ~n"
"if not last( _order ) then ~n"
"put trim(_field-name) + ', '. ~n"
"else ~n"
"put _field-name skip. ~n"
"end. ~n"
"FOR EACH " ttTables.ttTable " NO-LOCK: ~n"
"EXPORT DELIMITER '" cDelimiter "' " ttTables.ttTable ". ~n"
"END. ~n"
"OUTPUT CLOSE. ~n"
"RETURN.".
OUTPUT CLOSE.
/* Execute code to generate the extract -- call this bit if you have to automate the task */
/* RUN VALUE(ttTables.ttProg). */
RETURN.
END PROCEDURE.