I store my data in a file. And i would like to read the file to retrieve data in Informix-4gl. But, i dun hv any idea how to do it? Did anyone noe how to do and give me some guidance, pls..
Thanks in advanced
There is no in-built fuctionality exists in 4GL to such activities. A workaround is to create a temporary table, load it with your data and select the data from it. A sample below tries to demonstrate this.
database testdb
main
define m_dat varchar(200)
create temp table t_data (dat varchar(255)) with no log
load from 'your.data' insert into t_data
declare cur1 cursor for select * from t_data
open cur1
while(1)
fetch cur1 into m_dat
if status=notfound then
exit while
end if
display m_dat
end while
end main
Shriyan is right about there being no built in method for reading files into 4GL. However, if you take a look at my "How can informix 4GL interact with Unix" FAQ over in the Informix Online forum:
faq179-2007
It includes a section on reading and writing ASCII files. It's all "C" functions, but you don't have to be a "C" programmer to use it.
i had a similar problem and the method describe by vpshriyan works perfectly, but know i want to get that file i have loaded into the temporary table and insert it into a table in the database in a certain order, is that posible using informix 4gl?
Ok, dind't quite worked for me, i think my explanation was short, here's what i need to do. I already loaded my file into the temp table and the data is stored in this pattern without spaces between lines:
Name
Description
Date
Name
Description
Date.....
and so on.
I need to know if i can read for example the first 3 lines or line by line and insert them into a table in the database in that order into fields for that, and so on with the rest of the file that is quite big. Is it posible in 4GL? Hope i explain myself?.
Like Ed, I'm also unable to decipher your requirement fully. However, if I understood bit of it, then I feel that you have column-wise data horizontally placed in your data file, and every 3 lines of information makes a Row for your base table. If so, here is a solution:
database testdb
main
define m_dat varchar(255), cntr smallint,
arr_cols array[3] of
record
mcol varchar(255)
end record
create temp table t_data (dat varchar(255)) with no log
load from 'your.data' insert into t_data
declare cur1 cursor for select * from t_data
let cntr=0
open cur1
while(1)
fetch cur1 into m_dat
if status=notfound then
exit while
end if
let cntr=cntr+1
let arr_cols[cntr].mcol=m_dat clipped
display m_dat
if cntr=3 then
-- send the full row into your database table
while (1)
insert into base_table values
(arr_cols[1].mcol,
arr_cols[2].mcol,
arr_cols[3].mcol)
if status=0 then
exit while
else
error "<base_table> Insert ", status sleep 1
end if
end while
for cntr=1 to 3
let arr_cols[cntr].mcol=""
end for
let cntr=0
end if
end while
end main
Ok, i have been reading my files without problems, but i just got this error when i tried to read some files: -846 Number of values in load file is not equal to number of columns. Reading the Informix Error Messages, i think is beacuse of empty lines in the files. How do i skip the empty lines without my program stopping and keep reading the file and inserting into the temp table?
Ed,
Since 3 rows of raw input data makes a single row for the base table, knocking off any blank data from the input file would result in havoc to already set logic of the conversion steps. Those blank lines need to be there as place holders.
trdin,
You need to pre-process the initial datafile. The following sed command will replace blank lines with pipe character, which would be ok for the SQL LOAD statement.
sed "s/^$/|/" input_file > output_file
Regards,
Shriyan "Vision is the art of seeing things invisible."
Ok, you guys were right i need to pre-process the file, so i ask this, i know is a longshot, is there any way i can execute the Unix sed command from my program in i4gl?. Before the load statement.
Ok, i want to print the displayed information that i read from the files...if you remember i display the info like this:
Name
Description
Date
Name
Description
Date.....
and so on.
I want to print that information displayed on screen, i have tried using the unix cat command to create a file that contains the info, but i have to manually select the info and paste it on the screen so it can be copied into the file. Is it posible to do it automatically, maybe defining where it starts and where it ends and do it from i4GL?
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.