Moving table data to structures in Informix-4gl
Posted in 1999
Topics: Connectivity: ESQL/C, 4GL & Embedded SQL
Hi, I want to copy the table data to an array of structures.... I have done this in ESQLC. I declared a sturcture with elements similar to the columns of the table. Then I declare a SELECT cursor and copy the data to the structure. As a result I had an array of structure equal to the number of rows in the table. I have to do the same thing in 4GL. How do I do it????? Thanks, nkrishnakumar -----------== Posted via Deja News, The Discussion Network ==---------- http://www.dejanews.com/ Search, Read, Discuss, or Start Your Own
I presume that you use dynamic memory allocation in the ESQL/C program, and malloc'd a new structure for each row fetched. This cannot be done in Informix-4GL. The number of elements in the array of structures must be defined at compile time: define x array[100] of record like mytable.* It is hard to tell how to approach the problem with the 4GL since you did not say what you are trying to accomplish. If you can processes as you go, then in a 4GL program you can define a single structure (record in 4GL lingo) and fetch one row at a time into it, do the processing, then fetch the next row. Oh, but if you to look at *all* the data before making decisions, then its best to do this in ESQL/C where there dynamic memory allocation. krishnakn@yahoo.com wrote: > Hi, > > I want to copy the table data to an array of structures.... > > I have done this in ESQLC. I declared a sturcture with elements similar to the > columns of the table. Then I declare a SELECT cursor and copy the data to the > structure. > As a result I had an array of structure equal to the number of rows in the > table. > > I have to do the same thing in 4GL. How do I do it????? > > Thanks, > nkrishnakumar > > -----------== Posted via Deja News, The Discussion Network ==---------- > http://www.dejanews.com/ Search, Read, Discuss, or Start Your Own
if i understand your question right.... the answer is "very easily"! :) e.g. define your_prg_var_name array [10] of record like table1.* you can then refer to the elements of the array with: your_prg_var_name[i].colA your_prg_var_name[i].colB ... your_prg_var_name[i].colN unless you want to use in your record only some of the columns in table1; in that case: define your_prg_var_name array [10] of record colA like table1.colA, colB like table1.colB, ... colZ like table1.colZ end record Kleanthis
krishnakn@yahoo.com wrote:
> I have done this in ESQLC. I declared a sturcture with elements similar to the
> columns of the table. Then I declare a SELECT cursor and copy the data to the
> structure.
> As a result I had an array of structure equal to the number of rows in the
> table.
>
> I have to do the same thing in 4GL. How do I do it?????
Very simple example:
DATABASE mydb
MAIN
DEFINE p_record ARRAY[100] OF RECORD LIKE mytable.*,
i, n SMALLINT
DECLARE c_cursor CURSOR FOR
SELECT * FROM mytable
LET i = 1
FOREACH c_cursor INTO p_record[i].*
LET i = i + 1
IF i > 100 THEN
ERROR "Too many rows in table!"
EXIT FOREACH
END IF
END FOREACH
LET n = i - 1
END MAIN
HTH, Richard
--
+--------------------------+------------------------------------------+
| Dr. Richard Spitz | INTERNET: spitz@ana.med.uni-muenchen.de |
| EDV-Gruppe Anaesthesie | Tel : +49-89-7095-6110 |
| Klinikum Grosshadern | FAX : +49-89-7095-6420 <-- NEW!!! |
| 81366 Munich, Germany | GSM : +49-172-8933578 |
+--------------------------+------------------------------------------+