Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

4GL Read file

382 views
Skip to first unread message

phallage

unread,
Oct 13, 2011, 7:47:06 AM10/13/11
to
Hi,
I want to use the new OPEN FILE, READ FILE, CLOSE FILE in Informix
4GL. Could anyone direct me to detailed documentation on it?
I can't find any description on how to detect EOF in the READ
statement as the READ statement does not seem to return a flag.

Any help will be appreciated.

Poul H.

Ramesh G Srinivasan

unread,
Oct 13, 2011, 7:58:46 AM10/13/11
to phallage, informix-l...@iiug.org, inform...@iiug.org
http://www.ibm.com/developerworks/data/library/techarticle/dm-1007informix4gl/index.html?ca=drs-



phallage <Po...@Hallager.dk>
Sent by: informix-l...@iiug.org

13/10/2011 17:17

To
inform...@iiug.org
cc
Subject
4GL Read file





_______________________________________________
Informix-list mailing list
Inform...@iiug.org
http://www.iiug.org/mailman/listinfo/informix-list


phallage

unread,
Oct 13, 2011, 8:12:27 AM10/13/11
to
On 13 Okt., 13:58, Ramesh G Srinivasan <rames...@in.ibm.com> wrote:
> http://www.ibm.com/developerworks/data/library/techarticle/dm-1007inf...
>
> phallage <P...@Hallager.dk>
> Sent by: informix-list-boun...@iiug.org
> 13/10/2011 17:17
>
> To
> informix-l...@iiug.org

> cc
>
> Subject
> 4GL Read file
>
> Hi,
> I want to use the new OPEN FILE, READ FILE, CLOSE FILE in Informix
> 4GL. Could anyone direct me to detailed documentation on it?
> I can't find any description on how to detect EOF in the READ
> statement as the READ statement does not seem to return a flag.
>
> Any help will be appreciated.
>
> Poul H.
> _______________________________________________
> Informix-list mailing list
> Informix-l...@iiug.orghttp://www.iiug.org/mailman/listinfo/informix-list

Thanks!

I already read the document, but I don't find any description on how
to detect EOF?

Poul H.

Marco Greco

unread,
Oct 13, 2011, 9:34:38 AM10/13/11
to inform...@iiug.org

> _______________________________________________
> Informix-list mailing list
> Inform...@iiug.org
> http://www.iiug.org/mailman/listinfo/informix-list
>

I haven't played with it, but looking at the docs, it doesn't seem to me like
you can detect EOF at all.

If all else fails, in 1996 or thereabout I had written a IO package for 4gl
which does exactly what you want and more: head to the IIUG software
repository and look for the fglio package.
Alternatively, you can find it in my little web site, at
http://www.4glworks.com/misc.htm
--
Ciao,
Marco
______________________________________________________________________________
Marco Greco /UK /IBM Standard disclaimers apply!

Structured Query Scripting Language http://www.4glworks.com/sqsl.htm
4glworks http://www.4glworks.com
Informix on Linux http://www.4glworks.com/ifmxlinux.htm

phallage

unread,
Oct 13, 2011, 9:56:37 AM10/13/11
to
On 13 Okt., 15:34, Marco Greco <ma...@4glworks.com> wrote:
> On 13/10/11 12:47, phallage wrote:> Hi,
> > I want to use the new OPEN FILE, READ FILE, CLOSE FILE in Informix
> > 4GL. Could anyone direct me to detailed documentation on it?
> > I can't find any description on how to detect EOF in the READ
> > statement as the READ statement does not seem to return a flag.
>
> > Any help will be appreciated.
>
> > Poul H.
> > _______________________________________________
> > Informix-list mailing list
> > Informix-l...@iiug.org

> >http://www.iiug.org/mailman/listinfo/informix-list
>
> I haven't played with it, but looking at the docs, it doesn't seem to me like
> you can detect EOF at all.
>
> If all else fails, in 1996 or thereabout I had written a IO package for 4gl
> which does exactly what you want and more: head to the IIUG software
> repository and look for the fglio package.
> Alternatively, you can find it in my little web site, athttp://www.4glworks.com/misc.htm
> --
> Ciao,
> Marco
> ___________________________________________________________________________­___

> Marco Greco /UK /IBM                               Standard disclaimers apply!
>
> Structured Query Scripting Language          http://www.4glworks.com/sqsl.htm
> 4glworks                                              http://www.4glworks.com
> Informix on Linux                        http://www.4glworks.com/ifmxlinux.htm

Thanks Marco,

