Translating with DrWatson… this can take a few seconds the first time.
This is a genuine, complex translation. DrWatson protects commands, error codes, and log output while naturally translating the surrounding text. It’s translated once and saved.
The original poster asked how to copy table rows into an array of structures in Informix-4GL, as done in ESQL/C. Vic Glass said 4GL arrays need a compile-time size, so process row by row or use ESQL/C. Kleanthis and Richard Spitz showed an ARRAY OF RECORD LIKE table.* filled by FOREACH, with a row-limit check. Answered.
Auto-generated by Claude from the posts below — may be imperfect; read the full thread.
krishnakn@yahoo.com — — source: Informix-list mailing list archive (1991-1998)
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
↪ replying to krishnakn@yahoo.com
Vic Glass — — source: Informix-list mailing list archive (1991-1998)
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
↪ replying to krishnakn@yahoo.com
Kgoozis — — source: Informix-list mailing list archive (1991-1998)
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
↪ replying to krishnakn@yahoo.com
Richard Spitz — — source: Informix-list mailing list archive (1991-1998)
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 |
+--------------------------+------------------------------------------+
We use strictly necessary cookies to make this site work. With your
consent we’d also use optional cookies for analytics and marketing. You can accept all,
reject all, or choose. Read our Cookie Policy.