Wiley Ammons wrote on 29/06/2007 14:32:26:
   I have prototyped open and close and I am using Scott's readline 
almost
   verbatim as an external procedure to my program. I have an interface
   process that determines the type of message I have received by 
reading the
   header inside each file. There is a group of 3 programs that read the 
list
   of files, and then opens each file to see if it should process them.
   The problem I am facing is that when I open, readline and close an 
IFS
   file in the first program, subsequent programs called by the same 
parent
   process open the same file and get line 2 of the file instead of line 
1
   like that first program. They therefore never process the 
transaction. Any
   help would be appreciated, thanks for your time.
The readline in the form you have it is limited to handling one file at a 
time, and it is not designed to partially read a file, and then re-read it 
from the beginning.  It helps to understand that readline is in a sense 
'virtualizing' access to the file.  One of the main benefits of readline() 
is that it reads data in chunks from the file, in order to maximize I/O 
performance.
   If it helps, here is my copy of readline:
          //ReadLine - Get a line at a time from an IFS file
        P $_readline      B                   export
        D $_readline      PI            10I 0
        D   fd                          10I 0 value
        D   text                          *   value
        D   maxlen                      10I 0 value
        D rdbuf           S           1024A   static
        D rdpos           S             10I 0 static
        D rdlen           S             10I 0 static
Note the use of the 'static' keyword.  That means that these variables 
retain their values across calls to this procedure within a given 
activation group.  Also note that the buffer is is 1kB in size.
        D p_retstr        S               *
        D RetStr          S          32766A   based(p_retstr)
        D len             S             10I 0
        c                   eval      len = 0
        c                   eval      p_retstr = text
        c                   eval      %subst(RetStr:1:MaxLen) = *blanks
        c                   dow       1=1
        C* Load the buffer
        c                   if        rdpos>=rdlen
I'm guessing that your first line (the file header) is less than 1 kB 
long.  Suppose your file is 2 kB long and the first line is 256 bytes 
long.  Then, after reading the first line in program 1, you call this 
routine from program 2.  When you hit this line, rdpos = 256, and rdlen = 
1024.  Therefore, we don't read from the file again, and just continue 
processing what is left in the buffer.
Hope this helps,
Adam
Attention:
The information contained in this message and or attachments is 
intended only for the person or entity to which it is addressed and may contain 
confidential and/or privileged material. Any review, retransmission, 
dissemination or other use of, or taking of any action in reliance upon, this 
information by persons or entities other than the intended recipient is 
prohibited. If you received this message in error, please contact the sender 
and 
delete the material from any system and destroy any copies. Thank you for your 
time and consideration.
Attention: 
Le contenu de ce message et(ou) les fichiers ci-joints s?adressent 
exclusivement à la personne ou -entité à laquelle ils sont destinés. Ils 
peuvent 
contenir de l?information confidentielle, protégée et(ou) classifiée. Il est 
strictement interdit à toute personne ou entité autre que le(la) destinataire 
prévu(e) de ce message d?examiner, de réviser, de retransmettre ou de diffuser 
cette information, de prendre une quelconque action en fonction ou sur la base 
de celle-ci, ou d?en faire tout autre usage. Si vous avez reçu ce message par 
erreur, veuillez communiquer avec l?expéditeur(trice), supprimer ce message et 
les fichiers ci-inclus de tout système, et en détruire toutes copies, qu?elles 
soient électroniques ou imprimées. Nous vous remercions de votre entière 
collaboration. 
As an Amazon Associate we earn from qualifying purchases.