MVSFORUMS.com Forum Index MVSFORUMS.com
A Community of and for MVS Professionals
 
 FAQFAQ   SearchSearch   Quick Manuals   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

regarding input procedures in sort

 
Post new topic   Reply to topic   printer-friendly view    MVSFORUMS.com Forum Index -> Application Programming
View previous topic :: View next topic  
Author Message
kirank
Beginner


Joined: 21 Apr 2004
Posts: 61
Topics: 33
Location: hyderabad

PostPosted: Thu Apr 29, 2004 2:11 am    Post subject: regarding input procedures in sort Reply with quote

Hi,
i've a doubt in the following code:
Code:

     SelectCSISGraduates.
    OPEN INPUT GraduateInfoFile
    READ GraduateInfoFile
       AT END SET EndOfGradFile TO TRUE
    END-READ
    PERFORM UNTIL EndOfGradFile
       IF CSISGraduate
          MOVE StudentNameGF TO StudentNameWF
          MOVE GradYearGF    TO GradYearWF
          MOVE CourseCodeGF  TO CourseCodeWF
          MOVE EmailDomainGF TO EmailDomainWF
          MOVE CountryCodeGF TO CountryCodeWF
          RELEASE WorkRec
       ELSE
          DISPLAY "Rejected - " StudentNameGF SPACE CourseCodeGF
       END-IF
       READ GraduateInfoFile
         AT END SET EndOfGradFile TO TRUE
       END-READ
    END-PERFORM
    CLOSE GraduateInfoFile.


SelectCSISGraduates is a input procedure name.

my doubt is he is using READ verb two times in the code. But he is closing the file only one time.

But as per my knowledge , if we want open the same file two times, then, the procedure is:

first we open the file
then closethe file then
the again opend the same file
then close the file.


pls , clarify the doubt
Back to top
View user's profile Send private message
Mike Chantrey
Intermediate


Joined: 10 Sep 2003
Posts: 234
Topics: 1
Location: Wansford

PostPosted: Thu Apr 29, 2004 9:27 am    Post subject: Reply with quote

Just to expand on the 'why two reads' aspect - it is not logically necessary, you can code an equivalent with only one read in the loop as per below, but this is less efficient since you effectively have an test statement inside the loop to prevent processing beyond the end of the file.
Example recoded with one READ:
Code:


Select CSISGraduates.
OPEN INPUT GraduateInfoFile
SET EndOfGradFile TO FALSE

PERFORM UNTIL EndOfGradFile

      READ GraduateInfoFile
        NOT AT END   
 
          IF CSISGraduate
             MOVE StudentNameGF TO StudentNameWF
             MOVE GradYearGF TO GradYearWF
             MOVE CourseCodeGF TO CourseCodeWF
             MOVE EmailDomainGF TO EmailDomainWF
             MOVE CountryCodeGF TO CountryCodeWF
             RELEASE WorkRec
          ELSE
             DISPLAY "Rejected - " StudentNameGF SPACE CourseCodeGF
          END-IF

        AT END
          SET EndOfGradFile TO TRUE
      END-READ
END-PERFORM

CLOSE GraduateInfoFile.


This assumes your COBOL dialgoue supports NOT AT END (as IBM m/f COBOL does for COBOL 2 onwards); if not you can use an IF statement for the same effect.
As per above, it's probably a little less efficient than having an extra 'priming read' (as it's often called) before the loop but if you're doing I/O anyhow the tiny bit of extra CPU will probably not matter. And I think it's a bit more understandable (though I know that's a matter of opinion).
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic   printer-friendly view    MVSFORUMS.com Forum Index -> Application Programming All times are GMT - 5 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


MVSFORUMS
Powered by phpBB © 2001, 2005 phpBB Group