Read Statement



Support for OS/VS COBOL, VS COBOL II, COBOL for OS/390 & VM and Enterprise COBOL for z/OS

Read Statement

Postby ++mani++ » Mon Jan 28, 2013 8:21 pm

Hi,

Can any body help reagarding Read statement.

In file1 there are 10 records and if use

Read file1 into ws-rec1
At end
------------
Not At end
----------
move ws-rec1 to file2
Write file2

if i use the above syntax, read will be in loop until it reaches the end of file? or it read only 1 record at a time and write to output file
++mani++
 
Posts: 1
Joined: Mon Jan 28, 2013 8:11 pm
Has thanked: 0 time
Been thanked: 0 time

Re: Read Statement

Postby BillyBoyo » Mon Jan 28, 2013 9:06 pm

Yes, as you have shown it, that pseudo-code would only attempt one read, and one write if the read was not at end.
BillyBoyo
Global moderator
 
Posts: 3804
Joined: Tue Jan 25, 2011 12:02 am
Has thanked: 22 times
Been thanked: 265 times

Re: Read Statement

Postby c62ap90 » Mon Jan 28, 2013 9:16 pm

As written/coded you would only read and write 1-record. To get all records create a loop, for example, "GO TO" … and then AT END [no more records] do - whatever (I put GOBACK to end program).

Good Luck.

       100-READ-FILE1.           
           READ FILE1             
               INTO WS-REC1       
                AT END           
                   GOBACK         
           END-READ.             
                                 
           MOVE WS-REC1 TO FILE2.
           WRITE FILE2.           
                                 
           GO TO 100-READ-FILE1. 
c62ap90
 
Posts: 125
Joined: Thu Oct 11, 2012 10:24 pm
Has thanked: 1 time
Been thanked: 7 times

Re: Read Statement

Postby BillyBoyo » Mon Jan 28, 2013 9:36 pm

Why suggest GO TO to a novice? It is going to be much more useful to get a bit of PERFORM experience than to use GO TO which might be banned/limited by local standards.
BillyBoyo
Global moderator
 
Posts: 3804
Joined: Tue Jan 25, 2011 12:02 am
Has thanked: 22 times
Been thanked: 265 times

Re: Read Statement

Postby c62ap90 » Mon Jan 28, 2013 9:55 pm

As I noted, it's just an example and a good statement to show how a loop is done to a novice. Sure, PERFORM works well too. Why not show us…
Thanks.
c62ap90
 
Posts: 125
Joined: Thu Oct 11, 2012 10:24 pm
Has thanked: 1 time
Been thanked: 7 times


Return to IBM Cobol

 


  • Related topics
    Replies
    Views
    Last post