How to read the data dynamically from Prodataset and write i

Posted by Admin on 18-Aug-2011 05:49

Please find the example below :

/* pdsExample.p*/

DEFINE VARIABLE liCount     AS INTEGER       NO-UNDO.
DEFINE VARIABLE liNumber  AS INTEGER       NO-UNDO.
DEFINE VARIABLE lcName    AS CHARACTER NO-UNDO.

DEFINE OUTPUT PARAMETER DATASET-HANDLE oDataset.  /* output dataset-handle parameter */
    
DEFINE TEMP-TABLE ttExample NO-UNDO                            /* Defining Temp-table */
    FIELD ExampleNo      AS INTEGER
    FIELD ExampleName AS CHARACTER .

DEFINE TEMP-TABLE ttTest NO-UNDO                                 /* Defining Temp-table */
    FIELD TestNo      AS INTEGER
    FIELD TestName AS CHARACTER .
   
DEFINE DATASET dsExample FOR ttExample.                      /* Defining Dataset for Temp-table ttExample */

REPEAT liCount = 1 TO 2 :                                                  /* creating records for Temp-table ttExample */
    SET liNumber lcName.
    CREATE ttExample.
    ASSIGN
        ttExample.ExampleNo      = liNumber
        ttExample.ExampleName = lcName
        .
END.   

oDataset = DATASET dsExample:HANDLE.                         /* Created Temp-table data records are been assigned
                                                                                             to output dataset-handle parameter */

/* Main Procedure */

DEFINE VARIABLE hExample AS HANDLE NO-UNDO.            /* define handle varaible to use as dataset handle */

RUN pdsExample.p (OUTPUT DATASET-HANDLE hExample).  /* Run the external procedure pdsExample.p with one output parameter */

hExample:WRITE-XML("file","ExampleData.xml").                     /* To check the Data which is created in pdsExample.p */

Now if some data is already present in Prodataset then that data is copied to static Temp-table ttExample

DATASET dsExample:COPY-DATASET(oDataset:HANDLE).  /* Now the output parameter dataset information is copied to dataset dsExample */
oDataset:WRITE-XML("file","xmltestdata.xml").                        /* You can check the xml whether data is present  */

Now some data is present in ttExample temp-table and if i have another temp-table as ttTest then
i can create the records in temp-table ttTest easily using static procedure
  
FOR EACH ttExample NO-LOCK:
    CREATE ttTest.
    ASSIGN
        ttTest.TestNo      = ttExample.ExampleNo
        ttTest.TestName = ttExample.ExampleName
        .
END.   

Now my question is if the data is already present in Prodataset then the data should be copied to dataset defined (ex : dsExample)
and the data should be written to ttTest temp-table dynamically .

I would be very happy if any of the user reply to this discussion very soon  .

All Replies

This thread is closed