Page 1 of 1

Reading file to structure

PostPosted: Sun May 24, 2009 11:31 pm
by aidanmcg33
I have the following structure :
DCL 1 CUSTOMER_REC BASED(CUST_PTR),
   3 CUSTOMER_FIRST CHAR(10),
   3 CUSTOMER_SECOND CHAR(10),
   3 ADDRESS,
      5 LINE1 CHAR(20),
      5 LINE2 CHAR(20),
      5 LINE3 CHAR(20),
   3 BALANCE PIC ‘(5)9V9’;


I want to read a file which contains x number of records and carry out some conditional operations on the records.

I think i have an idea how to read one record into the program, but how can i code it that all records are recorded regardless of how many are in the file?

Re: Reading file to structure

PostPosted: Thu Jun 04, 2009 10:03 pm
by Jarek.B
I presume you're asking how to read all records of a file?
Well, since your record layout is a BASED variable, I think the best way is:
 DCL  your record layout here
 DCL  cust_ptr POINTER;
 DCL  eof      BIT INIT('0'B);

 ON ENDFILE(myfile)  eof='1'B;

 READ FILE(myfile) SET(cust_ptr);

 DO WHILE(¬eof);
      do your operations here, f.i. PUT SKIP LIST('input',customer_first,' ',customer_second);
      READ FILE(myfile) SET(cust_ptr);
 END;

(Btw. the programming element used here is called "loop" ;) ). Regards.