Page 1 of 1

Reading file and printing

PostPosted: Wed Feb 08, 2012 9:11 pm
by Alison Oliveira
Hello...
I am trying to read a file and print him... for tests and i don´t understand why don´t print...
a piece of the code :
ON ENDFILE (MYSORTO) W_END_FILE = '1'B;     
OPEN FILE (SYSPRINT);                       
OPEN FILE (MYSORTO);                         
READ FILE (MYSORTO) INTO (ESTRUT);           
PUT SKIP EDIT('PLANET = ',PLANET) (A);       
IF W_END_FILE = '1' THEN DO;                 
  PUT SKIP EDIT('ARQUIVO VAZIO!!!') (A);     
  STOP;                                     
END;                                         
ELSE DO;                                     
   DO WHILE(W_END_FILE);                     
       READ FILE (MYSORTO) INTO (ESTRUT);   
       ESTRUT = ' ';                         
   END;                                     
END;                                         
       PUT SKIP EDIT('PLANET = ',PLANET) (A);
CLOSE FILE(MYSORTO);                         


when i put the "put skips" in "do while" don´t print anything...

why????

Thanks for helps!!!

Re: Reading file and printing

PostPosted: Wed Feb 08, 2012 9:49 pm
by enrico-sorichetti
fixed a glitch, NOE it works
 ****** ***************************** Top of Data ******************************
 000001  zmf04:                                                                 
 000002      Proc Options(Main);                                               
 000003      dcl eof1   fixed bin(31) init(0)  ;                               
 000004      dcl coun   fixed bin(31) init(0)  ;                               
 000005      dcl buff   char(80);                                               
 000006      dcl sysut1 file record sequential input env(recsize(80));         
 000007      put  skip list('ZMF04   Started');                                 
 000008      on endfile(sysut1) eof1 = 1;                                       
 000009      open file(sysut1) ;                                               
 000010      read file(sysut1) into(buff) ;                                     
 000011      do  while ( eof1 = 0 ) ;                                           
 000012          coun = coun + 1;                                               
 000013          put  skip list('buff =',buff ); ;                             
 000014          read file(sysut1) into(buff) ;                                 
 000015      end ;                                                             
 000016      put  skip list('coun =',coun );                                   
 000017      put  skip list('ZMF04   Ended');                                   
 000018      End  ;                                                             
 ****** **************************** Bottom of Data ****************************


IMHO a DO WHILE is easier to understand than a DO UNTIL :D

Re: Reading file and printing

PostPosted: Wed Feb 08, 2012 9:51 pm
by Akatsukami
Alison Oliveira wrote:when i put the "put skips" in "do while" don´t print anything...

Please show the declaration of W_END_FILE.

Re: Reading file and printing

PostPosted: Wed Feb 08, 2012 9:57 pm
by Alison Oliveira
*-----------------------------------------------------------------*
PROG: PROC OPTIONS (MAIN) REORDER;                                 
/*----------------------------------------------------------------*
DCL MYSORTO FILE RECORD INPUT ENV (FB RECSIZE (80) TOTAL);         
DCL SYSPRINT EXTERNAL FILE PRINT;                                 
/*----------------------------------------------------------------*
DCL 1 ESTRUT,                                                     
     2 PLANET   CHAR (80);                                         
 /*----------------------------------------------------------------*/
 DCL W_END_FILE   BIT(1)  INIT('0'B);                                 
 /*----------------------------------------------------------------*/                                                   


=)

Re: Reading file and printing

PostPosted: Wed Feb 08, 2012 10:10 pm
by Akatsukami
Your problem, Sra. Oliveira, is here:
   DO WHILE(W_END_FILE);                     

Since W_END_FILE is declared BIT(1), this statement is equivalent to
   DO WHILE(W_END_FILE='1'B);                     

As W_END_FILE is initialized to '0'B, the condition is false, and the DO WHILE block is never executed. Change the statement to
   DO WHILE(¬W_END_FILE);                     

Re: Reading file and printing

PostPosted: Wed Feb 08, 2012 10:12 pm
by Alison Oliveira
Thanks a lot Akatsukami, and i am male!!! kkkkkkkkkkkk i am SR.

and thanks enrico-sorichetti
Now it´s working!!!
=))))

Re: Reading file and printing

PostPosted: Wed Feb 08, 2012 10:34 pm
by Akatsukami
Alison Oliveira wrote:Thanks a lot Akatsukami, and i am male!!! kkkkkkkkkkkk i am SR.

Washi-domo wa shazai, Sr. Oliveira. In the U.S., "Alison" is an androgynous name, but much more frequently female than male these days.

Re: Reading file and printing

PostPosted: Thu Feb 09, 2012 3:20 am
by prino
enrico-sorichetti wrote:IMHO a DO WHILE is easier to understand than a DO UNTIL :D

For processing a file you would rarely, if ever, use "do until" as that requires extra coding to process an empty file.

Re: Reading file and printing

PostPosted: Thu Feb 09, 2012 10:52 am
by NicC
You, also, should not open/close SYSPRINT. It has been done for you by the PL/1 environment. Doing it in your code may lose messages written by the environment.