Salesforce

4GL/ABL: How to dump a Progress Database using 4GL/ABL dynamic queries?

« Go Back

Information

 
Title4GL/ABL: How to dump a Progress Database using 4GL/ABL dynamic queries?
URL NameP108568
Article Number000149596
EnvironmentProduct: OpenEdge
Version: All supported versions
OS: All supported platforms
Other: N/A
Question/Problem Description
How to dump a Progress Database using 4GL/ABL dynamic queries?

How to programmatically dump a Progress Database using 4GL/ABL dynamic queries?
Steps to Reproduce
Clarifying Information
Error Message
Defect Number
Enhancement Number
Cause
Resolution

In 12.8 and later you can use the BUFFER-EXPORT method to export buffers dynamically.

https://docs.progress.com/bundle/abl-reference/page/BUFFER-EXPORT-method.html

The following code dumps the data of the connected database using dynamic queries:

/***************Define needed variables************/
DEFINE VARIABLE hBufferHandle AS HANDLE     NO-UNDO.
DEFINE VARIABLE cTableName    AS CHARACTER  NO-UNDO.
DEFINE VARIABLE iFieldCounter      AS INTEGER    NO-UNDO.
DEFINE VARIABLE iExtentCounter      AS INTEGER    NO-UNDO.
DEFINE VARIABLE hFieldHandle  AS HANDLE     NO-UNDO.
DEFINE VARIABLE hQueryHandle  AS HANDLE     NO-UNDO.

/** Loop Through User Tables of the currently connected Database **/
FOR EACH _File NO-LOCK WHERE _Tbl-Type = "T":
    RUN ExportCurrentTableData(INPUT _File._File-Name ).
END.

PROCEDURE ExportCurrentTableData:
    DEFINE INPUT PARAMETER cTableName AS CHARACTER.
    DEFINE VARIABLE cFileName AS CHARACTER  NO-UNDO.
    DEFINE VARIABLE cTemp     AS CHARACTER   NO-UNDO.
    
    DEFINE VARIABLE rTemp     AS RAW         NO-UNDO.
    
    /* Assign the name of the output file for the current table */
   
    cFileName = cTableName + ".dat".
    OUTPUT TO VALUE(cFileName).
   
    /* Create dynamic query for the cTablename */
    CREATE BUFFER  hBufferHandle FOR TABLE cTableName.
    CREATE QUERY  hQueryHandle.
    hQueryHandle:SET-BUFFERS(hBufferHandle).
    hQueryHandle:QUERY-PREPARE("for each " + cTableName + " NO-LOCK").
    hQueryHandle:QUERY-OPEN.
   
    /*  Iterate through all the records of the current table */
    REPEAT:
        hQueryHandle:GET-NEXT().
        IF hQueryHandle:QUERY-OFF-END THEN LEAVE.
        /*  Iterate through all the fields of the current record */
        DO iFieldCounter = 1 TO hBufferHandle:NUM-FIELDS:
            hFieldHandle = hBufferHandle:BUFFER-FIELD(iFieldCounter).
            IF  hFieldHandle:EXTENT = 0 THEN DO:
                IF iFieldCounter > 1 THEN PUT UNFORMATTED " ".
                IF (hFieldHandle:DATA-TYPE = "CHARACTER") THEN
                    PUT UNFORMATTED '"' hFieldHandle:BUFFER-VALUE '"'.
                ELSE IF hFieldHandle:DATA-TYPE EQ "RAW" THEN DO:
                    rTemp = hFieldHandle:BUFFER-VALUE.
                    cTemp = BASE64-ENCODE(rTemp).
                    PUT UNFORMATTED '"' cTemp '"'.
                END.
                ELSE
                    PUT UNFORMATTED hFieldHandle:BUFFER-VALUE.
            END. /* hFieldHandle:EXTENT = 0 */
            ELSE
            DO iExtentCounter = 1 TO hFieldHandle:EXTENT:
                IF iExtentCounter > 1 THEN PUT UNFORMATTED " ".
                /* handle special case where extent is the second or greater field */
                /* write a space before the first element of the extent */
                IF (iFieldCounter > 1 AND iExtentCounter = 1) THEN PUT UNFORMATTED " ".
                IF (hFieldHandle:DATA-TYPE = "CHARACTER") THEN
                    PUT UNFORMATTED '"' hFieldHandle:BUFFER-VALUE[iExtentCounter] '"'.
                ELSE IF hFieldHandle:DATA-TYPE EQ "RAW" THEN DO:
                    rTemp = hFieldHandle:BUFFER-VALUE[iExtentCounter].
                    cTemp = BASE64-ENCODE(rTemp).
                    PUT UNFORMATTED '"' cTemp '"'.
                END.
                ELSE
                    PUT UNFORMATTED hFieldHandle:BUFFER-VALUE[iExtentCounter].
            END.   /* DO iExtentCounter */
        END.   /* DO iFieldCounter */
        PUT  UNFORMATTED SKIP.
    END.   /* REPEAT */
    OUTPUT CLOSE.
    DELETE OBJECT hBufferHandle.
    DELETE OBJECT hQueryHandle.
END PROCEDURE.


See also article  How to EXPORT a record dynamically for further export examples, e.g. for CLOB fields, and article  How to use the EXPORT statement with a dynamic query?


 

Workaround
Notes
Keyword Phrase
Last Modified Date1/28/2025 4:26 PM

Powered by