Need to insert field values to a database from a temp-table that I have created from xml file in progress 4gl. How to do that??

nen

New Member
**Below is my samplecode to read data from xml file and write to temp-table "tttemp" and display a child "mainsub" and its sub-child nodes.**
XML:
DEFINE VARIABLE hDoc   AS HANDLE  NO-UNDO.
        
        DEFINE VARIABLE hroot AS HANDLE  NO-UNDO.
        
        DEFINE VARIABLE hmainsub  AS HANDLE  NO-UNDO.
        
        DEFINE VARIABLE hsub AS HANDLE  NO-UNDO.
        
        DEFINE VARIABLE hfield AS HANDLE  NO-UNDO.
        
        DEFINE VARIABLE htext AS HANDLE  NO-UNDO.
        
        DEFINE VARIABLE hBuf AS HANDLE NO-UNDO.
        
        DEFINE VARIABLE hDBFld AS HANDLE NO-UNDO.
        
        DEFINE VARIABLE ix     AS INTEGER NO-UNDO.
        
        DEFINE VARIABLE jx     AS INTEGER NO-UNDO.
        
        DEFINE VARIABLE cx     AS INTEGER NO-UNDO.
        
        DEFINE TEMP-TABLE tttemp
        
        FIELD ID      AS CHAR
        
        FIELD SUFFIX      AS CHAR
        
        FIELD PREFIX     AS CHAR
        
        FIELD FIRST_NAME    AS CHAR
        
        FIELD MIDDLE_NAME      AS CHAR
        
        FIELD LAST_NAME    AS CHAR
        
        FIELD DOB      AS CHAR
        
        FIELD AGE      AS CHAR.
        
        hBuf = BUFFER tttemp:HANDLE.   
          
        
        CREATE X-DOCUMENT hDoc.
        
        CREATE X-NODEREF hroot.
        
        CREATE X-NODEREF hmainsub.
        
        CREATE X-NODEREF hsub.
        
        CREATE X-NODEREF hfield.
        
        CREATE X-NODEREF htext.
        
        
        
        
        
        hDoc:LOAD("file", "C:\samplefile.xml", FALSE).
        
        
        
        hDoc:GET-DOCUMENT-ELEMENT(hroot).
        
        REPEAT ix = 1 TO hroot:NUM-CHILDREN:
        
        hroot:GET-CHILD(hmainsub,ix).
        
          
    
        IF  hmainsub:NAME = "mainsub" THEN
    
        DO:
    
             REPEAT cx = 1 TO hmainsub:NUM-CHILDREN:
    
             CREATE ttPilots.
    
               REPEAT jx = 1 TO hsub:NUM-CHILDREN:
    
               hsub:GET-CHILD(hfield, jx).
    
               IF hField:NUM-CHILDREN < 1 THEN NEXT.
    
               hDBFld = hBuf:BUFFER-FIELD(hField:NAME).
    
               hfield:GET-CHILD(htext, 1).
    
               hDBFld:BUFFER-VALUE = hTEXT:NODE-VALUE.
    
               END.
    
             END.
    
        END.
    
    END.
    
    DELETE OBJECT hDoc.
    
    DELETE OBJECT hmainsub.
    
    DELETE OBJECT  hsub.
    
    DELETE OBJECT htext.
    
    DELETE OBJECT  hfield.
    
    DELETE OBJECT  hroot.
    
    
    
    /* show data made it by displaying temp-table */
    
    FOR EACH tttemp:
    
      DISPLAY tttemp  WITH 1 COLUMN.
    
    END.
**From above procedure code I got output and can be able to display required temp-table**
**but now from this output I want to add data to fields in my already existing database table . How to do that in progress 4gl...plz help me with the code?? **
 

Attachments

Cringer

ProgressTalk.com Moderator
Staff member
Without knowing your database structure there's very little we can do to help. But you should look at the documentation for your version of Progress. In particular look at Transaction scoping, record locking, etc.

Something to get you started.

Code:
DEFINE BUFFER bTable for Table. 

DO FOR bTable TRANSACTION:
  FIND bTable EXCLUSIVE WHERE <some where clause> NO-WAIT NO-ERROR. 
  IF AVAILABLE bTable THEN 
    ASSIGN 
      bTable.Field1 = <whatever>
      etc...
      .
END.
 

nen

New Member
Ok...got it...thank you sir for your response.
 
Top