Kbase P13341: How to export the value of a buffer-object handle to in a fo
Autor |
  Progress Software Corporation - Progress |
Acesso |
  Público |
Publicação |
  3/12/2003 |
|
Status: Unverified
GOAL:
How to export the value of a buffer-object handle to a file that could be possible to import with IMPORT statement.
FACT(s) (Environment):
Progress 9.x
FIX:
If you want to export the value of a buffer-object handle to a file, you can still use the EXPORT statement to write in a file, unfortunately, if you need to read this exported file, then you will have to use the IMPORT UNFORMATTED option because the export statement will place each value onto a new line.
In order to make a direct IMPORT on the file you can to write it using the PUT statement to emulate a classic EXPORT behavior.
This sample code copies all the accessible table from the SPORTS database:
DEF VAR ctablename AS CHAR no-undo.
DEFINE VARIABLE hbBrowse AS HANDLE NO-UNDO.
DEFINE VARIABLE hqQuery AS HANDLE NO-UNDO.
DEFINE VARIABLE hBuffer AS HANDLE NO-UNDO.
DEFINE VARIABLE cOutputFileName AS CHARACTER NO-UNDO.
CREATE WIDGET-POOL 'DynObjects':U.
CREATE QUERY hqQuery IN WIDGET-POOL "DynObjects" NO-ERROR.
/*Release the record in a pre-existing buffer*/
IF VALID-HANDLE(hBuffer) THEN DO:
hBuffer:BUFFER-RELEASE().
END.
FOR EACH _file NO-LOCK:
/* Shall we keep it or skip it? */
IF (_file._file-name BEGINS "_"
AND LOOKUP(_file._file-name,"_file,_field,_index") = 0)
OR _file._file-name BEGINS "SYS"
OR _file._owner <> "PUB"
OR _file._dump-name = ?
THEN NEXT.
cTableName = _File._file-name.
CREATE BUFFER hBuffer FOR TABLE cTableName IN WIDGET-POOL "DynObjects":U
NO-ERROR.
hqQuery:SET-BUFFERS(hBuffer) NO-ERROR.
hqQuery:QUERY-PREPARE("FOR EACH " + hBuffer:NAME + " " +
" NO-LOCK") NO-ERROR.
hqquery:QUERY-OPEN.
cOutputFileName = <PATH> + string(_file._dump-name) + ".txt".
OUTPUT TO VALUE (cOutputFileName).
hqquery:GET-FIRST.
RUN cExport(",", hBuffer).
REPEAT:
hqquery:GET-next.
IF hqQuery:QUERY-OFF-END THEN DO:
hqQuery:GET-LAST().
LEAVE.
END.
RUN cExport(",", hBuffer).
END.
end.
PROCEDURE cExport:
DEF INPUT PARAMETER DELIM AS CHAR NO-UNDO.
DEF INPUT PARAMETER hBuff AS HANDLE NO-UNDO.
DEFINE VARIABLE i AS INTEGER INITIAL 1 NO-UNDO.
DEFINE VARIABLE h2 AS HANDLE NO-UNDO.
DO WHILE i <= hBuff:NUM-FIELDS:
h2 = hBuff:buffer-field(i).
IF h2:DATA-TYPE = "character" THEN PUT UNFORMATTED '"'.
PUT UNFORMATTED h2:BUFFER-VALUE .
IF h2:DATA-TYPE = "character" THEN PUT UNFORMATTED '"'.
IF i < hBuff:NUM-FIELDS THEN PUT UNFORMATTED DELIM.
i = i + 1.
END.
PUT SKIP.
END.