avdberg
New Member
There may be other/better ways to do this as the only idea I have is to use query, buffer and field handles. E.g. something like this:-
DEFINE VARIABLE fCount AS INTEGER.
DEFINE VARIABLE lCount AS INTEGER.
DEFINE VARIABLE tCount AS INTEGER.
DEFINE VARIABLE qh AS HANDLE.
DEFINE VARIABLE bh AS HANDLE.
DEFINE VARIABLE fh AS HANDLE.
DEFINE VARIABLE expTables AS CHARACTER EXTENT 10.
DEFINE STREAM ftables.
DEFINE STREAM fLog.
expTables[1] = "ContractRegel".
OUTPUT STREAM ftables TO "/data/export/micos/ContractRegel_xas4711i.csv".
OUTPUT STREAM fLog TO VALUE("aaexport.log") APPEND.
DO tCount = 1 TO 10:
IF expTables[tCount] <> "" THEN DO:
CREATE BUFFER bh FOR TABLE expTables[tCount].
CREATE QUERY qh.
qh:SET-BUFFERS(bh).
qh:QUERY-PREPARE("FOR EACH " + expTables[tCount]).
qh:QUERY-OPEN.
lCount = 0.
REPEAT:
qh:GET-NEXT().
IF qh:QUERY-OFF-END THEN LEAVE.
REPEAT fCount = 1 TO bh:NUM-FIELDS:
fh = bh:BUFFER-FIELD(fCount).
IF fh:dATA-TYPE = "CHARACTER" THEN
PUT STREAM ftables UNFORMATTED QUOTER(fh:BUFFER-VALUE).
ELSE
PUT STREAM ftables UNFORMATTED fh:BUFFER-VALUE.
IF fCount = bh:NUM-FIELDS THEN
PUT STREAM ftables SKIP.
ELSE
PUT STREAM ftables ",".
END.
lCount = lCount + 1.
END.
PUT STREAM fLog UNFORMATTED lCount SPACE(1) bh:NAME SKIP.
qh:QUERY-CLOSE().
DELETE OBJECT fh NO-ERROR.
DELETE OBJECT bh NO-ERROR.
DELETE OBJECT qh NO-ERROR.
END.
END.
OUTPUT STREAM ftables CLOSE.
OUTPUT STREAM fLog CLOSE.
Thank you for the information and help. Here a what i want to do.
I have the following tables in the progres DB
Contact
Contract
Project
Offerte
And want Contract exported to a seperate export file so
Contact to Contact_xoc1010i.csv
Contract to Contract_xom4010i.csv
Project to Project_xci4010.csv
Offerte to Offerte_cma1010i.csv
And for every table count the number of records and put this in a log file with information about number of records, time, date and table name.