Page 1 of 1

Read Statement

PostPosted: Mon Jan 28, 2013 8:21 pm
by ++mani++
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

Re: Read Statement

PostPosted: Mon Jan 28, 2013 9:06 pm
by BillyBoyo
Yes, as you have shown it, that pseudo-code would only attempt one read, and one write if the read was not at end.

Re: Read Statement

PostPosted: Mon Jan 28, 2013 9:16 pm
by c62ap90
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. 

Re: Read Statement

PostPosted: Mon Jan 28, 2013 9:36 pm
by BillyBoyo
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.

Re: Read Statement

PostPosted: Mon Jan 28, 2013 9:55 pm
by c62ap90
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.