Reading file to structure



IBM's cross-platform compiler PL/I for MVS, VM & VSE, OS/390 and Enterprise PL/I for z/OS

Reading file to structure

Postby aidanmcg33 » Sun May 24, 2009 11:31 pm

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?
aidanmcg33
 
Posts: 1
Joined: Sun May 24, 2009 11:28 pm
Has thanked: 0 time
Been thanked: 0 time

Re: Reading file to structure

Postby Jarek.B » Thu Jun 04, 2009 10:03 pm

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.
Jarek.B
 
Posts: 2
Joined: Fri May 08, 2009 9:52 pm
Has thanked: 0 time
Been thanked: 0 time


Return to PL/I

 


  • Related topics
    Replies
    Views
    Last post