Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Cobol help for a complete beginner

Status
Not open for further replies.

Heartfang

Programmer
Aug 20, 2015
1
0
0
US
Hello, I am a complete beginner to Cobol and I am looking for some help.

I am a CS graduate at my first job and my IT company has decided that I now need to learn Cobol. They have pretty much told me to go teach myself and I have come to expect little in the way of assistance. What I am hoping someone here could do would be to direct me to some good resources/tutorials for someone who has object oriented programming and is now needing to learn how to do mainframe related tasks with Cobol and JCL.

I already tried the tutorials on but I found their grammar atrocious and afterward felt I learned little. I have been looking at completed programs but often feel that they make no sense with my oop background.

An example snippet (Which I found while googling examples link) of my confusion is:

READ STUDENT-FILE
AT END MOVE 'NO' TO DATA-REMAINS-SWITCH
END-READ.
PERFORM PROCESS-RECORDS
UNTIL DATA-REMAINS-SWITCH = 'NO'.


With my background, I read that the second part would never occur because the until condition is already fulfilled. Obviously I am missing something.

Thank you for your time.
 
AT END is the EOF condition with the COBOL READ command. With COBOL you have to indicate what you want done when it happens. In this case, "NO" is moved to DATA-REMAINS-SWITCH. Since DATA-REMAINS-SWITCH is initialized to " " (or SPACES), the only condition that will cause the PERFORM to not work is if there is no data to read in STUDENT-FILE. This is what you want.

As for instructional texts, this is the best thing out there bar none. If you have OOP down, procedural coding (what COBOL is) won't be a problem for you. Just think of each program as one long method. More likely though, COBOL is a bit weird in some respects (all languages are), so you'll just have to get through the learning curve aspect of it.

 
The 1. part
Code:
READ STUDENT-FILE
  AT END 
    MOVE 'NO' TO DATA-REMAINS-SWITCH
END-READ
reads only 1.record of the file (when the file has no more record it sets the DATA-REMAINS-SWITCH = 'NO')

Then the 2. part is a loop, which reads the rest of the file
Code:
PERFORM 
  PROCESS-RECORDS
UNTIL DATA-REMAINS-SWITCH = 'NO'.

Look into the paragraf PROCESS-RECORDS - after processing of the record (i.e. printing) it contains the same as in the 1.part (i.e. reading next record):
Code:
...
READ STUDENT-FILE
  AT END 
    MOVE 'NO' TO DATA-REMAINS-SWITCH
END-READ.

When the PROCESS-RECORD should not contain reading of the next record,
then you could try something like this
Code:
MOVE 'YES' TO DATA-REMAINS-SWITCH
PERFORM UNTIL DATA-REMAINS-SWITCH = 'NO'
  READ FILE
    AT END
      MOVE 'NO' TO DATA-REMAINS-SWITCH
    NOT AT END
      PERFORM PROCESS-RECORD
  END-READ
END-PERFORM
 
There are several mainframe forums out there that will help you along. The IBM manuals that you will need are available online and usually linked to from those forums.


Nic
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top