I will look at it one of these days.

Regards
Poul

Jonathan Leffler

unread,
Oct 16, 2011, 4:58:26 PM10/16/11
to phallage, Informix List - IIUG
On Thu, Oct 13, 2011 at 04:47, phallage <Po...@hallager.dk> wrote:
I want to use the new OPEN FILE, READ FILE, CLOSE FILE in Informix
4GL. Could anyone direct me to detailed documentation on it?
I can't find any description on how to detect EOF in the READ
statement as the READ statement does not seem to return a flag.

I4GL programs should work off STATUS, roughly like this:

-- Testing I4GL Direct File I/O and EOF handling

MAIN

    DEFINE username     VARCHAR(32)
    DEFINE password     VARCHAR(32)
    DEFINE uid          INTEGER
    DEFINE gid          INTEGER
    DEFINE comment      VARCHAR(64)
    DEFINE home         VARCHAR(128)
    DEFINE shell        VARCHAR(64)
    DEFINE fd       INTEGER

    WHENEVER ERROR CONTINUE
    OPEN FILE fd FROM "/etc/passwd"  OPTIONS(READ, FORMAT = 'load', DELIMITER = ':')
    IF STATUS != 0 THEN
        DISPLAY "Failed to open /etc/passwd for reading"
        EXIT PROGRAM 1
    END IF
    WHILE STATUS = 0
        READ FROM fd INTO username,  password, uid, gid, comment, home, shell
        IF STATUS != 0 THEN
            EXIT WHILE
        END IF
        DISPLAY "Entry: ", username CLIPPED,
                " (", password CLIPPED, "),",
                " [UID=", uid USING "-----&", ", GID=", gid USING "-----&", "]",
                " Home = <<", home CLIPPED, ">>,",
                " Shell = <<", shell CLIPPED, ">>"
    END WHILE
    IF STATUS < 0 THEN
        DISPLAY "Read error", STATUS
    ELSE
        DISPLAY "EOF found"
    END IF

    CLOSE FILE fd

END MAIN

Unfortunately, this stopped abruptly with error -1215 on the machine I tested with...there was a user:

nfsnobody:!!:4294967294:4294967294:Anonymous NFS User:/var/lib/nfs:/sbin/nologin

The error is accurate; that number is too big to fit into a 4-byte integer.

Things went downhill after that.

Change the type of UID and GID to BIGINT and the display stops displaying numbers (in I4GL p-code; the c-code system worked OK).

It does however end reading to the end of the file, but then generates error -4828:

> -4828    The field to be read from the file file_name should not be greater than 4096 bytes.

> The length of the string read from the file exceeds 4096 bytes. Check the field in the file. Possibly, the
> file delimiter is misplaced.

Neither is acceptable behaviour - though they are independent bugs.  In my estimation, the READ should return NOTFOUND on EOF.

Tested: I4GL 7.50.FC4 on RHEL 5 (Linux x86/64).


The p-code DISPLAY of BIGINT bug is CQ idsdb00234046.
The EOF from READ bug is CQ idsdb00234047.


--
Jonathan Leffler <jonathan...@gmail.com>  #include <disclaimer.h>
Guardian of DBD::Informix - v2011.0612 - http://dbi.perl.org
"Blessed are we who can laugh at ourselves, for we shall never cease to be amused."

phallage

unread,
Oct 17, 2011, 3:26:25 AM10/17/11
to
On 16 Okt., 22:58, Jonathan Leffler <jonathan.leff...@gmail.com>
wrote:
> Jonathan Leffler <jonathan.leff...@gmail.com>  #include <disclaimer.h>
> Guardian of DBD::Informix - v2011.0612 -http://dbi.perl.org
> "Blessed are we who can laugh at ourselves, for we shall never cease to be
> amused."

Hi Jonathan,
Nice to hear from you again!
Thanks for your help!. I copied your program into my own environment
and modified it for my convenience, and I receive the same 4GL error
at eof (-4828) as you do with any text file. The length of the last
line does not exceed 4096 bytes and delimiter at end of last line is
correct "\n" as in every line in file.
What is "funny" is, that when I display the content of each read line
from file, the last line seems to be very long (but actually it is
not). So I redirected the output from fglgo to a file to see what
actually was read/displayed and I found, that at the last line it
inserts 22 blanks and a null and 17 extra newline characters (\n)
before it writes the -4828 read error.
So what I will do now is report the -4828 as an error in 4GL to IBM
support.
Thanks again to everybody for your help!
Regards
Poul
0 new messages