Reading file and printing



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

Reading file and printing

Postby Alison Oliveira » Wed Feb 08, 2012 9:11 pm

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!!!
Alison Oliveira
 
Posts: 37
Joined: Fri Jan 20, 2012 9:08 pm
Has thanked: 0 time
Been thanked: 0 time

Re: Reading file and printing

Postby enrico-sorichetti » Wed Feb 08, 2012 9:49 pm

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
Last edited by enrico-sorichetti on Wed Feb 08, 2012 9:58 pm, edited 2 times in total.
cheers
enrico
When I tell somebody to RTFM or STFW I usually have the page open in another tab/window of my browser,
so that I am sure that the information requested can be reached with a very small effort
enrico-sorichetti
Global moderator
 
Posts: 3006
Joined: Fri Apr 18, 2008 11:25 pm
Has thanked: 0 time
Been thanked: 165 times

Re: Reading file and printing

Postby Akatsukami » Wed Feb 08, 2012 9:51 pm

Alison Oliveira wrote:when i put the "put skips" in "do while" don´t print anything...

Please show the declaration of W_END_FILE.
"You have sat too long for any good you have been doing lately ... Depart, I say; and let us have done with you. In the name of God, go!" -- what I say to a junior programmer at least once a day
User avatar
Akatsukami
Global moderator
 
Posts: 1058
Joined: Sat Oct 16, 2010 2:31 am
Location: Bloomington, IL
Has thanked: 6 times
Been thanked: 51 times

Re: Reading file and printing

Postby Alison Oliveira » Wed Feb 08, 2012 9:57 pm

*-----------------------------------------------------------------*
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);                                 
 /*----------------------------------------------------------------*/                                                   


=)
Alison Oliveira
 
Posts: 37
Joined: Fri Jan 20, 2012 9:08 pm
Has thanked: 0 time
Been thanked: 0 time

Re: Reading file and printing

Postby Akatsukami » Wed Feb 08, 2012 10:10 pm

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);                     
"You have sat too long for any good you have been doing lately ... Depart, I say; and let us have done with you. In the name of God, go!" -- what I say to a junior programmer at least once a day
User avatar
Akatsukami
Global moderator
 
Posts: 1058
Joined: Sat Oct 16, 2010 2:31 am
Location: Bloomington, IL
Has thanked: 6 times
Been thanked: 51 times

Re: Reading file and printing

Postby Alison Oliveira » Wed Feb 08, 2012 10:12 pm

Thanks a lot Akatsukami, and i am male!!! kkkkkkkkkkkk i am SR.

and thanks enrico-sorichetti
Now it´s working!!!
=))))
Alison Oliveira
 
Posts: 37
Joined: Fri Jan 20, 2012 9:08 pm
Has thanked: 0 time
Been thanked: 0 time

Re: Reading file and printing

Postby Akatsukami » Wed Feb 08, 2012 10:34 pm

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.
"You have sat too long for any good you have been doing lately ... Depart, I say; and let us have done with you. In the name of God, go!" -- what I say to a junior programmer at least once a day
User avatar
Akatsukami
Global moderator
 
Posts: 1058
Joined: Sat Oct 16, 2010 2:31 am
Location: Bloomington, IL
Has thanked: 6 times
Been thanked: 51 times

Re: Reading file and printing

Postby prino » Thu Feb 09, 2012 3:20 am

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.
Robert AH Prins
robert.ah.prins @ the.17+Gb.Google thingy
User avatar
prino
 
Posts: 641
Joined: Wed Mar 11, 2009 12:22 am
Location: Vilnius, Lithuania
Has thanked: 3 times
Been thanked: 29 times

Re: Reading file and printing

Postby NicC » Thu Feb 09, 2012 10:52 am

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.
The problem I have is that people can explain things quickly but I can only comprehend slowly.
Regards
Nic
NicC
Global moderator
 
Posts: 3025
Joined: Sun Jul 04, 2010 12:13 am
Location: Pushing up the daisies (almost)
Has thanked: 4 times
Been thanked: 136 times


Return to PL/I

 


  • Related topics
    Replies
    Views
    Last post