Your SlideShare is downloading. ×
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Cobol from micro to mainframe
Upcoming SlideShare
Loading in...5
×

Thanks for flagging this SlideShare!

Oops! An error has occurred.

×
Saving this for later? Get the SlideShare app to save on your phone or tablet. Read anywhere, anytime – even offline.
Text the download link to your phone
Standard text messaging rates apply

Cobol from micro to mainframe

1,271

Published on

Cobol from micro to mainframe

Cobol from micro to mainframe

Published in: Education, Technology
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total Views
1,271
On Slideshare
0
From Embeds
0
Number of Embeds
0
Actions
Shares
0
Downloads
24
Comments
0
Likes
0
Embeds 0
No embeds

Report content
Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
No notes for slide

Transcript

  • 1. COBOL From Micro to Mainframe RT:elEntT T. [3Ft.AUEnl AR{f L VnzcpuEz VtLL,A,Fl ATTTHUR R. EIUgs THIRD EDITIOil
  • 2. ISBN O-I3_?1DBI7-A lffifiilflillilililllililtlflll
  • 3. T h e f o l l o w i n g s o f t w a r e a n d s u p p l e m e n t s are available f r o m P r e n t i c e Hall: • SOFTWARE—Micro F o c u s P e r s o n a l COBOL for W i n d o w s 3.1 w i t h o b j e c t orientation and Personal Dialog System. Compatible with W i n d o w s 9 5 and W i n d o w s N T , P e r s o n a l COBOL p r o v i d e s all t h e t o o l s to h e l p y o u l e a r n a n d u s e COBOL. T h e software i n c l u d e s a n i n t e g r a t e d editor, c o m p i l e r a n d a n i m a t o r for creating, d e b u g g i n g a n d e x e c u t i n g COBOL p r o g r a m s . P r e n t i c e Hall offers a n affordable p a c k a g e of COBOL: From Micro to Mainframe, Third Edition w i t h t h e M i c r o F o c u s P e r s o n a l COBOL C o m p i l e r . P l e a s e o r d e r ISBN 0-13-975178-5. e WEB S I T E — D o w n l o a d e v e r y COBOL p r o g r a m in t h e text as w e l l as d a t a files for t h e n e a r l y o n h u n d r e d s t u d e n t p r o j e c t s f r o m t h e COBOL: From Micro to Mainframe web site at: http://www.prenhall.com/grauer_cobol. • Instructor's R e s o u r c e M a n u a l (ISBN# 0 - 1 3 - 0 8 1 5 1 3 - 6 ) • P r e n t i c e Hall C u s t o m Test. B a s e d o n t h e p o w e r f u l t e s t i n g t e c h n o l o g y d e v e l o p e d b y E n g i n e e r i n g Software A s s o c i a t e s , Inc. (EAS), P r e n t i c e Hall C u s t o m T e s t a l l o w s t h e e d u c a t o r to c r e a t e a n d tailor t h e e x a m t o their o w n n e e d s . Please order ISBN* 0-13-081515-2 W e are e s p e c i a l l y grateful to o u r e d i t o r s at P r e n t i c e Hall, Laura Steele, A l a n Apt, a n d Marcia H o r t o n , w i t h o u t w h o m this p r o j e c t w o u l d n o t h a v e b e e n p o s s i b l e . W e a l s o w a n t to t h a n k t h e m a n y o t h e r i n d i v i d u a l s w h o h e l p e d p r o d u c e t h e third e d i t i o n . Irwin Zucker, w h o s u p e r v i s e d t h e p r o d u c t i o n , Kate Kaibni, editorial a s s i s t a n t , w h o w o r k e d h a r d to p r o v i d e u s w i t h t i m e l y c h a p t e r r e v i e w s , a n d Joel B e r m a n , o u r m a r k e t i n g m a n a g e r at P r e n t i c e Hall, w h o d e v e l o p e d t h e i n n o v a t i v e c a m p a i g n t o m a k e this b o o k a s u c c e s s . W e a l s o w a n t t o a c k n o w l e d g e o u r r e v i e w e r s , w h o t h r o u g h their c o m m e n t s a n d c o n s t r u c t i v e c r i t i c i s m , m a d e t h i s a far b e t t e r b o o k : R o b e r t V. B i n d e r , R o b e r t B i n d e r S y s t e m s C o n s u l t i n g , Inc. D i n o n Boyer, U n i v e r s i t y o f A k r o n G e o r g i a B r o w n , N o r t h e r n Illinois U n i v e r s i t y Jan D e L a s s e n , B r i g h a m Y o u n g U n i v e r s i t y Ida M. F l y n n , U n i v e r s i t y o f P i t t s b u r g h Frank T. Gergelyi, NJIT Ken Goldsmith, University of M i a m i T o m Gorecki, St. Charles C o m m u n i t y C o l l e g e Carol C. G r i m m , P a l m B e a c h C o m m u n i t y C o l l e g e M o n i c a H o l m e s , Central M i c h i g a n U n i v e r s i t y A n n W. H o u c k , P i m a C o m m u n i t y C o l l e g e David Lee J a m e s W. P a y n e , Kellogg C o m m u n i t y C o l l e g e N i c h o l a s R o s s , U n i v e r s i t y o f Illinois at C h i c a g o W e n d e l l I. P o p e , U t a h State U n i v e r s i t y D a n i e l H. R i n d f l e i s c h , C o m p u t e r Specialist w i t h F e d e r a l G o v e r n m e n t D a n i e l R. Rota, R o b e r t M o r r i s C o l l e g e Richard H. S a r a c u s a , N o r t h e a s t e r n U n i v e r s i t y Ron Teemley, DeVry Institute of T e c h n o l o g y D o n a t Valcourt, Northeastern University Ron Williams, M c L e n n o n C o m m u n i t y College Jackie Zucker, U n i v e r s i t y o f M i a m i
  • 4. A final w o r d o f t h a n k s t o y o u , o u r readers, for c h o o s i n g t h i s b o o k . P l e a s e feel free to c o n t a c t u s w i t h a n y c o m m e n t s or s u g g e s t i o n s via e m a i l . Robert Grauer r g r a u e r @ u m i a m i .miarni. e d u Carol Vazquez Villar Arthur R. Buss bussa@william.jewell.edu
  • 5. rreiace M i Introduction Test Data 13 Elements of COBOL 13 Reserved Words 13 Programmer-Supplied Names 14 Literals 15 Symbols 16 Level Numbers 16 Picture Clauses 17 A S e c o n d Look at COBOL 17 Summary 19 Fill-in 20 True/False 20 Problems 21 Overview 2 The First Problem 2 Programming Specifications 3 Required Logic 5 Flowcharts 6 Pseudocode 8 A First Look at COBOL 9 Identification Division 11 Environment Division 11 Data Division 11 Procedure Division 12 From Coding Form to Computer Overview 26 From Coding Form to Computer 26 The COBOL Coding Form 28 Use of an Editor 28 The Compile, Link, and Execute Sequence 30 Learning by Doing 3 2 Errors in Entering the Program 33 Errors in Operating System Commands 33 Errors in Compilation 33 Errors in Execution 35 Errors in Data Input 37 Evolution of COBOL 38 There's Always a Reason Summary 41 Fill-in 41 True/False 42 40 Problems 43 A Methodology for P r o g r a m D e v e l o p m e n t Overview 48 The Tuition Billing Problem 48 Structured Design 50 Evaluating the Hierarchy Chart Completeness 53 Functionality 54 Span of Control 54 Structured Programming 54 52 Sufficiency of the Basic Structures 56 Expressing Logic 57 The Traditional Flowchart 57 Pseudocode 57 Warnier-Orr Diagrams 59 Top-Down Testing 61 Summary 66 Fill-in 67 True/False 68 Problems 68
  • 6. Contents C h a p t e r 4 : T h e I d e n t i f i c a t i o n , Environment, a n d D a t a D i v i s i o n s 7 3 Overview 74 COBOL Notation 74 Identification Division 75 Environment Division 76 CONFIGURATION SECTION 76 INPUT-OUTPUT SECTION 76 Data Division 77 FILE SECTION 77 WORKING-STORAGE SECTION 82 The Tuition Billing Program 8 4 Programming Specifications 84 COBOL Entries 87 Limitations of COBOL-74 90 Summary 90 Fill-in 92 True/False 92 Problems 93 97 5: T h e P r o c e d u r e D i v i s i o n Overview 98 OPEN 98 CLOSE 99 READ 99 Placement of the READ Statement 100 WRITE 100 STOP RUN 102 MOVE 102 Restrictions on the Move Statement 103 Alphanumeric Field to Alphanumeric Field 103 Numeric Field to Numeric Field 104 Group Moves 105 PERFORM 105 IF 106 The ELSE Clause 106 Indentation 106 EVALUATE 109 Arithmetic Statements 109 The ROUNDED Clause 109 The SIZE ERROR Clause 110 COMPUTE 110 ADD 112 SUBTRACT 112 MULTIPLY 114 DIVIDE 115 Programming Tip: Use the COMPUTE Statement 116 Assumed Decimal Point 117 The Tuition Billing Program 118 Test Data 126 Hierarchy Chart 127 COBOL Program Skeleton 128 Limitations of COBOL-74 128 Summary 130 Fill-in 131 True/False 132 Problems 133 139 C h a p t e r 6: D e b u g g i n g Overview 140 Errors in Compilation 140 Common Compilation Errors 149 Errors in Execution 151 File Status Codes 156 Another Run Time Error 158 Logic Errors 159 Tips for Debugging 160 DISPLAY Statement 161 The Structured Walkthrough Summary 163 Fill-in 164 True/False 165 162 Problems 165
  • 7. Contents Chapter 7: Editing and Coding Standards Overview 170 Editing 170 The Decimal Point 172 Zero Suppression 172 Dollar Signs 174 Comma 174 Asterisks for Check Protection 175 Insertion Characters 175 Synopsis 175 Signed Numbers 176 CRandDB 176 Plus and Minus Signs 177 BLANK WHEN ZERO Clause 177 The Tuition Billing Program Revisited 178 Coding Standards 179 Data Division 179 Programming Tip; Avoid Literals 180 Procedure Division 181 Programming Tip: Use Scope Terminators 182 Both Divisions 183 A Well-Written Program 184 Summary 189 Fill-in 190 True/False 191 Problems 191 C h a p t e r Us Data Validation Overview 196 System Concepts: Data Validation 196 The IF Statement 197 Relational Condition 198 Class Test 199 Sign Test 200 Condition-Name Test (88-Level Entries) 200 Compound Test 200 Hierarchy of Operations 201 Implied Conditions 203 Nested IFs 203 NEXT SENTENCE 205 Cna^ici- S * More About the Overview 2 3 0 PERFORM 231 TEST BEFORE/TEST AFTER 231 In-line Perform 232 Performing Sections 232 PERFORM THRU 232 Programming Tip: Perform Paragraphs, Not Sections 233 READ 234 False-Condition Branch 234 READ INTO 235 WRITE FROM 236 INITIALIZE 236 String Processing 237 INSPECT 237 169 195 ACCEPT Statement 206 Calculations Involving Dates 206 The Stand-Alone Edit Program 2 0 7 Programming Specifications 208 Error Messages 211 Pseudocode 211 Hierarchy Chart 212 The Completed Program 212 Limitations of COBOL-74 221 Summary 2 2 3 Fill-in 224 True/False 224 Problems edure Division 225 229 STRING 238 UNSTRING 240 Reference Modification 240 ACCEPT 2 4 2 Duplicate Data Names 243 Qualification 244 MOVE CORRESPONDING 245 The Car Billing Program 246 Programming Specifications 246 Program Design 248 The Completed Program 249 Limitations of COBOL-74 258 Summary 2 5 8 Fill-in 259 True/False 260 Problems 260
  • 8. Contents w. . Overview 266 ACCEPT 266 Programming Tip: Micro Focus Level 78—The Use of COBOL Constants 267 DISPLAY 269 The Tuition Billing Program Revisited 270 Programming Specifications 270 Hierarchy Chart 271 Pseudocode 271 The Completed Program 273 Programming Tip: The Hidden Power of the Alt key 274 ... wveivl6w i"«» Introduction to Tai oud , u Car Validation and Billing Program 278 Programming Specifications 279 The Screen Section 280 Hierarchy Chart 284 Pseudocode 284 The Completed Program 287 Limitations of COBOL-74 297 Summary 297 Fill-in 298 True/False 299 Problems 299 s 301 OCCURS DEPENDING ON 310 introduction to Tables 302 OCCURS Clause 303 Processing a Table 304 PERFORM VARYING 304 A S e c o n d Example 306 Problems with the OCCURS Clause 308 Rules for Subscripts 308 Relative Subscripting 308 USAGE Clause 309 . 265 -i C: S c r e e n l-O Table Lookups Overview 332 System C o n c e p t s 332 Types of Codes 333 Characteristics of Codes 333 Sequential Table Lookup 334 Binary Table Lookup 335 Positional Organization and Direct Lookups 336 Initializing a Table 336 Hard Coding 336 Input-Loaded Tables 338 Table Lookups 339 PERFORM VARYING Statement 340 SEARCH Statement 340 The Student Transcript Program 311 Programming Specifications 311 Program Design 313 The Completed Program 314 Indexes versus Subscripts 321 The SET Statement 322 Limitations of COBOL-74 322 Summary 325 Fill-in 326 True/False 326 Problems 327 331 Programming Tip—Restrict Subscripts and Switches to a Single Use 342 SEARCH ALL Statement 344 Direct Lookup 344 Range-Step Tables 345 A Complete Example 347 Programming Specifications 347 Program Design 349 The Completed Program 350 Limitations of COBOL-74 357 Summary 357 Fill-in 358 True/False 359 Problems 360
  • 9. Contents c:; zn i. PERFORM VARYING 382 Overview 3 6 4 System C o n c e p t s 364 COBOL Implementation 366 One-Level Tables 3 6 6 PERFORM VARYING 366 A Sample Program 3 8 4 Programming Specifications 384 The Completed Program 386 Table Lookups 3 9 0 A Calorie Counter's Delight 3 9 2 Programming Specifications 392 Range-Step Tables 392 The Completed Program 394 Limitations of COBOL-74 398 Summary 3 9 8 Fill-in 399 True/False 399 Problems 400 Two-Level Tables 3 6 8 Errors in Compilation 369 PERFORM VARYING 370 A Sample Program 3 7 3 Programming Specifications 373 Program Design 375 The Completed Program 375 Three-Level Tables 3 8 0 .',[ k-,. 403 : Sorting USING/GIVING Option 4 1 4 INPUT PROCEDURE/OUTPUT PROCEDURE Option 4 1 9 Comparing Options 426 MERGE Statement 426 Limitations of COBOL-74 428 Summary 4 2 8 Fill-in 429 True/False 430 Problems 431 Overview 4 0 4 System C o n c e p t s 405 Collating S e q u e n c e 405 Embedded Sign 406 COBOL Implementation 408 SORT Statement 409 SD (Sort Description) 410 RELEASE and RETURN 410 Programming Specifications 411 . 363 Multilevel Tables i KV s.y:c,ikic Control Overview 4 3 6 System C o n c e p t s 436 Running versus Rolling Totals 440 One-Level Control Breaks 4 4 3 Programming Specifications 443 Hierarchy Chart 444 Pseudocode 446 The Completed Program 446 Two-Level Control Breaks 451 Hierarchy Chart 451 Pseudocode 452 Breaks 40 C The Completed Program 454 Three-Level Control Breaks 4 6 0 Hierarchy Chart 460 Pseudocode 462 The Completed Program 463 Programming Tip: How to Write a Control Break Program 470 Limitations of COBOL-74 471 Summary 471 Fill-in 472 True/False 472 Problems 473
  • 10. Contents 475 ' v.. Subprograms <.- j Overview 476 Subprograms 477 Called and Calling Programs 477 COPY Statement 479 Calling BY CONTENT and BY REFERENCE 480 Programming Tip: Use COPY to Pass Parameters 481 INITIAL Clause 482 A System for Physical Fitness 482 Programming Specifications 482 Hierarchy Chart 485 Pseudocode 485 cL^.;r.!r t L '. Sequential File M Overview 516 System C o n c e p t s 516 Sequential versus Nonsequential Processing 518 Periodic Maintenance 518 Data Validation 519 Programming Specifications 520 Designing the Program 523 The Completed Program 524 Sequential File Maintenance 528 _. . . Indexed F i l e s Overview 550 System C o n c e p t s 550 COBOL Implementation 554 Creating an Indexed File 5 5 6 Programming Specifications 556 Pseudocode 557 The Completed Program 557 Additional COBOL Elements 559 OPEN 559 READ 560 WRITE 562 REWRITE 562 DELETE 562 The Completed Programs 486 Main Program (FITNESS) 486 Input Program (INPUTSUB) 490 Weight-Range Program (WGTSUB) 495 Training Program (TRAINSUB) 498 Display Program (DSPLYSUB) 498 Time Program (TIMESUB) 503 The Linkage Editor 5 0 4 Problems with the Linkage Editor 505 Limitations of COBOL-74 506 Summary 508 Fill-in 509 True/False 509 Problems 510 intenance 515 Programming Specifications 528 The Balance Line Algorithm 529 Designing the Hierarchy Chart 531 Top-Down Testing 535 The Stubs Program 535 The Completed Program 540 Summary 545 Fill-in 546 True/False 546 Problems 547 549 Maintaining an Indexed File 5 6 3 Programming Specifications 563 Hierarchy Chart 564 Pseudocode 566 The Completed Program 566 Alternate Record Key 5 7 0 Programming Specifications 570 Concatenated Key 573 The START Statement 574 Limitations of COBOL-74 574 Summary 576 Fill-in 577 True/False 578 Problems 578
  • 11. Contents v J - : ^ , T h e Year 2000 Problem Overview 5 8 4 The Year 2 0 0 0 Problem 5 8 4 Date Arithmetic 5 9 0 COBOL Intrinsic Calendar Functions 591 583 Leap-Year Problem 5 9 4 Retirement Program Revisited 594 Summary 5 9 9 Fill-in 600 True/False 600 Problems 601 a : Object-Oriented C O B O L Programming .iv"' Overview 6 0 4 The Next Generation of COBOL 605 The Development of Structured Programming 606 Terminology 607 The Object-Oriented versus Structured Paradigm 608 Student-Look-UP Program 612 The Registrar Class 616 Classes and Inheritance 619 ProcessRequests Method 619 603 The StudentDM Class 621 The StudentDM Instance Definition 625 The Student Class 627 The Person Class 630 The Student Ul Class 633 The Student PRT Class 635 Conclusion 639 Summary 6 4 0 Fill-in 641 True/False 641 Problems 642 Micro F o c u s Personal C O B O L for Windows: U s e r s Guide and Tutorial 643 Getting Started R e s e r v e d Words uiL 1 697 709 l : C O B O L - 8 5 R e f e r e n c e Summary C^C^BC^IiHa 1997j 1 < C | 1 <999^ ^C^OC^§i 01 9 9 ^$ 711 s A n s w e r s to Odd-Numbered E x e r c i s e s Projects 737 745 7 5 3 893
  • 12. Overview The First Problem Programming Specifications Required Logic Flowcharts Pseudocode A First Look at COBOL Identification Division Environment Division Data Division Procedure Division Test Data Elements of COBOL Reserved Words Programmer-Supplied Names Literals Symbols Level Numbers PICTURE Clauses A Second Summary Fill-in True/False Problems Look at COBOL
  • 13. Chapter E 1 — Introduction S After reading this chapter you will be able to: Define the terms: field, record, and file. Name two techniques used to express program logic. Identify the four divisions of a C O B O L program. State the six C O B O L language elements. State the rules for creating a programmer-supplied name; distinguish between examples of valid and invalid names. State the difference between numeric and nonnumeric literals; recognize valid and invalid examples of e a c h . Follow the logic of a simple program a s e x p r e s s e d in a flowchart or pseudocode. This book is about computer programming. In particular, it is about C O B O L , a widely used commercial programming language. Programming involves the translation of an algorithm ( a precise means of solving a problem) into a form the computer c a n understand. Programming is necessary b e c a u s e , despite reports to the contrary, computers cannot think for themselves. Instead, they do exactly what they have been instructed to do, and these instructions take the form of a computer program. The advantage of the computer stems from its s p e e d and accuracy. It does not do anything that a human being could not do, given sufficient time and memory capacity. We begin our study of computer programming by describing a simple problem and then developing the logic and C O B O L program to solve it. This rapid entrance into C O B O L is somewhat different from the approach followed by most textbooks, but we believe in learning by doing. There is nothing very mysterious about C O B O L programming, so let's get started. Our first p r o b l e m is s e t in t h e c o n t e x t o f a university, a n d i n v o l v e s a s e t o f s t u d e n t r e c o r d s , o n e r e c o r d p e r s t u d e n t . E a c h record c o n t a i n s t h e s t u d e n t ' s n a m e , n u m b e r o f c o m p l e t e d credits, a n d major. I m p l i c i t i n t h i s s t a t e m e n t a r e t h e d e f i n i t i o n s o f t h r e e f u n d a m e n t a l t e r m s : field, r e c o r d , a n d file. A field is a b a s i c fact, s u c h a s t h e n a m e , a d d r e s s , major, g r a d e p o i n t average, or n u m b e r of c o m p l e t e d credits. A record is a s e t o f fields, a n d a file is a s e t o f r e c o r d s . T h u s , if there w e r e 1,000 s t u d e n t s , t h e r e w o u l d b e 1,000 r e c o r d s ( o n e for e a c h s t u d e n t ) , e a c h c o n s i s t i n g o f five fields, a n d c o m p r i s i n g a s i n g l e s t u d e n t file. T o clarify t h i s r e l a t i o n s h i p , w e c r e a t e four h y p o t h e t i c a l s t u d e n t s for o u r p r o b l e m : J o h n A d a m s , A m e l i a Earhart, Orville Wright, a n d G e o r g i a O'Keeffe. There are m a n y facts a b o u t e a c h o f o u r s t u d e n t s , b u t o u r p r o b l e m utilizes o n l y three:
  • 14. The First Problem Fields, Records, and Files (Facts) (Set of Fields) Name Credits Major John Adams 9G Political Science Name Credits. Major Amelia Earhart 120 Aviation John Adams (Set of Records) f90 [ Political Science J Amelia Earhart 120 Aviation ohin Adams A n i 6 | XI, A ji || i* | if Name Credits Major Orville Wright 115 Engineering Name Credits Major: Qgomi» O Keeffe 125 Art [J Orville Wright JTlS^Tf" Engineering i a Earhart 0rvi « e Wright 90 120 Political Science Aviation Engineering f I Georgia O'Keeffel 125 n a m e , major, a n d credits c o m p l e t e d . Figure 1.1 r e p r e s e n t s t h e s e c o n c e p t s i n pictorial f a s h i o n . E a c h fact a b o u t e a c h s t u d e n t c o m p r i s e s a s i n g l e field. T h e t h r e e fields c o l l e c t i v e l y m a k e u p t h a t s t u d e n t ' s r e c o r d . T h e four r e c o r d s ( o n e for e a c h of o u r s t u d e n t s ) c o m p o s e t h e s t u d e n t file. T h e p r o b l e m is t o p r o c e s s t h e file o f s t u d e n t r e c o r d s a n d p r o d u c e a list o f e n g i n e e r i n g s t u d e n t s w h o h a v e c o m p l e t e d m o r e t h a n 110 credits. It is a typical p r o b l e m , i n that its s o l u t i o n will a d d r e s s t h e t h r e e e l e m e n t s c o m m o n t o all c o m p u t e r a p p l i c a t i o n s : i n p u t , p r o c e s s i n g , a n d o u t p u t . A s s h o w n i n Figure 1.2, t h e s t u d e n t file, j u s t d e f i n e d , is t h e input, this file is processed b y d e t e r m i n i n g w h i c h s t u d e n t s are e n g i n e e r i n g m a j o r s w i t h m o r e t h a n 110 credits; a n d c o n s e q u e n t l y , a r e p o r t is created as output, reflecting t h e s e s t u d e n t s . T h e i n p u t t o a c o m p u t e r p r o g r a m ; that is, t h e p r e c i s e a r r a n g e m e n t of t h e v a r i o u s fields i n e a c h i n c o m i n g record, h a s t o b e s p e c i f i e d exactly. F i g u r e 1.3a is a c o m m o n w a y t o c o m m u n i c a t e this i n f o r m a t i o n , a n d s h o w s that t h e s t u d e n t ' s n a m e is c o n t a i n e d i n p o s i t i o n s 1 - 2 5 , t h e n u m b e r of c r e d i t s i n p o s i t i o n s 2 6 - 2 8 , a n d t h e s t u d e n t ' s m a j o r in p o s i t i o n s 2 9 - 4 3 . N o t e t o o , that every r e c o r d i n a g i v e n file m u s t have t h e identical record layout. In similar f a s h i o n , t h e report p r o d u c e d as o u t p u t is also p r e c i s e l y d e s i g n e d . Figure 1.3c s h o w s a print l a y o u t chart, i n w h i c h d e s c r i p t i v e i n f o r m a t i o n a p p e a r s o n l i n e o n e , w i t h t h e n a m e s o f s e l e c t e d s t u d e n t s i n c o l u m n s 9 - 3 3 of s u b s e q u e n t l i n e s . O b s e r v e a l s o that t h e l o c a t i o n o f t h e n a m e field is different i n t h e i n p u t a n d o u t p u t r e c o r d s ( p o s i t i o n s 1 - 2 5 a n d 9 - 3 3 , r e s p e c t i v e l y ) , a n d that e a c h i n p u t record c o n t a i n s t h r e e fields, b u t that e a c h l i n e of o u t p u t h a s b e e n d e s i g n e d t o c o n t a i n o n l y o n e field. It is i m p o r t a n t that p r o g r a m m i n g s p e c i f i c a t i o n — t h a t is, t h e i n p u t , p r o c e s s i n g , a n d o u t p u t r e q u i r e m e n t s — b e p r e s e n t e d in a clear a n d u n a m b i g u o u s fashion.
  • 15. Chapter 1 — Introduction i ^ / e t "i Input, Processing, and Output IHPUT John «aams Engineering major with more than 110 credits 90 Atnelii Earhart 120 . Aviation OrviH, Wright 115 SU E T NM T DN A E O VL E W I H R I L RG T la o 6 re 1,3 Engineering —-— 0 Engineering Senior (Input and Output) CREDITS S T U D E N T NAME 1 2 3 4 5 6 7 !) STUDENT MAJOR 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 (s) £>ttident Recc rd Layout JOHN ADAMS AMELIA EARHART ORVILLE WRIGHT GEORGIA 0'KEEFE 090P0LITICAL SCI 120AVIATI0N 115ENGINEERING 125ART (b) Test Data STUDENT NAME XXXXXXXXXXXXXXXXXXXXXXXXX xxxxxxxxxxxxxxxxxxxxxxxxx (c) Print Layout
  • 16. Required Logic A c c o r d i n g l y , t h e a u t h o r s h a v e a d o p t e d t h e f o r m a t s h o w n b e l o w , a n d u s e it t h r o u g h o u t t h e text for b o t h illustrative p r o g r a m s a n d s t u d e n t a s s i g n m e n t s . T h e p r o g r a m m i n g s p e c i f i c a t i o n s b e g i n w i t h t h e p r o g r a m n a m e a n d a brief narrative, f o l l o w e d b y a d e t a i l e d d e s c r i p t i o n o f t h e v a r i o u s r e q u i r e m e n t s . N o t e , t o o , that t h e s p e c i f i c a t i o n d o c u m e n t is entirely s e l f - c o n t a i n e d , a n d that if t h e p e r s o n p r e p a r i n g t h e s p e c i f i c a t i o n s h a s d o n e a c o m p l e t e j o b , t h e r e will b e little n e e d for t h e p r o g r a m m e r to s e e k a d d i t i o n a l i n f o r m a t i o n . P R O G R A M M I N G Program Name: Narrative: S P E C I F I C A T I O N S Engineering Senior Program This program processes a file of student records and prints the name of every student who is an engineering major with more than 110 credits. Input File(s): STUDENT-FILE Input Record Layout: See Figure 1.3a Test Data: See Figure 13b Report Layout: See Figure 1,3c Processing Requirements: 1. Print a heading iine. 2. Read a file of student records. 3. For every record, determine whether that student has a major of engineering and has completed more than 110 credits. 4. Print the name of every student who satisfies the requirements in item 3 above. Singlespace the output. i L^v„ L v . ^ . ^ Let us imagine m o m e n t a r i l y that the student records are physically in the form of manila folders, stored in a filing cabinet, and further that a clerk is available to d o our work. Our p r o b l e m is to instruct the clerk o n h o w to go through the folders. We w o u l d say s o m e t h i n g to the following effect: R e p e a t s t e p s 1 t h r o u g h 4 until t h e r e are n o m o r e folders: 1. S e l e c t a folder. 2. E x a m i n e t h e folder t o s e e if that s t u d e n t is a n e n g i n e e r i n g m a j o r a n d h a s m o r e t h a n 110 credits. 3. If t h e s t u d e n t m e e t s b o t h q u a l i f i c a t i o n s , w r i t e t h e s t u d e n t ' s n a m e o n a r u n n i n g list. 4. Return t h e folder t o t h e file c a b i n e t . Stop In e s s e n c e , w e h a v e p r e p a r e d a s e r i e s o f i n s t r u c t i o n s for t h e c l e r k t o follow. If o u r i n s t r u c t i o n s a r e c o r r e c t a n d if t h e y a r e f o l l o w e d exactly, t h e n t h e clerk will produce the desired results.
  • 17. Chapter A computer program 1 — Introduction is a s e t o f i n s t r u c t i o n s , w r i t t e n a c c o r d i n g t o a p r e c i s e aci e i iatca, v i x i uic ^ciiiipuid » vi ^i iiucipicio a u j u ouuotqucntiy C A t i a u Cuc . m i c uic i^ clerk, h o w e v e r , t h e c o m p u t e r a l w a y s f o l l o w s o u r i n s t r u c t i o n s exactly. I n o t h e r w o r d s , the computer does what we tell it to do, which is not necessarily what we want it to do. A h u m a n clerk, o n t h e o t h e r h a n d , h a s a m i n d o f h i s o r h e r o w n a n d c a n q u e s t i o n or alter e r r o n e o u s i n s t r u c t i o n s . S i n c e t h e c o m p u t e r d o e s p r e c i s e l y w h a t it i s t o l d , it is i m p e r a t i v e that y o u strive t o w r i t e logically correct p r o g r a m s . A c c o r d i n g l y , y o u m u s t e x p e n d s i g n i f i c a n t effort prior to actual coding to d e v e l o p a p r o g r a m ' s l o g i c correctly. T w o c o m m o n t e c h n i q u e s for e x p r e s s i n g t h a t l o g i c are flowcharts a n d pseudocode. A f l o w c h a r t is a pictorial r e p r e s e n t a t i o n o f t h e l o g i c i n h e r e n t i n a p r o g r a m . It is t h e t r a n s l a t i o n o f a p r o b l e m s t a t e m e n t i n t o a l o g i c a l b l u e p r i n t t h a t is s u b s e q u e n t l y i n c o r p o r a t e d i n t o the COBOL p r o g r a m . A flowchart to list t h e e n g i n e e r i n g s t u d e n t s w i t h m o r e t h a n 110 c r e d i t s is s h o w n i n Figure 1.4. A flowchart u s e s blocks with specific s h a p e s t o indicate t h e nature of a n o p e r a t i o n . U s i n g Figure 1.4 as a g u i d e , w e s e e that a d i a m o n d - s h a p e d block indicates a d e c i s i o n , a p a r a l l e l o g r a m d e p i c t s i n p u t or output, a n e l l i p s e s h o w s the b e g i n n i n g or e n d , a n d a r e c t a n g l e i m p l i e s straightforward p r o c e s s i n g . A r e c t a n g l e w i t h vertical lines implies that the p r o c e s s i n g within the rectangle will b e expanded into a f l o w c h a r t o f its o w n . T o u n d e r s t a n d t h e f l o w c h a r t i n Figure 1.4, c o n s i d e r t h e n a t u r e o f a READ s t a t e m e n t . T h e f u n c t i o n o f a READ i n s t r u c t i o n is t o o b t a i n a r e c o r d , b u t t h e r e will a l w a y s b e a p o i n t w h e n a READ i s a t t e m p t e d a n d n o r e c o r d is f o u n d , that is, w h e n all t h e r e c o r d s i n t h e file h a v e already b e e n read. S i n c e o n e d o e s n o t k n o w i n a d v a n c e h o w m a n y r e c o r d s a file c o n t a i n s , t h e READ i n s t r u c t i o n m u s t a l s o test for t h e end-of-file c o n d i t i o n . T h u s , if a file c o n t a i n s t w o r e c o r d s , it i s a c t u a l l y r e a d t h r e e t i m e s ( o n c e for e a c h r e c o r d , a n d o n c e t o s e n s e t h e e n d - o f - f i l e c o n d i t i o n ) . T h e f l o w c h a r t i n Figure 1.4 b e g i n s w i t h a start b l o c k ( b l o c k 1), a n d c o n t i n u e s w i t h v a r i o u s h o u s e k e e p i n g b l o c k s . H o u s e k e e p i n g c o n s i s t s o f s t a t e m e n t s that are d o n e o n c e a t t h e start o f p r o c e s s i n g , for e x a m p l e , o p e n i n g files ( b l o c k 2), r e a d i n g t h e first r e c o r d ( b l o c k 3), a n d w r i t i n g a h e a d i n g a t t h e start o f a report (block 4). C o n t r o l t h e n p a s s e s t h r o u g h a c o n n e c t o r b l o c k ( b l o c k 5) t o a d e c i s i o n s t a t e m e n t (block 6). If t h e e n d - o f - f i l e h a s n o t b e e n r e a c h e d , c o n t r o l g o e s to t h e PROCESS-RECORDS block, w h i c h is e x p a n d e d i n t h e right s i d e o f t h e figure. E a c h i n c o m i n g r e c o r d is c h e c k e d i n b l o c k 9 t o d e t e r m i n e if it m e e t s b o t h q u a l i f i c a t i o n s . If s o , t h a t s t u d e n t ' s n a m e i s w r i t t e n t o t h e o u t p u t r e p o r t i n b l o c k 10; if n o t , c o n t r o l g o e s d i r e c t l y to t h e c o n n e c t o r i n b l o c k 11. ( N o t e that b o t h t h e t r u e a n d false b r a n c h e s for t h e c o n d i t i o n i n b l o c k 9 m e e t a t a s i n g l e c o n n e c t o r i n b l o c k 11.) T h e next r e c o r d is r e a d i n b l o c k 12, a n d t h e P R O C E S S - R E C O R D S b l o c k is f i n i s h e d . C o n t r o l t h e n m o v e s t o t h e left s i d e o f t h e figure, t o t h e c o n n e c t o r i n b l o c k 5 t o t h e e n d - o f - f i l e test in b l o c k 6. E v e n t u a l l y , w h e n t h e e n d - o f - f i l e has b e e n r e a c h e d , c o n t r o l will p a s s t o c l o s e files ( b l o c k 7), t h e n t o t h e s t o p s t a t e m e n t i n b l o c k 8. To better u n d e r s t a n d h o w t h e flowchart works, w e c a n u s e t h e test data of Figure 1.1 a n d p l a y c o m p u t e r , b y r u n n i n g t h e d a t a t h r o u g h t h e f l o w c h a r t . E x e c u t i o n b e g i n s b y o p e n i n g t h e files, r e a d i n g t h e first r e c o r d (John A d a m s ) , a n d w r i t i n g t h e h e a d i n g l i n e . T h e e n d - o f - f i l e h a s not b e e n r e a c h e d , s o b l o c k 6 d i r e c t s f l o w t o b l o c k 9, t h e t e s t for e n g i n e e r i n g m a j o r s w i t h m o r e t h a n 110 c r e d i t s . J o h n A d a m s fails t h e test, s o c o n t r o l p a s s e s t o t h e c o n n e c t o r in b l o c k 1 1 , t o t h e READ i n b l o c k 12, w h e r e u p o n the d a t a for A m e l i a Earhart are r e a d i n t o m e m o r y . C o n t r o l f l o w s t h r o u g h
  • 18. Required Logic Flowchart to Select Engineering Seniors t h e c o n n e c t o r o f b l o c k 5, t o t h e end-of-file test i n b l o c k 6, a n d t h e n t o t h e qualification t e s t in b l o c k 9. A m e l i a Earhart fails t h e test, a g a i n p a s s i n g c o n t r o l to t h e c o n n e c t o r in b l o c k 11, to t h e READ in b l o c k 12, at w h i c h p o i n t Orville W r i g h t is r e a d i n t o m e m o r y . H o w e v e r , Wright is a n e n g i n e e r i n g m a j o r w i t h m o r e t h a n 110 credits, s o h e p a s s e s t h e t e s t a n d h i s n a m e is w r i t t e n in b l o c k 10. T h e d a t a for G e o r g i a O'Keeffe are r e a d in b l o c k 12, a n d c o n t r o l flows o n c e m o r e to t h e c o n n e c t o r i n b l o c k 5, to t h e e n d - o f - f i l e test i n b l o c k 6. R e a l i z e , h o w e v e r , t h a t e v e n t h o u g h O'Keeffe is t h e last r e c o r d , t h e e n d - o f - f i l e c o n d i t i o n h a s not y e t b e e n d e t e c t e d . O'Keeffe fails t h e q u a l i f i c a t i o n test, w h e r e u p o n c o n t r o l flows t o t h e READ i n b l o c k 12. T h i s t i m e t h e e n d - o f - f i l e is d e t e c t e d s o that, w h e n c o n t r o l a g a i n r e a c h e s t h e e n d - o f - f i l e t e s t i n b l o c k 6, p r o c e s s i n g will b e d i r e c t e d t o t h e CLOSE FILES a n d STOP s t a t e m e n t s i n b l o c k s 7 a n d 8.
  • 19. Chapter _' .. 1 Introduction i The Flow chart and Test Data 1 Start At beginning of program 2 Open files At beginning of program 3 Initial read Reads the first record (Adams) 4 Write heading A t 5 Connector Entered five times 6 End-of-file test Once for each of four records; once to sense end-of-file condition K i ^ * ,^ r ; -, , ^r^r^m 7 Close files Once, before execution stops 8 Stop Executed once, at program's end 9 Qualifying test Once for each student 10 Write Executed for Wright only 11 Connector Entered four times 12 Read Reads every record but the first, and detects the end-of-file condition It is useful to summarize this discussion by tabulating the n u m b e r of times each block in Figure 1.4 is executed. This is s h o w n in Table 1.1. Pseudocode e x p r e s s e s a program's logic m o r e c o n c i s e l y t h a n a flowchart. O n e neat notes to oneself, d e f i n i t i o n o f p s e u d o c o d e is a n d s i n c e p r o g r a m m e r s d o this naturally, p s e u d o c o d e h a s r e p l a c e d t h e t r a d i t i o n a l f l o w c h a r t i n m a n y i n s t a l l a t i o n s . C o n s i d e r F i g u r e 1.5, w h i c h c o n t a i n s i d e n t i c a l l o g i c t o t h e f l o w c h a r t i n Figure 1.4, albeit in a m o r e c o n c i s e fashion. As s h o w n i n Figure 1.5, t h e l o g i c o f m o s t p r o g r a m s c a n b e d i v i d e d i n t o t h r e e major portions: initialization, processing, a n d termination. Initialization is d o n e o n c e at t h e start o f p r o c e s s i n g — f o r e x a m p l e , o p e n i n g files, r e a d i n g t h e first r e c o r d i n a file, a n d w r i t i n g a h e a d i n g . T h i s is f o l l o w e d b y a s e r i e s o f i n s t r u c t i o n s t h a t are e x e c u t e d r e p e a t e d l y , o n c e for e a c h i n c o m i n g r e c o r d ; e.g., e a c h r e c o r d is e v a l u a t e d for a n e n g i n e e r i n g m a j o r w i t h t h e r e q u i s i t e n u m b e r o f c r e d i t s . If b o t h c o n d i t i o n s are m e t , t h e n a m e w i l l b e w r i t t e n o n t h e registrar's list; if t h e c o n d i t i o n s are n o t m e t , Pseudocode Open f i l e s Initialization Read f i r s t record Write heading D w h i l e data remains O IF e n g i n e e r i n g major with more than 110 c r e d i t s Write s t u d e n t ' s name Processing ENDIF Read next record ENDDO Termination Close Stop files
  • 20. A First Look at COBOL n o t h i n g further is d o n e w i t h t h e particular r e c o r d . W h e n all o f t h e r e c o r d s in t h e file h a v e b e e n read, t h e l o o p is finished, a n d a t e r m i n a t i o n r o u t i n e is e n t e r e d t o print a total or s i m p l y s t o p p r o c e s s i n g . Figure 1.5 a l s o c o n t a i n s vertical l i n e s c o n n e c t i n g t h e w o r d s IF a n d ENDIF, a n d D O a n d E N D D O . This n o t a t i o n i n d i c a t e s t w o o f t h e b a s i c b u i l d i n g b l o c k s {selection a n d iteration) o f a d i s c i p l i n e k n o w n a s structured programming w h i c h is fully e x p l a i n e d i n C h a p t e r 3. P s e u d o c o d e u s e s i n s t r u c t i o n s similar t o t h o s e o f a c o m p u t e r l a n g u a g e t o d e s c r i b e p r o g r a m logic, b u t i s not b o u n d b y p r e c i s e s y n t a c t i c a l rules f o u n d i n formal p r o g r a m m i n g l a n g u a g e s . For e x a m p l e , t h e vertical l i n e s referred to p r e v i o u s l y are t h e a u t h o r s ' c o n v e n t i o n a n d d o n o t n e c e s s a r i l y a p p e a r i n t h e p s e u d o c o d e o f o t h e r s . N o r is p s e u d o c o d e b o u n d b y a n y rules for i n d e n t a t i o n , w h i c h is d o n e strictly at t h e d i s c r e t i o n o f t h e p e r s o n u s i n g it. T h e p u r p o s e o f p s e u d o c o d e is s i m p l y t o c o n v e y p r o g r a m l o g i c i n a straightforward a n d easily f o l l o w e d m a n n e r . W e p r o c e e d to t h e COBOL p r o g r a m in Figure 1.6, w h i c h c o r r e s p o n d s to t h e flowchart i n Figure 1.4 a n d t h e p s e u d o c o d e i n Figure 1.5. T h e s y n t a c t i c a l rules for COBOL are e x t r e m e l y p r e c i s e , a n d y o u a r e certainly not e x p e c t e d t o r e m e m b e r t h e m after a brief e x p o s u r e t o Figure 1.6. T h e a u t h o r s b e l i e v e , h o w e v e r , that immediate exposure to a real program is extremely beneficial in stripping the mystical aura that too often The First COBOL Program l 2 3 4 5 6 7 8 9 IDENTIFICATION DIVISION. PROGRAM-ID. SENIOR. ROBERT GRAUER. AUTHOR. ENVIRONMENT DIVISION. INPUT-OUTPUT SECTION. FILE-CONTROL. SELECT STUDENT-FILE ASSIGN TO 'A:CHAPTR02SENI0R.DAT ORGANIZATION IS LINE SEQUENTIAL. SELECT PRINT-FILE 10 11 12 13 14 15 16 17 18 19 20 21 22 ASSIGN TO PRINTER. DATA DIVISION. FILE SECTION. FD STUDENT-FILE 01 RECORD CONTAINS 43 CHARACTERS DATA RECORD IS STUDENT-IN. STUDENT-IN. 05 STU-NAME PIC X(25). PIC 05 05 STU-CREDITS STU-MAJ0R PIC 9(3). PIC PIC X(15). PIC
  • 21. Chapter re 1.6 23 24 25 26 27 28 29 30 31 32 33 34 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 1 - Introduction (continued) FD 01 PRINT-FILE RECORD CONTAINS 132 CHARACTERS DATA RECORD IS PRINT-LINE. PRINT-LINE PIC X(132). WORKING-STORAGE SECTION. 01 DATA-REMAINS-SWITCH 01 01 PIC X(2) VALUE SPACES. HEADING-LINE. 05 FILLER 05 FILLER 05 FILLER PIC X(10) PIC X(12) PIC X(110) VALUE SPACES. VALUE 'STUDENT NAME' VALUE SPACES. DETAIL-LINE. 05 FILLER 05 PRINT-NAME 05 FILLER PIC X(8) PIC 1(25). PIC X(99) VALUE SPACES. ~~~Da(a Division VALUE SPACES. I PROCEDURE DIVISION. PREPARE-SENIOR-REPORT. OPEN INPUT STUDENT-FILE OUTPUT PRINT-FILE. READ STUDENT-FILE AT END MOVE 'NO' TO DATA-REMAINS-SWITCH END-READ. PERFORM WRITE-HEADING-LINE. PERFORM PROCESS-RECORDS UNTIL DATA-REMAINS-SWITCH = 'NO'. CLOSE STUDENT-FILE PRINT-FILE. STOP RUN. WRITE-HEADING-LINE. MOVE HEADING-LINE TO PRINT-LINE. WRITE PRINT-LINE. PROCESS-RECORDS. IF STU-CREDITS > 110 AND STU-MAJOR = 'ENGINEERING' MOVE STU-NAME TO PRINT-NAME MOVE DETAIL-LINE TO PRINT-LINE WRITE PRINT-LINE END-IF. READ STUDENT-FILE AT END MOVE 'NO' TO DATA-REMAINS-SWITCH END-READ. Procedure Division
  • 22. surrounds programming. Further, Figure 1.6 will b e c o m e e a s i e r t o u n d e r s t a n d after s o m e brief e x p l a n a t i o n . Every COBOL p r o g r a m c o n s i s t s o f four d i v i s i o n s , w h i c h m u s t a p p e a r i n t h e f o l l o w i n g order: IDENTIFICATION DIVISION The Identification Division contains the program n a m e a n d author's n a m e . ENVIRONMENT DIVISION T h e E n v i r o n m e n t D i v i s i o n a s s o c i a t e s t h e file n a m e s referenced in a program to t h e input a n d o u t p u t (I/O) d e v i c e s r e c o g n i z e d b y t h e o p e r a t i n g system. DATA DIVISION The Data Division describes the record layout of t h e i n c o m i n g record(s) a n d t h e l o c a t i o n o f d a t a in t h e g e n e r a t e d report. PROCEDURE DIVISION The Procedure Division contains the program logic, t h a t is, t h e i n s t r u c t i o n s t h e c o m p u t e r is t o e x e c u t e in s o l v i n g t h e p r o b l e m . S i n c e COBOL is i n t e n d e d t o r e s e m b l e English, y o u m a y b e a b l e t o g e t a n overall s e n s e of w h a t is h a p p e n i n g , m e r e l y b y r e a d i n g t h e p r o g r a m . W e p r o v i d e a n intuitive e x p l a n a t i o n a n d reiterate that, at this t i m e , y o u s h o u l d i n n o w a y b e c o n c e r n e d w i t h t h e p r e c i s e s y n t a x of t h e l a n g u a g e ; that is, o u r p r e s e n t i n t e n t is t o t e a c h COBOL b y e x a m p l e , w i t h t h e s h o r t - t e r m o b j e c t i v e of a c h i e v i n g a c o n c e p t u a l u n d e r s t a n d i n g of a COBOL p r o g r a m . T h e Identification Division .... T h e I D E N T I F I C A T I O N D I V I S I O N (Lines 1-3) a p p e a r s at t h e b e g i n n i n g of e v e r y p r o g r a m . It s e r v e s t o identify t h e p r o g r a m (SENIOR) a n d t h e a u t h o r (Robert Grauer). T h e r e is n o t h i n g c o m p l i c a t e d a b o u t this d i v i s i o n , a n d it h a s n o effect o n t h e r e s u l t s of the program. T h e E n i o v r n m n e t Division T h e E N V I R O N M E N T D I V I S I O N (lines 5-11) c o n t a i n s t h e I N P U T - O U T P U T SECTION, w h i c h d e s c r i b e s t h e files u s e d b y t h e p r o g r a m . T h e e n g i n e e r i n g s e n i o r p r o g r a m u s e s t w o files, a n i n p u t file c o n t a i n i n g t h e s t u d e n t r e c o r d s a n d a n o u t p u t file for t h e report. B o t h o f t h e s e files are d e f i n e d i n SELECT s t a t e m e n t s . T h e n a m e s c h o s e n b y t h e p r o g r a m m e r for t h e s e files (that is, S T U D E N T - F I L E a n d PRINT-FILE) are a s s i g n e d t o logical d e v i c e s k n o w n t o t h e o p e r a t i n g s y s t e m , b y t h e SELECT s t a t e m e n t a n d a s s o c i a t e d ASSIGN c l a u s e . Line 8, for e x a m p l e , ties t h e i n c o m i n g STUDENT-FILE t o t h e file SENIOR.DAT; this tells t h e o p e r a t i n g s y s t e m t o read t h e file c o n t a i n i n g t h e i n c o m i n g s t u d e n t r e c o r d s f r o m t h e file SENIOR.DAT. (The format o f t h e file n a m e is i n s t a l l a t i o n d e p e n d e n t a n d varies f r o m c o m p u t e r t o c o m p u t e r . ) T h e c l a u s e ORGANIZATION IS LINE SEQUENTIAL is r e q u i r e d t o properly p r o c e s s s e q u e n t i a l files o n p e r s o n a l c o m p u t e r s . M a i n f r a m e s e q u e n t i a l files h a v e a different f o r m a t a n d d o n o t r e q u i r e this c l a u s e . T h e D < ^ &i vision a .,.„„.., T h e D A T A D I V I S I O N (lines 1 3 - 3 9 ) d e s c r i b e s all d a t a e l e m e n t s u s e d b y t h e p r o g r a m . It is d i v i d e d i n t o t w o s e c t i o n s , t h e FILE SECTION (lines 1 4 - 2 6 ) a n d t h e WORKINGSTORAGE SECTION (lines 2 8 - 3 9 ) .
  • 23. Chapter 1 Introduction T h e FILE SECTION c o n t a i n s file d e s c r i p t i o n (FD) e n t r i e s for files p r e v i o u s l y d e n n e d i n SELECT s t a t e m e n t s . T h e F D for STUDENT-FILE e x t e n d s f r o m l i n e 15 to l i n e 17 a n d c o n t a i n s c l a u s e s that d e s c r i b e t h e p h y s i c a l c h a r a c t e r i s t i c s o f t h e file. T h e F D is f o l l o w e d b y a record description, w h i c h d e f i n e s t h e v a r i o u s fields w i t h i n t h e r e c o r d (lines 1 8 - 2 1 ) . T h e s t a t e m e n t s w i t h i n t h e r e c o r d d e s c r i p t i o n are p r e c e d e d b y level numbers, in this e x a m p l e , 01 a n d 05. T h e level n u m b e r 0 1 is s p e c i a l a n d i n d i c a t e s t h e b e g i n n i n g of a record description entry. T h e fields w i t h i n a r e c o r d are d e f i n e d t h r o u g h a s e r i e s of PICTURE c l a u s e s (PIC is a n a c c e p t a b l e a b b r e v i a t i o n ) , w h i c h i n d i c a t e t h e type a n d size o f t h e field. A p i c t u r e o f 9's i n d i c a t e s a n u m e r i c field, w h e r e a s a p i c t u r e o f X's signifies a n a l p h a n u m e r i c field. T h e n u m b e r i n p a r e n t h e s e s i n d i c a t e s t h e s i z e o f t h e field; for e x a m p l e , PIC 9 ( 3 ) i n d i c a t e s a t h r e e - p o s i t i o n n u m e r i c field, a n d PIC X(25) is a 2 5 - p o s i t i o n a l p h a n u m e r i c field. T h e PICTURE c l a u s e s i n l i n e s 1 9 - 2 1 o f F i g u r e 1.6 are c o n s i s t e n t w i t h t h e r e c o r d d e s c r i p t i o n i n t h e o r i g i n a l problem statement. T h e WORKING-STORAGE SECTION (lines 2 8 - 3 9 ) is u s e d to d e f i n e a n y d a t a n a m e s that d o n o t a p p e a r in a n i n p u t or o u t p u t file. T h e p r o g r a m m i n g s p e c i f i c a t i o n s c a l l e d for t w o d i s t i n c t print l i n e s (a h e a d i n g l i n e a n d a d e t a i l l i n e ) , e a c h o f w h i c h c o n t a i n s a different f o r m a t as p e r t h e print l a y o u t of F i g u r e 1.3. A c c o r d i n g l y , t w o different 01 e n t r i e s are d e f i n e d , H E A D I N G - L I N E a n d DETAIL-LINE, e a c h w i t h a different l a y o u t . T h e f u n c t i o n o f DATA-REMAINS-SWITCH w i l l b e m a d e clearer after a n e x a m i n a t i o n o f t h e P r o c e d u r e D i v i s i o n . The P R O C E D U R E DIVISION (lines 4 1 - 6 7 ) c o n t a i n s t h e l o g i c r e q u i r e d t o s o l v e t h e p r o b l e m . T h e P r o c e d u r e D i v i s i o n is d i v i d e d i n t o paragraphs, with each paragraph c o n s i s t i n g o f o n e or m o r e s e n t e n c e s . T h e first p a r a g r a p h , PREPARE-SENIOR-REPORT, e x t e n d s f r o m l i n e 4 2 t o l i n e 53. It b e g i n s b y o p e n i n g t h e files, t h e n r e a d i n g t h e first s t u d e n t r e c o r d . T h e PERFORM s t a t e m e n t i n l i n e 4 8 transfers c o n t r o l t o t h e p a r a g r a p h WRITE-HEADING-LINE (lines 5 5 - 5 7 ) , w h i c h p r i n t s t h e h e a d i n g , t h e n r e t u r n s c o n t r o l b a c k t o l i n e 4 9 i n t h e PREPARE-SENIOR-REPORT p a r a g r a p h . T h i s t o o is a PERFORM s t a t e m e n t , w h i c h transfers control to the paragraph PROCESS-RECORDS (lines 5 9 - 6 7 ) , w h i c h p r o c e s s e s i n c o m i n g s t u d e n t r e c o r d s until t h e d a t a file is e x h a u s t e d . T h e IF s t a t e m e n t in l i n e 6 0 d e t e r m i n e s w h e t h e r a n i n c o m i n g r e c o r d m e e t s b o t h q u a l i f i c a t i o n s , t h a t is, w h e t h e r t h e s t u d e n t is a n e n g i n e e r i n g m a j o r a n d h a s m o r e t h a n 110 c r e d i t s . If b o t h c o n d i t i o n s are m e t , that s t u d e n t ' s n a m e is w r i t t e n to t h e o u t p u t report. T h e IF s t a t e m e n t e x t e n d s to t h e E N D - I F scope terminator in l i n e 64; that is, if t h e c o n d i t i o n i n l i n e 6 0 is m e t , every s t a t e m e n t b e t w e e n t h e c o n d i t i o n a n d t h e E N D - I F in l i n e 6 4 will b e e x e c u t e d . N o t e , t o o , t h a t t h r e e COBOL s t a t e m e n t s are r e q u i r e d t o p r o d u c e a detail line; t h e i n c o m i n g n a m e is m o v e d to t h e o u t p u t n a m e i n l i n e 6 1 , t h e d e t a i l l i n e is m o v e d t o t h e print l i n e i n l i n e 62, a n d t h e l i n e is written in line 63. T h e a c t i o n o f t h e PERFORM s t a t e m e n t is e x p l a i n e d w i t h t h e a i d of Figure 1.7. The PERFORM s t a t e m e n t in line 49 transfers control to the paragraph PROCESS-RECORDS, until DATA-REMAINS-SWITCH = 'NO', t h a t is, u n t i l t h e d a t a file is e m p t y . A c c o r d i n g l y , t h e last s t a t e m e n t of t h e p e r f o r m e d r o u t i n e is a READ s t a t e m e n t to r e a d t h e n e x t r e c o r d . W h e n t h e e n d - o f - f i l e is r e a c h e d , t h e AT E N D c l a u s e o f t h e READ s t a t e m e n t will m o v e ' N O ' to D A T A - R E M A I N S - S W I T C H t o t e r m i n a t e t h e PERFORM; t h e READ s t a t e m e n t itself is e n d e d b y t h e E N D - R E A D s c o p e t e r m i n a t o r . C o n t r o l t h e n r e t u r n s t o t h e s t a t e m e n t u n d e r t h e PERFORM s t a t e m e n t (to l i n e 51), w h i c h c l o s e s t h e files, a n d finally t o t h e STOP R U N s t a t e m e n t , which terminates the program.
  • 24. Procedure Division Logic PROCEDURE DIVISION PREPARE-SENIOR-REPORT. OPEN INPUT STUDENT-FILE OUTPUT PRINT-FILE. READ STUDENT-FILE AT END MOVE 'NO' TO DATA-REMINS-SWITCH END-READ PERFORM WRITE-HEADING-LINE. PERFORM PROCESS RECORDS 1 UNTIL DATA-REMAINS-SWITCH = 'NO'. PROCESS-RECORDS. IF STU-CREDITS > 110 AND STU-MAJOR = 'ENGINEERING' MOVE STU-NAME TO PRINT-NAME MOVE DETAIL-LINE TO PRINT-LINE WRITE PRINT-LINE END-IF READ STUDENT-FILE CLOSE STUDENT-FILE pKiNl-FiLE. STOP RUN. Figure 1.8 c o n t a i n s test d a t a a n d t h e a s s o c i a t e d o u t p u t p r o d u c e d b y t h e p r o g r a m i n Figure 1.6. (Five m o r e r e c o r d s h a v e b e e n a d d e d t o p r o v i d e a d d i t i o n a l e x a m p l e s . ) You s h o u l d b e a b l e t o s t a t e t h e r e a s o n s w h y i n d i v i d u a l r e c o r d s w e r e n o t s e l e c t e d for t h e o u t p u t report; for e x a m p l e , A m e l i a Earhart a n d Alex Bell w e r e r e j e c t e d for t h e w r o n g m a j o r a n d a n insufficient n u m b e r of c r e d i t s , r e s p e c t i v e l y . ( C a n y o u identify all n i n e of o u r f a m o u s students?) A l t h o u g h y o u are n o t y e t e x p e c t e d to w r i t e a COBOL p r o g r a m , y o u s h o u l d b e a b l e to f o l l o w s i m p l e p r o g r a m s like t h e o n e in Figure 1.6 intuitively. T h i s s e c t i o n b e g i n s a f o r m a l d i s c u s s i o n o f COBOL s o that y o u will e v e n t u a l l y b e a b l e t o w r i t e a n e n t i r e program. COBOL c o n s i s t s o f s i x l a n g u a g e e l e m e n t s : r e s e r v e d w o r d s , p r o g r a m m e r s u p p l i e d n a m e s , literals, s y m b o l s , level n u m b e r s , a n d p i c t u r e s . Reserved words h a v e s p e c i a l s i g n i f i c a n c e t o COBOL a n d are u s e d i n a rigidly p r e s c r i b e d m a n n e r . T h e y m u s t b e s p e l l e d correctly, or t h e c o m p i l e r w i l l n o t b e a b l e
  • 25. Chapter 1 — Introduction Test Data and Associated Output 090POLTICAL SCI 120AVIATION I 115ENGINEERING 125ART 115TRAVEL 115POLITICAL SCI JOHN ADAMS AMELIA E A R H A R T ORVILLE W R I G H T G E O R G I A O'KEEFE M E R I W E T H E R LEWIS JOHN KENNEDY ALEX BELL EMILY DICKINSON J O H N ROEBLING 090ENGINEERING 085LITERATURE 115ENGINEERING STUDENT N A M E ORVILLE W R I G H T J O H N ROEBLING to r e c o g n i z e t h e m . T h e list of r e s e r v e d w o r d s varies f r o m c o m p i l e r t o c o m p i l e r . A c o m p r e h e n s i v e list o f r e s e r v e d w o r d s is g i v e n i n A p p e n d i x C. T h e b e g i n n e r is u r g e d to refer f r e q u e n t l y t o this a p p e n d i x for t w o r e a s o n s : (1) t o e n s u r e t h e p r o p e r s p e l l i n g o f r e s e r v e d w o r d s u s e d i n h i s o r h e r p r o g r a m ; a n d (2) t o a v o i d t h e i n a d v e r t e n t u s e o f reserved w o r d s as programmer-supplied n a m e s . You, t h e p r o g r a m m e r , s u p p l y n a m e s for p a r a g r a p h s , d a t a e l e m e n t s , a n d files. A paragraph name is a t a g t o w h i c h t h e p r o g r a m refers, for e x a m p l e , PROCESSRECORDS or PREPARE-SENIOR-REPORT in Figure 1.6. Data names are t h e e l e m e n t s o n w h i c h i n s t r u c t i o n s o p e r a t e , for e x a m p l e , S T U - N A M E , S T U - C R E D I T S , a n d S T U MAJOR in F i g u r e 1.6. File names are s p e c i f i e d in s e v e r a l p l a c e s t h r o u g h o u t a COBOL p r o g r a m , b u t t h e i r initial a p p e a r a n c e is i n t h e E n v i r o n m e n t D i v i s i o n , for e x a m p l e , S T U D E N T - F I L E a n d PRINT-FILE i n Figure 1.6. All p r o g r a m m e r - s u p p l i e d n a m e s are c h o s e n a c c o r d i n g t o t h e f o l l o w i n g rules: 1. A p r o g r a m m e r - s u p p l i e d n a m e m a y c o n t a i n t h e l e t t e r s A t o Z, t h e d i g i t s 0 t o 9, a n d t h e h y p h e n ; n o o t h e r c h a r a c t e r s are p e r m i t t e d , n o t e v e n b l a n k s .
  • 26. Elements of COBOL 2. A p r o g r a m m e r - s u p p l i e d n a m e m a y rcof b e g i n or e n d w i t h a h y p h e n . 3. A p r o g r a m m e r - s u p p l i e d n a m e m u s t b e 30 c h a r a c t e r s or f e w e r i n l e n g t h . 4. A r e s e r v e d w o r d m a y not be u s e d a s a p r o g r a m m e r - s u p p l i e d n a m e . 5. D a t a n a m e s m u s t c o n t a i n at l e a s t o n e letter. 6. P a r a g r a p h n a m e s m a y b e all n u m e r i c . T a b l e 1.2 illustrates e x a m p l e s of t h e rules a s s o c i a t e d w i t h p r o g r a m m e r - s u p p l i e d names. 1.2 Programmer-Supplied Names SUM Invalid—reserved word SUM-OF-X Valid S U M OF X Invalid—contains blanks SUM-OF-X- invalid—ends with a hyphen SUM-OF-ALL-THE-XS Valid SUM-OF-ALL-THE-XS-IN-ENTIRE-PROGRAM I n v a l i d -more than 30 characters GROSS-PAY-IN-$ Invalid—contains a $ 12345 V a l i d as a paragraph name but invalid as a data name A literal or is a n e x a c t v a l u e or c o n s t a n t . Literals are of t w o t y p e s , nonnumeric numeric (a n u m b e r ) (a c h a r a c t e r string). Literals of b o t h t y p e s a p p e a r t h r o u g h o u t a p r o g r a m a n d are u s e d to c o m p a r e t h e v a l u e of a d a t a n a m e to a s p e c i f i e d c o n s t a n t . C o n s i d e r l i n e 60 o f F i g u r e 1.6: IF STU-CREDITS > 110 AND STU-MAJOR = 'ENGINEERING 1 In t h e first p o r t i o n o f t h e s t a t e m e n t , STU-CREDITS is c o m p a r e d to 1 1 0 , a n u m e r i c literal. N u m e r i c literals a d h e r e to t h e f o l l o w i n g rules: 1. A n u m e r i c literal c a n b e u p to 18 digits l o n g . 2. A n u m e r i c literal m a y b e g i n w i t h a l e a d i n g ( l e f t m o s t ) p l u s or m i n u s s i g n . 3. A n u m e r i c literal m a y c o n t a i n a d e c i m a l p o i n t , b u t it m a y not e n d w i t h a decimal point. T h e s e c o n d p a r t o f t h e IF s t a t e m e n t contains a nonnumeric literal, 'ENGINEERING'. N o n n u m e r i c literals a d h e r e to t h e f o l l o w i n g rules: 1. A n o n n u m e r i c literal is e n c l o s e d i n a p o s t r o p h e s (or q u o t a t i o n m a r k s ) a s specified by the compiler. 2. A n o n n u m e r i c literal m a y b e u p to 160 c h a r a c t e r s i n l e n g t h . 3. A n o n n u m e r i c literal m a y c o n t a i n a n y t h i n g , i n c l u d i n g b l a n k s , n u m b e r s , a n d r e s e r v e d w o r d s , b u t n o t a n o t h e r a p o s t r o p h e (or q u o t a t i o n m a r k ) . E x a m p l e s of b o t h n u m e r i c a n d n o n n u m e r i c literals are s h o w n T a b l e 1.3.
  • 27. C h a p t e r 1 Introduction Numeric and Nonnumeric Literals 123.4 Valid numeric literal '123.4' Valid nonnumeric literal +123 Valid numeric literal 'IDENTIFICATION DIVISION' Valid nonnumeric literal i c^. :t i v a u v j i i u i i i c i ivj n i d i a i 123- Invalid numeric literal—the minus sign must be in the leftmost position i i lay i u i c i t u w i n i a i j ^ ^ n i ic*i p w n l i Symbols are of t h r e e t y p e s — p u n c t u a t i o n , a r i t h m e t i c , a n d r e l a t i o n a l , a s l i s t e d in T a b l e 1.4. IfelLfr: 1 , 4 Symbols Denotes end of C O B O L entry Punctuation Delineates clauses 1 or" () Sets off nonnumeric literals Encloses subscripts or expressions Addition Subtraction Arithmetic + Multiplication Division Exponentiation / Equal to Greater than Relational > Less than < Greater than or equal to >= Less than or equal to <= T h e u s e o f r e l a t i o n a l a n d a r i t h m e t i c s y m b o l s is d e s c r i b e d i n detail later in t h e text, b e g i n n i n g i n C h a p t e r 4. A p e r i o d t e r m i n a t e s a n entry, a n d i t s o m i s s i o n (in t h e a b s e n c e o f a s c o p e t e r m i n a t o r ) c a n c a u s e difficulty. A c o m m a , o n t h e o t h e r h a n d , is e n t i r e l y o p t i o n a l , a n d its o m i s s i o n (or i n c l u s i o n ) h a s n o effect w h a t s o e v e r o n t h e p r o g r a m . T h e u s e o f c o m m a s is d i s c o u r a g e d , h o w e v e r , a s a c o m m a c a n b e m i s t a k e n for a p e r i o d o n o l d e r printers, w h i c h t e n d to b l u r t h e o u t p u t . Level numbers d e s c r i b e t h e r e l a t i o n s h i p o f i t e m s in a r e c o r d . F o r e x a m p l e , u n d e r S T U D E N T - F I L E in Figure 1.6, t h e r e w a s a s i n g l e 0 1 - l e v e l e n t r y a n d several 0 5 - l e v e l e n t r i e s . In g e n e r a l , t h e h i g h e r ( n u m e r i c a l l y ) t h e l e v e l n u m b e r , t h e l e s s s i g n i f i c a n t t h e entry; t h u s 0 5 is l e s s i m p o r t a n t t h a n 0 1 . E n t r i e s w i t h h i g h e r n u m e r i c v a l u e s are s a i d t o b e l o n g t o t h e l e v e l s a b o v e t h e m . T h u s , i n F i g u r e 1.6 t h e s e v e r a l 0 5 - l e v e l entries b e l o n g to their respective 01-level entries.
  • 28. A Second Look at COBOL P I C T U R E C l a u s e s , Pictures d e s c r i b e t h e n a t u r e of i n c o m i n g o r o u t g o i n g data. A p i c t u r e o f 9's m e a n s t h e entry is n u m e r i c ; a p i c t u r e of X's m e a n s t h e entry is a l p h a n u m e r i c , that is, it c a n c o n t a i n letters, n u m b e r s , a n d s p e c i a l c h a r a c t e r s . (Alphabetic p i c t u r e s , w i t h a p i c t u r e o f A, are s e l d o m u s e d ; e v e n n a m e s c a n c o n t a i n a p o s t r o p h e s o r h y p h e n s , w h i c h are a l p h a n u m e r i c rather t h a n a l p h a b e t i c i n n a t u r e . ) Level n u m b e r s a n d p i c t u r e s are d i s c u s s e d m o r e fully i n C h a p t e r 4. I'iguie 1.9 c o n t a i n s a r e l a b e l e d v e r s i o n of t h e E n g i n e e r i n g S e n i o r P r o g r a m a n d r e p r e s e n t s a s e c o n d l o o k at COBOL. This t i m e o u r i n t e n t i o n is to e m p h a s i z e t h e v a r i o u s COBOL e l e m e n t s a s t h e y a p p e a r in a c o m p l e t e p r o g r a m . The Engineering Senior Program (A S e c o n d Look) 1 IDENTIFICATION DIVISION. | 2 PROGRAM-ID. SENIOR. | 3 AUTHOR. ROBERT GRAUER. | 4 [ 5 6 INPUT-OUTPUT SECTION. 7 FILE-CONTROL. 8 SELECT I ENVIRONMENT DIVISION. 9 j T D N - I E LA&IGN_J0_ ' A : C H A P T R 0 2 S E N I 0 R . D A T ' . S U E TFL j O R G A N I Z A T I O N I S L I N E SEQUENtYaT." 10 1 SELECT PRINT-FILE 11 ASSIGN T O PRINTER. | 12 ! 13 DATA DIVISION. I 14 FILE SECTION. j 15 FD [ S J U D E r n Z I L l } ' ' ' 16 17 18 I RECORD CONTAINS 4 3 CHARACTERS [ DATA RECORD IS STUDENT-IN. 01 STUDENT-IN. 19 05 SRI-NAME" P I C X(?f>). 20 ;05 S T U - C R E D I T S PIC 9(3). 21 105 S T U - M A J O R PIC X(15). 1 22 23 j-"""""" ' FD PRINT-FILE 24 RECORD CONTAINS 132 CHARACTERS 25 D A T A R E C O R D IS P R I N T - L I N E . 26 2 7 28 29 30 01 PRINT-LINE PICX(132). ^ jWORKING-STORAGE ^ . i ^ : ^ , , ^ , , ~ SECTION.| 01 DATA-REMAINS-SWITCH 1 ' i | PIC X(2) VALUE SPACES. [ I
  • 29. Chapter 1— Introduction (continued) 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 01 01 HEADING-LINE. 05 FILLER 05 FILLER 05 FILLER PIC X{10) PIC X(12) PIC X(110) VALUE SPACES. VALUE STUDENT NAME', VALUE SPACES. DETAIL-LINE. 05 FILLER 05 PRINT-NAME 05 FILLER PIC X(8) PIC X(25). PIC X(99) VALUE SPACES. 1 VALUE SPACES. | PROCEDURE D I V I S I O N , f R i PREPARE-SENIOR-RFPORT. ~ OPEN INPUT STUDENT-FILE OUTPUT PRINT-FILE. READ STUDENT-FILE AT END MOVE 'NO' TO DATA-REMAINS-SWITCH END-READ. PERFORM WRITE-HEADING-LINE. [PERFORM proces's-reCorB?! UNTIL DATA-REMAINS-SWITCH = 'NO'. CLOSE STUDENT-FILE PRINT-FILE. STOP RUN. ~ ~ >HedL / WRITE-HEADING-LINE. / MOVE HEADING-LINE TO PRINT-LINE. WRITE PRINT-LINE. / /Numeric lite. PROCESS-RECORDS. IF STU-CREDITS > [110]AND STU-MAJOR "ENGINEERINGT MOVE STU-NAME TO PRINT-NAME MOVE DETAIL-LINE TO PRINT-LINE WRITE PRINT-LINE END-IF. READ STUDENT-FILE AT END MOVE 'NO' TO DATA-REMAINS-SWITCH END-READ. / Nonnumaric liiera! O b s e r v e , for e x a m p l e , t h e d e f i n i t i o n o f a file name, S T U D E N T - F I L E , i n t h e SELECT s t a t e m e n t o f l i n e 8, a n d its s u b s e q u e n t a p p e a r a n c e i n t h e I'D o f l i n e 15, a n d t h e O P E N , READ, a n d CLOSE s t a t e m e n t s o f l i n e s 4 3 , 4 5 , 5 1 , a n d 6 5 . N o t i c e t h e d e f i n i t i o n o f t h e v a r i o u s data names i n l i n e s 1 9 - 2 1 ( a c c o m p l i s h e d t h r o u g h l e v e l n u m b e r s a n d PICTURE c l a u s e s ) a n d t h e s u b s e q u e n t a p p e a r a n c e s i n t h e P r o c e d u r e D i v i s i o n . N o t e t h e c o n s i s t e n c y o f t h e p a r a g r a p h n a m e in t h e PERFORM s t a t e m e n t of l i n e 4 9 a n d t h e p a r a g r a p h h e a d e r i n l i n e 5 9 . O b s e r v e t h a t l i t e r a l s a p p e a r i n t h e IF s t a t e m e n t o f l i n e 6 0 a n d i n t h e AT E N D c l a u s e of t h e READ s t a t e m e n t ( l i n e s 4 6 a n d 66). F i n a l l y , n o t e t h e a b u n d a n t u s e o f C O B O L r e s e r v e d w o r d s ( P R O C E D U R E , DIVISION, WORKING-STORAGE, SECTION, a n d s o o n ) t h r o u g h o u t .
  • 30. A field is a basic fact, such a s the name, address, major, grade point average, or number of completed credits, A record is a set of fields, and a file is a set of records. Every computer application consists of input, processing, and output. The computer cannot think for itself but must be told precisely what to do. This is done through a series of instructions known a s a program. The computer does not do anything that a human being could not do if given sufficient time. The advantages of a computer stem from its speed and accuracy. A flowchart and/or pseudocode represent the logic embodied in a computer program. Every C O B O L program contains four divisions, which appear in the sequence: Identification, Environment, Data, edure. C O B O L contains six language elements; reserved words, programmersupplied names, literals, symbols, level numbers, and pictures. Xey m o r a s a n c Alphabetic data Processing Alphanumeric data Programmer-supplied name Arithmetic symbol Programming specifications End-of-file Pseudocode Field Punctuation symbol File Record Flowchart Record description Initialization Relational symbol Level number Reserved words Nonnumeric literal S c o p e terminator Numeric data Symbol Numeric literal Termination Paragraph Test Data C 0 B G L E l e m e n t s DATA DIVISION ENVIRONMENT DIVISION FILE SECTION IDENTIFICATION DIVISION INPUT-OUTPUT SECTION PICTURE PROCEDURE DIVISION WORKING-STORAGE SECTION
  • 31. CHAPTER 1. All computer applications consist of 1 Introduction , . and 2. The divisions of a COBOL program appear in the order: , 3. A 4. , , and , _. is a pictorial representation of the logic in a program. may be described as neat notes to oneself. 5. A diamond-shaped block in a flowchart indicates a 6. , . have special significance to COBOL and must be used in a rigidly prescribed manner and be spelled correctly. 7. A - may contain the letters A to Z, the digits 0 to 9, and the hyphen. 8. ** is the COBOL symbol for . 9. =, > , and < are examples of 10. A is a set of records. 11. A record consists of one or more 12. A / symbols in COBOL. . is a set of instructions to a computer. R U E / F A L S E 1. Nonnumeric literals may not contain numbers. 2. Numeric literals may not contain letters. 3. A data name may not contain any characters other than letters or numbers. 4. The rules for forming paragraph names and data names are exactly the same. 5. A data name may not consist of more than 30 characters. 6. A nonnumeric literal may not contain more than 30 characters. 7. A numeric literal may contain up to 18 digits. 8. There are four divisions in a COBOL program. 9. The divisions of a COBOL program may appear in any order. 10. Data description appears in the Identification Division. 11. A record contains one or more fields. 12. A file is a set of records. 13. Computers can think for themselves. 14. No statement in a computer program may be executed more than once. 15. A rectangle is the standard flowchart symbol for a decision block. 16. Reserved words may appear in a nonnumeric literal. 17. Reserved words may be used as data names.
  • 32. Problems 18. Pseudocode serves the same function as a flowchart. 19. Pseudocode must be written according to precise syntactical rules. 20. The COBOL compiler needs to be installed every time a program is executed. P R O B L E M S 1. Indicate whether the entries below are valid as data names. If any entry is invalid, state the reason. a. NUMBER-OF-TIMES b. CODE c. 12345 d. ONE TWO THREE e. IDENTIFICATION-DIVISION f. IDENTIFICATION g. HOURS h. GROSS-PAY i. GROSS-PAY-IN-S 2. Classify the entries below as being valid or invalid literals. For each valid entry, indicate whether it is numeric or nonnumeric; for each invalid entry, state why it is invalid. a. 567 b. 567. c. -567 d. +567 e. +567. f. '567.' g. 'FIVE SIX SEVEN' h. '-567' i. 567j. 567+ k. '567+' 3. a. Which division(s) contain paragraph names? b. Which division(s) contain the SELECT statement(s)? c. Which division(s) contain level numbers? d. Which division(s) contain data names? e. Which division(s) contain reserved words? f. Which division(s) contain PICTURE clauses? g. Which division(s) do not contain file names? 4. Given the COBOL program in Figure 1.6, indicate what changes would have to be made if a. We wanted music students rather than engineering students. b. We wanted students with 60 or fewer credits. c. The student major was contained in columns 60-74 of the incoming record. d. We wanted engineering students or students with 110 credits or more. Note: Treat parts (a), (b), (c), and (d) independently.
  • 33. C h a p t e r 1 — Introduction 5. Which division in a COBOL program contains a. The File Section? b. Statements to open and close files? c. The description of incoming data? d. The description of outgoing data? e. The author's name? f. The program's name? g. Statements to read information? h. Statements to write information? 6. Your programming supervisor has drawn a flowchart for you to code. He left the flowchart on his dining room table at home, and unfortunately his three-year-old son, Benjy, cut it up into pieces with a pair of scissors. Your supervisor has collected the pieces (shown in Figure 1.10) and has asked you to rearrange them properly into a correct flowchart; do so. The flowchart is to read a file with each record containing three unequal numbers, A, B, and C. Write out the greater of the two sums (A + B) and (B + C) for each record only if A is less than 50. Develop the equivalent pseudocode. 7. World Wide Sales, Inc., wishes to promote one of its employees to head the South American Division. The selected employee must speak Spanish, be 40 or younger, and hold a college degree. The programming manager has prepared the necessary flowchart (see Figure 1.11), but unfortunately Benjy and his scissors got to it first (see Problem 6). Your job is to put the flowchart together. Note that there may be more than one employee who qualifies for the position. Accordingly, the flowchart includes the necessary logic to count and print the number of qualified employees and to print the name of every such employee. Develop the equivalent pseudocode. 8. Figure 1.12 contains a COBOL program to process a file of employee records and print the names of programmers under 30. Using Figure 1.6 as a guide, restore the missing information so that the program will run as intended. Flowchart Blocks for Problem 6
  • 34. Flowchart Blocks for Problem 7 May be used more than once C O B O L Listing for Problem 8 IDENTIFICATION DIVISION. PROGRAM-ID. FIRSTTRY. GRAUER. ENVIRONMENT DIVISION. INPUT-OUTPUT SECTION. FILE-CONTROL. SELECT EMPLOYEE-FILE ASSIGN TO 'A:CHAPTR02FIRSTTRY.DAT' ORGANIZATION IS LINE SEQUENTIAL. PRINT-FILE ASSIGN TO PRINTER. FILE SECTION. FD EMPLOYEE-FILE RECORD CONTAINS 44 CHARACTERS DATA RECORD IS EMPLOYEE-RECORD. 01 EMPLOYEE-RECORD. 05 EMP-NAME PIC X(25). 05 EMP-TITLE PIC X(10). 05 EMP-AGE PIC 99. 05 FILLER PIC XX. 05 EMP-SALARY PIC 9(5).
  • 35. Chapter i g u r e 1.12 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 COBOL Listing for Problem 8 FD (continued) 4 RECORD CONTAINS 132 CHARACTERS DATA RECORD IS PRINT-LINE. 01 PRINT-LINE. 05 FILLER PIC X. 05 PRINT-NAME 5 05 FILLER PIC X(2). 05 PRINT-AGE PIC 99. 05 FILLER PIC X(3). 05 PRINT-SALARY PIC 9(5). 05 FILLER PIC X(94). 6 01 END-OF-DATA-FLAG PIC X(3) 7 PROCEDURE DIVISION. MAINLINE. 8 INPUT EMPLOYEE-FILE OUTPUT PRINT-FILE. MOVE SPACES TO PRINT-LINE. MOVE 'SALARY REPORT FOR PROGRAMMERS UNDER 30' TO PRINT-LINE. WRITE PRINT-LINE AFTER ADVANCING 2 LINES. READ EMPLOYEE-FILE AT END MOVE 'YES' TO END-OF-DATA-FLAG END-READ. .9 PROCESS-EMPLOYEE-RECORDS UNTIL END-OF-DATA-FLAG = 'YES'. CLOSE EMPLOYEE-FILE PRINT-FILE. STOP RUN. ? 0 PROCESS-EMPLOYEE-RECORDS. ^' IF EMP-TITLE = PROG RAMMER 'JMSTMP-AGE < 30 MOVE SPACES TO PRINTLINE MOVE EMP-NAME ,10'PRINT-NAME MOVE " TO PRINT-AGE MOVE EMP-SALARY TO PRINT-SALARY WRITE PRINT-LINE END-IF. READ EMPLOYEE-FILE ' AT END MOVE "TO END-OF-DATA-FLAG END-READ. 1 ? 1 — Introduction
  • 36. Overview From Coding Form to Computer The C O B O L Coding Form Use of an Editor The Compile, Link, and Execute S e q u e n c e Learning by Doing Errors in Entering the Program Errors in Operating System Commands Errors in Compilation Errors in Execution Errors in Data Input Evolution of C O B O L There's Always a Reason Summary Fill-in True/False Problems
  • 37. C h a p t e r O B J E C T I V E 2 From Coding Form to Computer S After reading this chapter you will be able to: I State the rules associated with the C O B O L coding sheet, and enter a program appropriately. Distinguish between compilation and execution; describe the function of a link program. Describe the environmental differences between a P C and a mainframe a s they relate to execution of C O B O L programs. Compile, link, and execute a C O B O L program. Find and correct simple errors in compilation or execution. O V E R V I E W This chapter continues with the engineering senior program of Chapter 1, describing how to actually run a C O B O L program. We d i s c u s s the C O B O L coding form and its associated rules, the use of an editor (or word processor) to create C O B O L programs and/or data files, and the procedure for submission to the computer. We describe the compile, link, and execute s e q u e n c e . We also prepare you for the errors you will inevitably make, d i s c u s s fundamentals of debugging, and alert you to the subtle differences between the two standards in use today, C O B O L - 7 4 and C O B O L - 8 5 . At the conclusion of the chapter we ask you to run the engineering senior program of Chapter 1. Seeing is believing may be a cliche, but it is only after you have seen output from your own program that the material truly begins to make sense. Suffice it to s a y then, that the sooner you are on the computer, the sooner you will appreciate the subtleties inherent in programming. I* Sf © 6 1 1 C&*disft& P&h'm t& Chapter 1 e n d e d w i t h p r e s e n t a t i o n of a c o m p l e t e d COBOL p r o g r a m , a n d a d i s c u s s i o n <>f t h e e l e m e n t s that m a k e u p t h e COBOL l a n g u a g e . T h e p r o g r a m , h o w e v e r , is n o t y e t i n a f o r m s u i t a b l e for e x e c u t i o n o n t h e c o m p u t e r , a n d m u c h h a s t o b e d o n e i n o r d e r for this t o b e a c c o m p l i s h e d . That is t h e overriding o b j e c t i v e of this c h a p t e r . T h e flowchart i n Figure 2.1 d e p i c t s t h e v a r i o u s s t e p s i n s o l v i n g a p r o b l e m t h r o u g h u s e o f a c o m p u t e r . T h e first s t e p is t o o b t a i n a c l e a r s t a t e m e n t o f t h e problem, containing a c o m p l e t e description of the input a n d desired output. The p r o b l e m s t a t e m e n t s h o u l d a l s o c o n t a i n d e t a i l e d p r o c e s s i n g s p e c i f i c a t i o n s . It is n o t e n o u g h , for e x a m p l e , t o s a y c a l c u l a t e a s t u d e n t ' s grade p o i n t average; i n s t e a d t h e m e t h o d for c a l c u l a t i n g t h e a v e r a g e m u s t b e p r o v i d e d a s well. Once t h e input, output, and processing specifications h a v e b e e n enumerated, a h i e r a r c h y chart ( s e e C h a p t e r 3) is c r e a t e d , t h e n a f l o w c h a r t or p s e u d o c o d e is d e v e l o p e d . Careful a t t e n t i o n t o t h e s e s t e p s will s i m p l i f y t h e s u b s e q u e n t p r o g r a m a n d i n c r e a s e t h e l i k e l i h o o d it will b e correct. C o d i n g is t h e t r a n s l a t i o n of t h e h i e r a r c h y chart, flowchart, a n d / o r p s e u d o c o d e i n t o COBOL. C o d i n g m u s t b e d o n e w i t h i n t h e w e l l - d e f i n e d rules o f COBOL regarding
  • 38. From Coding Form to Co mp uter Figure 2.1 The Programming Process START ENTER TEST DATA OBTAIN PROGRAM SPECS DEVELOP A HIERARCHY CHART DEVELOP A FLOWCHART OR PSEUDOCODE TRUE REVISE COBOL PROGRAM TRUE REVISE COBOL PROGRAM ENTER PROGRAM ON CODING SHEETS ENTER PROGRAM USING TEXT EDITOR FALSE STOP t h e p l a c e m e n t o f v a r i o u s s t a t e m e n t s i n s p e c i f i c a r e a s of t h e c o d i n g form. After c o d i n g , t h e p r o g r a m is e n t e r e d i n t o a file s u i t a b l e for i n p u t t o a c o m p u t e r t h r o u g h u s e o f an editor. T h e p r o g r a m is t h e n s u b m i t t e d to t h e c o m p u t e r i n c o n j u n c t i o n w i t h a s e t o f c o n t r o l s t a t e m e n t s . T h e latter p r o v i d e i n f o r m a t i o n t o t h e o p e r a t i n g s y s t e m as to t h e l o c a t i o n of t h e COBOL p r o g r a m a n d / o r its a s s o c i a t e d data. T h e c o n t r o l s t a t e m e n t s v a r y greatly f r o m i n s t a l l a t i o n t o i n s t a l l a t i o n . N e x t c o m e s c o m p i l a t i o n i n w h i c h t h e COBOL p r o g r a m is t r a n s l a t e d i n t o m a c h i n e l a n g u a g e . Initial a t t e m p t s at c o m p i l a t i o n are apt to identify s e v e r a l errors, d u e to m i s s p e l l i n g s , m i s s i n g p e r i o d s , m i s p l a c e d p a r e n t h e s e s , e t c . C o r r e c t i o n s are m a d e , a n d t h e p r o g r a m is r e c o m p i l e d . O n l y after t h e c o m p i l a t i o n h a s b e e n successfully c o m p l e t e d c a n w e p r o c e e d to execution. D u r i n g e x e c u t i o n t h e c o m p u t e r d o e s e x a c t l y w h a t it w a s i n s t r u c t e d t o d o , w h i c h m a y b e different f r o m w h a t y o u w a n t it to d o . For e x a m p l e , if OR w e r e s u b s t i t u t e d for A N D in l i n e 6 0 of t h e e n g i n e e r i n g s e n i o r p r o g r a m , t h e p r o g r a m w o u l d s e l e c t either e n g i n e e r i n g m a j o r s or s e n i o r s . Either w a y , it w o u l d f u n c t i o n differently f r o m t h e original, logically correct v e r s i o n , a l t h o u g h t h e p r o g r a m w o u l d
  • 39. C h a p t e r 2 — From Coding Form to Computer still c o m p i l e c l e a n l y . C o r r e c t i o n s are m a d e , t h e p r o g r a m is r e c o m p i l e d , a n d t e s t i n g continues. T h e p r e s e n c e o f t h e t w o d e c i s i o n b l o c k s in Figure 2.1 i n d i c a t e s t h e iterative n a t u r e o f t h e e n t i r e p r o c e s s . F e w , if any, p r o g r a m s c o m p i l e c o r r e c t l y o n t h e first t r y — h e n c e t h e n e e d t o r e c o d e s p e c i f i c s t a t e m e n t s . Similarly, p r o g r a m s m a y n o t e x e c u t e p r o p e r l y o n t h e first a t t e m p t , a n d t h u s t h e n e e d t o r e v i s e t h e p r o g r a m , recompile, reexecute, and so on. T h e COBOL c o m p i l e r is very particular a b o u t t h e i n f o r m a t i o n it r e c e i v e s , a n d requires a p r o g r a m to b e w r i t t e n w i t h i n its w e l l - d e f i n e d syntax. For e x a m p l e , d i v i s i o n a n d s e c t i o n h e a d e r s are r e q u i r e d to b e g i n b e t w e e n c o l u m n s 8 a n d 11, w h e r e a s m o s t o t h e r s t a t e m e n t s b e g i n i n o r p a s t c o l u m n 12. T h e r e are a d d i t i o n a l r u l e s for c o n t i n u a t i o n ( w h a t h a p p e n s if a s t a t e m e n t d o e s n o t fit o n o n e line), c o m m e n t s , o p t i o n a l s e q u e n c i n g o f s o u r c e s t a t e m e n t s in c o l u m n s 1-6, a n d p r o g r a m identification in columns 73-80. T h e rules o f t h e c o d i n g s h e e t are s u m m a r i z e d i n T a b l e 2 . 1 , a n d illustrated i n Figure 2.2. T h e latter s h o w s c o m p l e t e d f o r m s for t h e e n g i n e e r i n g s e n i o r p r o b l e m of C h a p t e r I. Several f e a t u r e s i n F i g u r e 2.2 b e a r m e n t i o n . N o t e i n particular t h e w a v y l i n e u n d e r v a r i o u s PIC e n t r i e s t o i n d i c a t e t h a t i d e n t i c a l i n f o r m a t i o n is to b e e n t e r e d o n s u b s e q u e n t l i n e s . Of g r e a t e s t i m p o r t , h o w e v e r , is t h e c o n f o r m i t y b e t w e e n t h e e n t r i e s i n Figure 2.2 a n d t h e COBOL r e q u i r e m e n t s of T a b l e 2 . 1 . C o d i n g s h e e t s are n o t m a n d a t o r y a n d y o u c a n u s e o r d i n a r y p a p e r i n s t e a d . You will find, h o w e v e r , t h a t p r o g r a m m i n g is m u c h easier, if y o u are w e l l o r g a n i z e d . A g o o d start is t o h a v e t h e p r o g r a m n e a t l y e n t e r e d in a p p r o p r i a t e c o l u m n s b e f o r e s i t t i n g d o w n at t h e c o m p u t e r . O n c e a p r o g r a m h a s b e e n w r i t t e n o n c o d i n g s h e e t s , it is e n t e r e d t h r o u g h a n e d i t o r (or w o r d p r o c e s s o r ) i n t o a file for s u b s e q u e n t i n p u t t o t h e c o m p u t e r . In all l i k e l i h o o d y o u are a l r e a d y familiar w i t h a w o r d p r o c e s s o r , a n d c a n u s e t h a t t o c r e a t e a n d e d i t COBOL p r o g r a m s a s w e l l . A c c o r d i n g l y , b e s u r e y o u c a n d o all o f t h e f o l l o w i n g : 1. S a v e t h e p r o g r a m as a n u n f o r m a t t e d (ASCII text) file, w i t h a file n a m e o f y o u r o w n c h o o s i n g , c o n s i s t e n t w i t h t h e c o m p u t e r o n w h i c h y o u will e x e c u t e t h e program. 2 . Retrieve t h e file, t h e n r e s a v e it after m a k i n g a d d i t i o n a l m o d i f i c a t i o n s . 3. T o g g l e b e t w e e n t h e i n s e r t i o n a n d r e p l a c e m e n t m o d e s t o c h a n g e c h a r a c t e r s w i t h i n a s t a t e m e n t , a n d / o r t o insert a n d / o r d e l e t e s t a t e m e n t s w i t h i n a program. 4. Print a l i s t i n g of t h e file. Y o u will a l s o find it u s e f u l to l e a r n t h e c o m m a n d s to: 1. Set t a b s t o m o v e to d e s i g n a t e d c o l u m n s ; for e x a m p l e , c o l u m n s 8 a n d 12 for the A and B margins, respectively. 2. S e a r c h a n d / o r r e p l a c e c h a r a c t e r strings. 3. M o v e t o s p e c i f i e d p l a c e s w i t h i n t h e p r o g r a m ; for e x a m p l e , t h e b e g i n n i n g or e n d , a p a r t i c u l a r l i n e , t h e start o f t h e P r o c e d u r e D i v i s i o n , a n d s o o n . T h e availability o f a n o n - l i n e e d i t o r facilitates p r o g r a m m i n g to a n e x t e n t t h a t w a s u n i m a g i n a b l e to t e n s o f t h o u s a n d s o f COBOL p r o g r a m m e r s of t h e 1 9 6 0 s a n d
  • 40. From Coding Form to Computer Rules for the COBOL Coding Form 1-6 Optional sequence numbers, If this field is coded, the compiler performs a sequence check on incoming C O B O L statements by flagging any statements out of order. Although some commercial installations encourage this option, we advise against it, especially since you are entering your own programs, and the more you type, the more chance for error. 7 An asterisk in column 7 indicates a comment, while a hyphen is used for the continuation of nonnumeric literals (described further on page 180). Comments may appear anywhere in a program; they are shown on the source listing but are otherwise ignored. 8-11 Known as the A margin, Division headers, section headers, paragraph names, FD's, and 01 's all begin in the A margin. 12-72 Known as the B margin, All remaining entries begin in or past column 12. C O B O L permits considerable flexibility here, but individual installations have their own requirements. W e , for example, begin PICTURE clauses in the same column, for example, column 37, for better readability. (We shall discuss this further in Chapter 7.) 73-80 Program identification, a second optional field, which is ignored by the compiler. Different installations have different standards regarding use of this field. Fhe C O B O L Coding Form SENIOR .. R O B E R T 6RAUER • .. 9/10/93 I D E N T I F l C A T I ON D I V I 51 ON ; I PROGRAM-ID SENIOR AUTHOR. . ROBERT GRAUER • R : : I I : I I : I . ! ! I 1 { f , 1 ENVIRONMENT D I V I S I O N •: I •< I , I I I I : : I ' M I N P U T - O U T P U T SECTION". ; I I ! ! • I • : I I • I : ; I : ! II FI LE-CONTROL SELECT STUDENT-FILE A S S I G N TO ' A CHAPTRO2SEN ICRDAT' ORGANIZATION I S LINE SEQUENTIAL S E L E C T P R I NTL- P I L|E " " | , ! | | , J I A S S I G N T O PRJMTEFT.. 1 DATA D I V I S I O N Fl L E S E C T I O N FD STUDENT-FILE RECORD C O N T A I N S 4 3 CHARACTERS DATA- R E C O R D I S S T U D E N T - I N . 01 $tu>zhx-h 05 S T U - NAME P I C XU5) 05 STU-CREDITS P I C 9(3) 05 STU-MAOOR P I C X ( t 5) ! i i I I j FD PRINT-FILE RECORD CONTAINS 1 n CHARACTERS DATA R E C O R D I S P R I N T - L I N E I 1 I Ci PRINT I I ! LINE P I C X ( i 32-) I j , [ 1 ; 1 ! I
  • 41. 2 Chapter From Coding Form to Computer (continued) Pgm S E N I O R rr oa Pgm e R O B E R T <3RAUER r r mr oa Rq ee b e usd y t Pg ae 2 o 5 l a o 7 3 9/10/93 Dt a e I e tia n dn ct i i f o Sq e c j | j e une : q A CBL S tmn O O te e t a t 3 A 6 j 8 NS-SfOR;A<JE | 7 WORkil i0! J 01 P : 5 t 0 6 I i io f 1 | 1 SECTION" DATA.-REMA I N S , - S W I T C H i|i I 'I 1 HEAD|l N G - ' L I NEj 05 'FILLER 1 1 ! , P I C i M ' 6 B 1 M X(2') I l l l VALINE SPACES ! deta'i l - l ' i n e 05 F!l LLEIR X P;Ri NT - N A M E A F i L L E,R ( 1 ( xcio) 1 X(1,Z) , A ;x, V 1 ' ' P i c j X( I'O) i. I i r [ VALUE SPjACES' V SfTUDEjNT NAME' A SPACfeSf K ' i 1 i , P I C X(fl) , Y, XU5) , A . 7 2 j i X £ 9 9) |VALtjE SPACES iVAlUE SP ACES, ( 'procedure DIVISION ' PREPARE-.SENIOR-R'EPORT_ , OPtN i N P U T STUDE.Nl - F! LE ; ' O U T P U T PIRINT-Fi L E ! R E A D S T U D E N T - F I L'E A T E'ND WOVE ' NO T O IdATA - R E M A i NS - Stw i TcH end - Read perform wrlte-he,ad i n s - l i n e PERFORM PROCESS RECORDS 1 HO' UNT L DA T A - R E M A I N S - S W I T C H = C L O S E STUDENT-FI L E P R l M T - F I LE S T O P RUN fj"" It early 1 9 7 0 s . C O B O L itself is o v e r 3 0 y e a r s o l d , a n d for m u c h o f its e x i s t e n c e t h e p u n c h e d card a n d batch p r o c e s s i n g (often with turnaround t i m e s of several hours or m o r e ) w a s t h e w a y i n w h i c h p r o g r a m s w e r e s u b m i t t e d . S t u d e n t s t o d a y a r e far m o r e f o r t u n a t e i n t h e a v a i l a b l e t e c h n o l o g y , t a k i n g for g r a n t e d t h e ability t o e x e c u t e a p r o g r a m m a n y t i m e s i n a s i n g l e s e s s i o n , i n s t e a d o f h a v i n g t o w a i t h o u r s (or d a y s ) to retrieve a s i n g l e r u n , w a i t h o u r s m o r e for t h e n e x t r u n , e t c . T h e m a t e r i a l o n t h e c o d i n g s h e e t a n d u s e o f a n e d i t o r is s t r a i g h t f o r w a r d , a n d s h o u l d p o s e little difficulty. T h e e x e c u t i o n o f a C O B O L p r o g r a m , h o w e v e r , is m o r e c o m p l e x , a n d i s e x p l a i n e d i n c o n j u n c t i o n w i t h F i g u r e 2 . 3 . T h e figure s h o w s t h e e x e c u t i o n o f t h r e e d i s t i n c t p r o g r a m s , a compiler, and load module, linker (or l i n k a g e - e d i t o r o n IBM m a i n f r a m e s ) , e a c h o f w h i c h is n e c e s s a r y t o p r o d u c e t h e list o f e n g i n e e r i n g s e n i o r s . R e a l i z e , t o o , t h a t t h e p r o c e s s d e s c r i b e d i n F i g u r e 2.3 i s r e q u i r e d for a n y COBOL p r o g r a m , e v e n o n e a s s i m p l e a s t h e e n g i n e e r i n g s e n i o r e x a m p l e .
  • 42. From Coding Form to Computer (continued) P gm r r oa SENIOR ROBERT ^RACIER Rq ee b e usd y t P gm e r r m oa , Sq e c |nj e une A Pg ae 3 9l 0/92> Dt a e i R o 3 f 7 3 8 0 I e tia n dn ct i i f o CBL S tmn O O te e t a WRi TE - tttAD i m - 1 I NE MOVE, HEAD I N S - L I N E TO P R I N T - L I N E WRITE P R I N T - L I N E PROCESS .RECORDS I F STU-CREDITS > I t 0 AND STU-MAJOR = ' ENGINEERING' MOVE STU-NAME TO PR I NT-NAME WOVE D E T A I L - L I N E TO P R I N T - L I N E WRITE P R I N T - L I N E END-;IF^_ READj STUDENT-F I LE END-READ ' i T h e p r o c e d u r e b e g i n s w i t h t h e COBOL compiler, a program that accepts a COBOL (source) p r o g r a m as i n p u t , a n d p r o d u c e s a m a c h i n e - l a n g u a g e (object) p r o g r a m as o u t p u t . T h e result o f t h e c o m p i l a t i o n , t h e o b j e c t p r o g r a m , i s i n p u t i n t o a s e c o n d p r o g r a m c a l l e d t h e linker, that c o m b i n e s t h e o b j e c t p r o g r a m w i t h s u b r o u t i n e s a n d o t h e r o b j e c t m o d u l e s to p r o d u c e a l o a d m o d u l e . E x e c u t i o n o f t h e c o m p i l e d COBOL p r o g r a m t a k e s p l a c e in the third s t e p as the load module a c c e p t s i n p u t d a t a a n d p r o d u c e s a n o u t p u t report. T h e e x e c u t i o n o f t h e v a r i o u s p r o g r a m s i n Figure 2.3 d o e s n o t h a p p e n t h r o u g h w i s h f u l t h i n k i n g , b u t t h r o u g h s p e c i f i c a t i o n o f c o m m a n d s to t h e operating system t o d e s c r i b e t h e s e p r o g r a m s a n d t h e i r a s s o c i a t e d d a t a files. Every o p e r a t i n g s y s t e m h a s its o w n s p e c i f i c c o m m a n d s , b u t t h e u n d e r l y i n g c o n c e p t is t h e s a m e , n a m e l y t h a t t h r e e different p r o g r a m s (a c o m p i l e r , linker, a n d l o a d m o d u l e ) are r e q u i r e d . It will b e n e c e s s a r y , t h e r e f o r e , t o l e a r n t h e c o m m a n d s for y o u r particular c o n f i g u r a t i o n i n o r d e r to c o m p i l e , link, a n d e x e c u t e a COBOL p r o g r a m . ' 1 A p n i e A . p e dc s t x. e t a dB n d s rb e c i e t e Mc o F c s P r o a C B L f r Wn o s t a may h i r o u es n l O O o i d w h t a c m a y t i c o p n hs
  • 43. C h a p t e r inn 2 - } torn Coding Form to Computer Compile, Link, and Execute S e q u e n c e O n e l e a r n s b y d o i n g . T h i s t i m e - w o r n a x i o m i s e s p e c i a l l y true for p r o g r a m m i n g . W e h a v e c o v e r e d a lot of m a t e r i a l s i n c e y o u first b e g a n r e a d i n g C h a p t e r 1. N o w it is t i m e to p u t e v e r y t h i n g t o g e t h e r a n d actually r u n y o u r first p r o g r a m . Enter t h e p r o g r a m o n t h e c o d i n g s h e e t s in Figure 2.2, u s i n g t h e a p p r o p r i a t e editor. Prepare t h e n e c e s s a r y c o n t r o l s t a t e m e n t s for t h e o p e r a t i n g s y s t e m . Create y o u r o w n test data, or u s e Figure 1.8a. S u b m i t t h e j o b a n d retrieve y o u r o u t p u t . W e b e l i e v e — i n fact w e are very s u r e — t h a t after y o u r e c e i v e y o u r first c o m p u t e r p r i n t o u t , m a n y t h i n g s will fall i n t o p l a c e . N e v e r t h e l e s s , t h e first p r o g r a m is i n m a n y w a y s t h e m o s t difficult y o u will a t t e m p t , a n d y o u s h o u l d b e p r e p a r e d for p r o b l e m s a l o n g t h e w a y . T h e difficulty is n o t in t h e p r o g r a m ' s c o m p l e x i t y (the e n g i n e e r i n g s e n i o r p r o g r a m is logically trivial). N o r is it in t h e COBOL syntax, i n that t h e p r o g r a m u s e s o n l y a fraction of t h e COBOL features y o u will e v e n t u a l l y e m p l o y . T h e p r o b l e m s arise in i n t e r a c t i n g w i t h t h e c o m p u t e r , u s i n g t h e e d i t o r , e n t e r i n g t h e p r o p e r c o m m a n d s to the operating system, and so o n . Murphy's Law is perhaps the m o s t e l o q u e n t s t a t e m e n t of w h a t to e x p e c t , a n d t h u s y o u s h o u l d b e p r e p a r e d for a n y or all of t h e e n s u i n g errors.
  • 44. Learning by Doing T h e errors that o c c u r as y o u e n t e r t h e p r o g r a m are p o t e n t i a l l y t h e m o s t d a m a g i n g , e s p e c i a l l y if y o u s p e n d h o u r s e n t e r i n g t h e p r o g r a m a n d t h e n forget t o s a v e it, s a v e it incorrectly, or d e l e t e it u n i n t e n t i o n a l l y . A s u g g e s t e d c o u r s e o f a c t i o n for y o u r first a t t e m p t is t o e n t e r o n l y t h e first t w o l i n e s o f t h e p r o g r a m , save t h e s e , l o g off t h e s y s t e m , t h e n l o g o n a n d retrieve t h e file. I n this w a y y o u are sure y o u k n o w h o w t o use the editor. O t h e r f r e q u e n t errors are to e n t e r i n f o r m a t i o n in t h e w r o n g c o l u m n s , to m i s u s e a t a b key, a n d s o o n . T h e s y n t a x o f o p e r a t i n g s y s t e m c o m m a n d s h a s to b e f o l l o w e d exactly, i n o r d e r for t h e s y s t e m to d o y o u r b i d d i n g . S i m p l e m i s t a k e s result i n baffling errors; for e x a m p l e , Bad command or file name, w h e n y o u m i s s p e l l a n M S - D O S c o m m a n d , a n d / o r fail to i n d i c a t e t h e p r o p e r s u b d i r e c t o r y w h e r e t h e c o m m a n d is l o c a t e d . In similar f a s h i o n t h e c o n t r o l s t a t e m e n t s s u b m i t t e d o n a m a i n f r a m e m u s t b e s y n t a c t i c a l l y correct, or e v e r y t h i n g e l s e will fail. Invalid j o b s t r e a m s result in t h e s y s t e m b e i n g u n a b l e t o execute the job, leaving you w i t h the m o s t frustrating of all messages, Job not run due to JCL error. A compilation error o c c u r s w h e n e v e r y o u v i o l a t e a rule o f COBOL, for e x a m p l e , m i s s p e l l i n g a r e s e r v e d w o r d or m i s p l a c i n g a p e r i o d . T h e result of t h e error is that t h e c o m p i l e r is u n a b l e to translate a p o r t i o n of t h e COBOL p r o g r a m to m a c h i n e l a n g u a g e , a n d a n y s u b s e q u e n t a t t e m p t at e x e c u t i o n will ( m o s t likely) b e incorrect. C o n s i d e r , for e x a m p l e , Figure 2.4a, w h i c h c o n t a i n s a slightly m o d i f i e d v e r s i o n of t h e E n g i n e e r i n g S e n i o r P r o g r a m o f Figure 1.6, i n w h i c h l i n e s 5 9 - 6 4 h a v e b e e n Engineering Senior Program with Compilation Errors 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 IDENTIFICATION DIVISION. PROGRAM-ID. SENIORCE. AUTHOR. ROBERT GRAUER. ENVIRONMENT DIVISION. INPUT-OUTPUT SECTION. FILE-CONTROL. SELECT STUDENT-FILE ASSIGN TO 'A:CHAPTER02SENI0R.DAT' ORGANIZATION IS LINE SEQUENTIAL. SELECT PRINT-FILE ASSIGN TO PRINTER. DATA DIVISION. FILE SECTION. FD STUDENT-FILE RECORD CONTAINS 43 CHARACTERS DATA RECORD IS STUDENT-IN. 01 STUDENT-IN. 05 STU-NAME PIC X(25).
  • 45. C h a p t e r Fit 2 From Coding Form (continued) 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 5 JL [59 60 61 62 63 64 65 66 67 05 05 FD 01 STU-CREDITS STU-MAJOR PRINT-FILE RECORD CONTAINS 132 CHARACTERS DATA RECORD IS PRINT-LINE. PRINT-LINE PIC X(132). WORKING-STORAGE SECTION. 01 DATA-REMAINS-SWITCH 01 01 PIC 9(3). PIC X(15). PIC X(2) VALUE SPACES. HEADING-LINE. 05 FILLER 05 FILLER 05 FILLER P I C X(10) PIC X(12) PIC X(110) VALUE SPACES. VALUE 'STUDENT NAME' VALUE SPACES. DETAIL-LINE. 05 FILLER 05 PRINT-NAME 05 FILLER PIC X(8) P I C X(25). P I C X(99) VALUE SPACES. VALUE SPACES. PROCEDURE DIVISION. PREPARE-SENIOR-REPORT. OPEN INPUT STUDENT-FILE OUTPUT PRINT-FILE. READ STUDENT-FILE AT END MOVE 'NO' TO DATA-REMAINS-SWITCH END-READ. PERFORM WRITE-HEADING-LINE. PERFORM PROCESS-RECORDS UNTIL DATA-REMAINS-SWITCH = 'NO'. CLOSE STUDENT-FILE PRINT-FILE. STOP RUN. WRITE-HEADING-LINE. MOVE HEADING-LINE TO PRINT-LINE. WRITE PRINT-LINE. Period missing after paragraph header PROCESS-RECORDSr IF STU-CREDITS > 110 AND STU-MAJOR = 'ENGINEERING' MOVE STU-NAME TO PRINT-NAME MOVE DETAIL-LINE TO PRINT-LINE WRTE PRINT-LINE. WRITE is misspelled END-IF. Period does no! belong before END-IF terminator READ STUDENT-FILE AT END MOVE 'NO' TO DATA-REMAINS-SWITCH END-READ. (a) C O B O L Listing to Computer
  • 46. Learning by Doing (continued) Flgar LINE ERR# LVL • ERROR TEXT 0138 W Period assumed before 'IF' 0787 E Undefined symbol 'WRTE' 0593 E No corresponding active scope for 'END-IF' seniorce has 1 Warning + 2 E Level messages c h a n g e d t o p r o d u c e c o m p i l a t i o n errors. Figure 2 . 4 b s h o w s t h e r e s u l t i n g c o m p i l e r d i a g n o s t i c s . T h e error m e s s a g e a s s o c i a t e d w i t h l i n e 6 0 is c a u s e d b y t h e m i s s i n g p e r i o d (after t h e p a r a g r a p h h e a d e r ) in l i n e 5 9 . T h e d i a g n o s t i c i n l i n e 6 3 r e s u l t e d f r o m m i s s p e l l i n g a r e s e r v e d w o r d , a n d t h e d i a g n o s t i c in l i n e 6 4 is p r o d u c e d b y t h e s u p e r f l u o u s p e r i o d in l i n e 6 3 . C o m p i l e r d i a g n o s t i c s are d i s c u s s e d fully in C h a p t e r 6. C o r r e c t i o n s are m a d e , a n d t h e p r o g r a m is r e c o m p i l e d . O n l y after t h e c o m p i l a t i o n h a s b e e n s u c c e s s f u l l y c o m p l e t e d s h o u l d w e proceed to execution. E x e c u t i o n errors o c c u r after c o m p i l a t i o n a n d are g e n e r a l l y d u e t o errors in logic. Figure 2 . 5 a c o n t a i n s y e t a n o t h e r v e r s i o n o f t h e e n g i n e e r i n g s e n i o r p r o g r a m i n w h i c h t h e credits test w a s deliberately o m i t t e d in l i n e 60. T h e p r o g r a m is syntactically c o r r e c t a n d will c o m p i l e w i t h o u t error; it is, h o w e v e r , logically i n c o r r e c t a n d h e n c e t h e a s s o c i a t e d o u t p u t i n Figure 2 . 5 b is w r o n g . ( R e v i e w t h e o r i g i n a l p r o g r a m s p e c i f i c a t i o n s a n d t e s t data; Alex Bell s h o u l d n o t b e s e l e c t e d b e c a u s e o f a n insufficient n u m b e r o f credits.) .5 1 2 3 4 5 6 7 8 9 10 11 12 13 Engineering Senior Program with Execution Errors IDENTIFICATION DIVISION. PROGRAM-ID. SENI0REE. AUTHOR. ROBERT GRAUER. ENVIRONMENT DIVISION. INPUT-OUTPUT SECTION. FILE-CONTROL. SELECT STUDENT-FILE ASSIGN TO 'A:CHAPTR02SENIOR.DAT' ORGANIZATION IS LINE SEQUENTIAL. SELECT PRINT-FILE ASSIGN TO PRINTER. DATA DIVISION.
  • 47. C h a p t e r Fg r i u e 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 2 From (continued) FILE SECTION. FD STUDENT-FILE RECORD CONTAINS 43 CHARACTERS DATA RECORD IS STUDENT-IN. 01 STUDENT-IN. PIC X(25). 05 STU-NAME PIC 9(3). 05 STU-CREDITS PIC X(15). 05 STU-MAJOR FD 01 PRINT-FILE RECORD CONTAINS 132 CHARACTERS DATA RECORD IS PRINT-LINE. PRINT-LINE PIC X(132), WORKING-STORAGE SECTION. 01 DATA-REMAINS-SWITCH 01 01 PIC X(2) VALUE SPACES. HEADING-LINE. 05 FILLER 05 FILLER 05 FILLER PIC X(10) PIC X(12) PIC X(110) VALUE SPACES. VALUE 'STUDENT NAME' VALUE SPACES. DETAIL-LINE. 05 FILLER 05 PRINT-NAME 05 FILLER PIC X(8) PIC X(25). PIC X(99) VALUE SPACES. VALUE SPACES. PROCEDURE DIVISION. PREPARE-SENIOR-REPORT. OPEN INPUT STUDENT-FILE OUTPUT PRINT-FILE. READ STUDENT-FILE AT END MOVE 'NO' TO DATA-REMAINS-SWITCH END-READ. PERFORM WRITE-HEADING-L1NE. PERFORM PROCESS-RECORDS UNTIL DATA-REMAINS-SWITCH = 'NO'. CLOSE STUDENT-FILE PRINT-FILE. STOP RUN. WRITE-HEADING-LINE. MOVE HEADING-LINE TO PRINT-LINE. WRITE PRINT-LINE. PROCESS-RECORDS. [IF STU-MAJOR = 'ENGINEERING' h MOVE STU-NAME TO PRINT-NAME MOVE DETAIL-LINE TO PRINT-LINE WRITE PRINT-LINE Coding Form to Compute
  • 48. Learning 64 65 66 67 by Doing END-IF. READ STUDENT-FILE AT END MOVE 'NO' TO DATA-REMAINS-SWITCH END-READ. STUDENT NAME ORVILLE WRIGHT ALEX BELL}-JOHN ROEBLING It is i m p o r t a n t to r e m e m b e r , therefore, that a computer does exactly what it is instructed to do, which may be different from what you want it to do. In o t h e r w o r d s if y o u (incorrectly) tell the c o m p u t e r to i g n o r e t h e c r e d i t s test, t h e n that is p r e c i s e l y w h a t t h e p r o g r a m will d o . A p r o g r a m m a y a l s o p r o d u c e e r r o n e o u s o u t p u t , e v e n if it is logically correct, w h e n t h e d a t a o n w h i c h t h e p r o g r a m o p e r a t e s are invalid. If, for e x a m p l e , t h e erroneous d a t a i n Figure 2 . 6 are s u b m i t t e d t o t h e valid p r o g r a m i n Figure 2.2, n e i t h e r Orville Wright n o r J o h n R o e b l i n g will b e s e l e c t e d ! Wright's m a j o r a p p e a r s i n t h e d a t a a s ENGINEER, w h e r e a s line 6 0 in t h e p r o g r a m is l o o k i n g for ENGINEERING. R o e b l i n g ' s c r e d i t s a r e e n t e r e d in t h e w r o n g c o l u m n . I n o t h e r w o r d s , a c o m p u t e r o p e r a t e s o n d a t a e x a c t l y a s it is s u b m i t t e d , w i t h n o regard for i t s c o r r e c t n e s s . Stated a n o t h e r w a y , t h e o u t p u t p r o d u c e d b y a p r o g r a m is o n l y as g o o d a s its i n p u t , or p u t e v e n m o r e s i m p l y , garbage in, garbage out, g i v i n g rise t o t h e w e l l k n o w n a c r o n y m , GIGO. Erroneous Input Data JOHN ADAMS AMELIA EARHART ORVILLE WRIGHT GEORGIA 0'KEEFFE MERIWETHER LEWIS JOHN KENNEDY ALEX BELL EMILY DICKINSON JOHN ROEBLING 090P0LITICAL SCI 120AVIATI0N 115gNGINEERj 125ART 115TRAVEL 115P0LITICAL SCI 090ENGINEERING 085LITERATURE 115ENGINEERING
  • 49. Chapter 2 From Coding Form to Computer COBOL w a s i n t r o d u c e d i n 1959 t h r o u g h t h e efforts of C a p t a i n Grace Murray H o p p e r of t h e U n i t e d States N a v y . It w a s d e s i g n e d t o b e a n o p e n e n d e d l a n g u a g e , c a p a b l e o f a c c e p t i n g c h a n g e a n d a m e n d m e n t . It w a s a l s o i n t e n d e d t o b e a h i g h l y p o r t a b l e l a n g u a g e ; i.e., a COBOL p r o g r a m w r i t t e n for a n IBM m a i n f r a m e c o m p u t e r s h o u l d run e q u a l l y w e l l o n a n y o t h e r c o m p u t e r w i t h a COBOL c o m p i l e r . Over t h e y e a r s t h e n e e d s o f a n e v o l v i n g l a n g u a g e , a n d t h e d e s i r e for c o m p a t i b i l i t y a m o n g v e n d o r s h a v e g i v e n rise t o several COBOL s t a n d a r d s , t w o of w h i c h are i n c o m m o n u s e t o d a y , COBOL-74 a n d COBOL-85. All of t h e listings in this text are w r i t t e n t o take a d v a n t a g e o f f e a t u r e s in t h e n e w e s t s t a n d a r d , COBOL-85. W e t h i n k it i m p o r t a n t t o e m p h a s i z e COBOL-85 ( d e e m p h a s i z e COBOL-74) b e c a u s e COBOL-85 h a s b e e n t h e current s t a n d a r d for several years. Industry, h o w e v e r , is s l o w t o c h a n g e , a n d e v e n a s this b o o k is w r i t t e n i n 1993, m a n y ( p e r h a p s m o s t ) o f i n d u s t r y ' s c u r r e n t l y r u n n i n g COBOL p r o g r a m s a d h e r e to COBOL-74. T h e r e a s o n for t h e s l o w c o n v e r s i o n is t h e s u b t l e incompatibilities that exist b e t w e e n t h e t w o c o m p i l e r s . In t h e o r y , a p r o g r a m w r i t t e n u n d e r t h e earlier c o m p i l e r is s u p p o s e d t o r u n w i t h o u t m o d i f i c a t i o n u n d e r t h e later c o m p i l e r . In p r a c t i c e , h o w e v e r , this is n o t a l w a y s t h e c a s e . C o n s i d e r , for e x a m p l e , t h e i n c o m p a t i b i l i t y b r o u g h t a b o u t b y t h e i n t r o d u c t i o n of n e w features a n d a s s o c i a t e d n e w r e s e r v e d w o r d s , w o r d s s u c h as C O N T E N T , EVALUATE, FALSE, OTHER, TEST, a n d s o o n . A p r o g r a m m e r w r i t i n g u n d e r COBOL74 c o u l d logically h a v e u s e d a n y or all of t h e s e w o r d s as data n a m e s , w h i c h p o s e d n o problem under the older compiler, but which produces n u m e r o u s compilation errors u n d e r COBOL-85. T h u s , a b l a n k e t c o n v e r s i o n b y a n installation of its h u n d r e d s ( t h o u s a n d s , or t e n s of t h o u s a n d s ) o f COBOL p r o g r a m s , w o u l d p r o v e d i s a s t r o u s , u n l e s s e a c h p r o g r a m w a s m a n u a l l y c h e c k e d for c o m p a t i b i l i t y w i t h t h e n e w s t a n d a r d . Many installations support b o t h compilers, using COBOL-74 to maintain e x i s t i n g p r o g r a m s a n d COBOL-85 for n e w d e v e l o p m e n t . It is i m p o r t a n t , therefore, t h a t y o u b e c o m e a w a r e of t h e d i f f e r e n c e s b e t w e e n t h e t w o s t a n d a r d s . A c c o r d i n g l y , w e e n d most chapters with a section describing differences b e t w e e n the standards as t h e y relate t o t h e p r o g r a m d i s c u s s e d in that c h a p t e r . Figure 2.7 r e p r e s e n t s o u r final l o o k at t h e e n g i n e e r i n g s e n i o r p r o g r a m a s it w o u l d b e i m p l e m e n t e d i n C O B O L - 7 4 . N o t e t h e f o l l o w i n g d i f f e r e n c e s b e t w e e n this p r o g r a m a n d t h e C O B O L - 8 5 i m p l e m e n t a t i o n o f Figure 1.6: Engineering Senior Program ( C O B O L - 7 4 Implementation) IDENTIFICATION DIVISION. PROGRAM-ID. SENI0R74. AUTHOR. ROBERT GRAUER. ENVIRONMENT DIVISION. CON FIGURATION"SECTION'.'| SOURCE-COMPUTER. IBM-PC.' OBJECT-COMPUTER. IBM-PC. INPUT-OUTPUT SECTION. FILE-CONTROL. jlELECT'stUDlNl-FILEASSIGN f0 Ut-S-SYSIN. SELECT PRINT-FILE L ASSIGN TO UJ-S-SYSOUT. DATA DIVISION.
  • 50. Evolution of COBOL (continued) 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 FILE SECTION. FD STUDENT-FILE LABEL RECORDS ARE STANDARD RECORD CONTAINS 43 CHARACTERS DATA RECORD IS STUDENT-IN. 01 STUDENT-IN. 05 STU-NAME PIC X(25). 05 STU-CREDITS PIC 9(3). 05 STU-MAJOR PIC X(15) V FD 1 01 PRINT-FILE LABEL RECORDS ARE STANDARD -" RECORD CONTAINS 132 CHARACTERS DATA RECORD IS PRINT-LINE. PRINT-LINE PIC X(132). WORKING-STORAGE SECTION. 01 DATA-REMAINS-SWITCH 01 01 PIC X(2) VALUE SPACES. HEADING-LINE. 05 FILLER 05 FILLER 05 FILLER PIC X(10) PIC X(12) PIC X(110) VALUE SPACES. VALUE STUDENT NAME VALUE SPACES. DETAIL-LINE. 05 FILLER 05 PRINT-NAME 05 FILLER PIC X(8) PIC X(25). PIC X(99) VALUE SPACES. 1 VALUE SPACES. PROCEDURE DIVISION. PREPARE-SENIOR-REPORT. OPEN INPUT STUDENT-FILE OUTPUT PRINT-FILE. READ STUDENT-FILE AT END MOVE 'NO' TO DATA-REMAINS-SWITCH. PERFORM WRITE-HEADING-LINE. PERFORM PROCESS-RECORDS UNTIL DATA-REMAINS-SWITCH = 'NO'. CLOSE STUDENT-FILE PRINT-FILE. STOP RUN. WRITE-HEADING-LINE. MOVE HEADING-LINE TO PRINT-LINE. WRITE PRINT-LINE. PROCESS-RECORDS. _ _ IFITU-CREDITS > lib AND~STU-MAJOR = 'ENGINEERING MOVE STU-NAME TO PRINT-NAME MOVE DETAIL-LINE TO PRINT-LINE WRITE PRINT-LINE. READ STUDENT-FILE AT END MOVE 'NO' TO DATA-REMAINS-SWITCH. 1 1
  • 51. C h a p t e r 1. C O HO 1.-74 requires 2 From Coding a CONFIGURATION Form SECTION a uu E VUvr i A a ua u i ^ j i i uE n nU D j E ^ i - ^ u i n r u i c n to with Computer both a p i ga n LU m t a aa i p , u u i e t h e c o m p u t e r o n w h i c h the p r o g r a m will c o m p i l e a n d e x e c u t e . T h e C O N F I G U R A T I O N SECTION is o p t i o n a l i n COBOL-85, a n d s i n c e t h e s e e n t r i e s are t r e a t e d as c o m m e n t s b y t h e c o m p i l e r , t h e y are o m i t t e d i n t h e C O B O L - 8 5 listing. 2. COBOL-74 requires t h e LABEL RECORDS c l a u s e in a file d e s c r i p t i o n to i n d i c a t e w h e t h e r s t a n d a r d , n o n s t a n d a r d , or n o l a b e l s are i n effect. (A label c o n t a i n s i n f o r m a t i o n a b o u t a file s u c h a s t h e d a t e it w a s c r e a t e d a n d t h e i n t e n d e d e x p i r a t i o n date.) T h e c l a u s e i s o p t i o n a l i n COBOL-85 w h e r e i t s o m i s s i o n d e f a u l t s t o LABEL RECORDS ARE S T A N D A R D . 3. S c o p e t e r m i n a t o r s (END-IF a n d E N D - R E A D ) are n o t p e r m i t t e d in C O B O L - 7 4 a n d h e n c e d o n o t a p p e a r i n Figure 2.7. S c o p e t e r m i n a t o r s are o p t i o n a l i n C O B O L - 8 5 , b u t are u s e d t h r o u g h o u t t h e text b e c a u s e of a d v a n t a g e s that will b e clearly e x p l a i n e d in C h a p t e r 7. D e s p i t e these differences the COBOL-74 i m p l e m e n t a t i o n of the engineering senior p r o g r a m is u p w a r d c o m p a t i b l e w i t h COBOL-85; that is, t h e p r o g r a m in Figure 2.7 will run without m o d i f i c a t i o n u n d e r t h e n e w c o m p i l e r . T h e c o n v e r s e is n o t true; t h e COBOL-85 listing in Figure 1.6 will n o t run u n d e r t h e earlier s t a n d a r d . X A i i tk V liVsi " « W e e x p e c t that y o u c o m p l e t e d t h e c h a p t e r w i t h little difficulty a n d that y o u w e r e a b l e to s u c c e s s f u l l y run t h e e n g i n e e r i n g s e n i o r p r o g r a m . T h e r e will b e t i m e s , h o w e v e r , w h e n n o t e v e r y t h i n g will g o a s s m o o t h l y a n d s o w e relate a favorite a n e c d o t e ("Mystery o f t h e M o n t h , " PC W o r l d M a g a z i n e , April 1983) that is a s r e l e v a n t t o d a y as w h e n it w a s w r i t t e n . As y o u r e a d o u r tale, r e m e m b e r t h a t a c o m p u t e r d o e s e x a c t l y w h a t y o u tell it t o d o , w h i c h is n o t n e c e s s a r i l y w h a t y o u w a n t it t o d o . It is a s o u r c e o f wonderful satisfaction w h e n everything works, but also the cause o f nearly u n b e l i e v a b l e frustration w h e n r e s u l t s are n o t w h a t y o u e x p e c t . Our s t o r y c o n c e r n s a m a n a g e r w h o p u r c h a s e d a PC a n d b e g a n t o u s e it e n t h u s i a s t i c a l l y . U n f o r t u n a t e l y , t h e f e e l i n g did n o t r u b off o n h i s a s s i s t a n t , w h o w a s a p p r e h e n s i v e o f c o m p u t e r s i n g e n e r a l , but w h o finally a g r e e d t o try t h e n e w technology. A s is f r e q u e n t l y t h e c a s e , t h e a s s i s t a n t ' s e x p e r i e n c e w i t h t h e c o m p u t e r w a s as frustrating as t h e m a n a g e r ' s w a s r e w a r d i n g . Every t i m e t h e a s s i s t a n t tried u s i n g t h e c o m p u t e r a n error m e s s a g e a p p e a r e d , y e t w h e n t h e m a n a g e r tried t h e s a m e p r o c e d u r e it w o r k e d fine. Finally, m a n a g e r a n d a s s i s t a n t w e n t t h r o u g h a s y s t e m a t i c c o m p a r i s o n o f e v e r y t h i n g t h e y d i d : t u r n i n g t h e m a c h i n e o n a n d off, h a n d l i n g disks, u s i n g t h e k e y b o a r d , e t c . T h e y c o u l d find n o d i f f e r e n c e i n their p r o c e d u r e s a n d c o u l d n o t a c c o u n t for t h e r e p e a t e d disk errors w h i c h p l a g u e d t h e a s s i s t a n t b u t left t h e manager alone. Just a s t h e y w e r e a b o u t t o give u p t h e m a n a g e r n o t i c e d that h i s a s s i s t a n t w a s wearing a c h a r m bracelet. H e looked closely, a n d sure e n o u g h o n e o f the c h a r m s w a s a tiny m a g n e t c o n t a i n i n g just e n o u g h force to interfere with reading t h e disk. T h e a s s i s t a n t s t o r e d t h e b r a c e l e t i n a d r a w e r a n d t h e m a c h i n e h a s b e e n fine e v e r s i n c e . T h e p o i n t o f o u r s t o r y is that t h e r e is a l w a y s a l o g i c a l r e a s o n for e v e r y t h i n g a c o m p u t e r d o e s or d o e s n o t d o , a l t h o u g h d i s c o v e r i n g t h a t r e a s o n m a y b e l e s s t h a n o b v i o u s . Y o u are a b o u t t o e m b a r k o n a w o n d e r f u l j o u r n e y t o w a r d t h e p r o d u c t i v e u s e o f a c o m p u t e r , w i t h a virtually u n l i m i t e d n u m b e r o f p o t e n t i a l a p p l i c a t i o n s . B e patient, b e inquisitive, and enjoy.
  • 52. The A margin consists of columns 8-11 whereas the B margin is defined as columns 12-72. Division and section headers, paragraph names, FD's, and 01-level entries must begin in the A margin; all other entries begin in the B margin (that is, in or past column 12). The execution of a COBOL program is a three part process, involving three distinct programs—a compiler, a linker, and the resultant load module. The means of communicating information about these programs (and their associated files) is dependent on the operating system. A compiler is a computer program that translates a higher-level (problemoriented) language such as COBOL into machine language; the input to a compiler is referred to as a source program, whereas the output is an object program. The linker combines the output produced by the compiler, with additional object modules (such as subroutines and/or Input/Output modules) to produce a load module. Execution of the COBOL program occurs when the load module processes the input file(s) to produce the required reports. COBOL-74 is intended to be upward compatible with COBOL-85 although subtle incompatibilities do exist between the two standards. The converse is not true, as COBOL-85 programs will not run under the earlier standard. A margin ASCII file B margin COBOL-74 COBOL-85 Debugging Editor Execution error GIGO Incompatibility Load module Object program Operating system Source, program Test data Coding form Comments Compilation error Compiler Continuation A translates a language into an language. 2. is the most recently approved COBOL standard, but is still widely used in industry.
  • 53. C h a p t e r 3. The 2 from Coding Form to Computer is in columns 8 to 11 of the coding sheet. 4. A comment is indicated by an in column . 5. Entries that are not required to begin in the A margin may begin anywhere in columns to __. 6. Division headers and paragraph names must begin in the 7. An . is used to enter programs into the computer. 8. The compile, link, and execute process requires the execution of distinct programs. 9. is the process of finding and correcting errors in a program. 10. Picture clauses may begin anywhere within the margin. 11. The output of compilation is input to a second program called the . 12. A clean compile (does/does not) guarantee that the resulting program execution will be correct. 13. Different mainframe computers will most likely use (different/identical) COBOL compilers. 14. Misspelling a reserved word wili result in a error. 15. Entering test data in the wrong columns will result in an error. TRUE/FALSE 1. A compiler translates a machine-oriented language into a problem-oriented language. 2. A well-written program will always produce correct results, even with bad data. 3. A compiler is a computer program. 4. The COBOL compiler for an IBM mainframe is identical to the compiler for a PC. 5. A COBOL program can run on a variety of computers. 6. Division headers must begin in the A margin. 7. Division headers must begin in column 8. 8. Section headers must begin in column 12. 9. Paragraph names must begin in column 8. 10. PICTURE clauses may appear in column 12 or after. 11. If a program compiles correctly, then it must execute correctly. 12. Columns 1-6 are never used on the coding sheet. 13. The use of columns 73-80 is optional. 14. Column 8 is used as a continuation column. 15. All editors have identical commands. 16. All computers use the same operating system. 17. Successful execution of the COBOL compiler produces a load module.
  • 54. Problems PROBLEMS 1. Figure 2.8a contains data for the COBOL program in Figure 2.8b, which will process a file of employee records and print the names of all programmers under 30. "igure 2.8 C O B O L Program and Associated Data for Problems 1 & 2 WALT BECHTEL NELSON KERBEL MARGOT HUMMER CATHY BENWAY JUD MCDONALD JACKIE CLARK LOUIS NORIEGA JEFF SHEESLEY PR0GRAMMER34 PR0GRAMMER23 PR0GRAMMER30 DATA BASE 23 DATA BASE 29 PR0GRAMMER22 PROGRAMER 24 ANALYST 28 39700 30000 45000 50000 55000 47500 42500 46400 (a) Data 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 IDENTIFICATION DIVISION. PROGRAM-ID. FIRSTTRY. AUTHOR. GRAUER. ENVIRONMENT DIVISION. INPUT-OUTPUT SECTION. FILE-CONTROL. SELECT EMPLOYEE-FILE ASSIGN TO 'A:CHAPTR02FIRSTTRY.DAT ORGANIZATION IS LINE SEQUENTIAL. SELECT PRINT-FILE ASSIGN TO PRINTER. DATA DIVISION. FILE SECTION. FD EMPLOYEE-FILE RECORD CONTAINS 44 CHARACTERS DATA RECORD IS EMPLOYEE-RECORD. 01 EMPLOYEE-RECORD. 05 EMP-NAME PIC X(25). 05 EMP-TITLE PIC X(10). 05 EMP-AGE PIC 99. 05 FILLER PIC XX. 05 EMP-SALARY PIC 9(5). FD PRINT-FILE RECORD CONTAINS 132 CHARACTERS DATA RECORD IS PRINT-LINE. 01 PRINT-LINE.
  • 55. C h a p t e r Igure 2 , 8 2 From Coding Form to Computer (continued) 29 05 FILLER P I C X. 30 05 PRINT-NAME PIC X(25). 31 05 FILLER P I C X(2). 32 05 PRINT-AGE P I C 99. 33 05 FILLER PIC X(3). 34 05 PRINT-SALARY P I C 9(5). 35 05 F I L L E R P I C X(94). 36 37 WORKING-STORAGE SECTION. 38 01 39 PROCEDURE DIVISION. 40 41 END-OF-DATA-FLAG P I C X(3) VALUE SPACES. PREPARE-PROGRAMMER-REPORT. OPEN INPUT EMPLOYEE-FILE 42 OUTPUT PRINT-FILE. 43 MOVE SPACES TO PRINT-LINE. 44 M O V E 'SALARY R E P O R T F O R P R O G R A M M E R S U N D E R 30' T O P R I N T - L I N E . 45 WRITE PRINT-LINE 46 47 AFTER ADVANCING 2 LINES. READ EMPLOYEE-FILE 48 AT END MOVE 49 50 PERFORM ' Y E S ' T O END-OF-DATA-FLAG END-READ. 51 52 CLOSE EMPLOYEE-FILE 53 54 PROCESS-EMPLOYEE-RECORDS U N T I L E N D - O F - D A T A - F L A G = 'YES'. PRINT-FILE. STOP RUN. 55 56 57 PROCESS-EMPLOYEE-RECORDS. I F E M P - T I T L E = ' P R O G R A M M E R ' A N D E M P - A G E < 30 58 MOVE SPACES TO PRINT-LINE 59 MOVE EMP-NAME TO PRINT-NAME 60 MOVE EMP-AGE TO PRINT-AGE 61 MOVE EMP-SALARY T O PRINT-SALARY 62 WRITE PRINT-LINE 63 END-IF. 64 READ 65 66 EMPLOYEE-FILE A T END M O V E 'YES' T O END-OF-DATA-FLAG END-READ. (b) C O B O L Program a. Compile, link, and execute the COBOL program, using the appropriate commands for your system. (The program is on the data disk that accompanies this book.) b. Are any potential problems introduced by checking age rather than date of birth? c. Would processing be simplified if the employee records contained an abbreviated title code (for example, 010) rather than an expanded title (for example, programmer)? Are there any other advantages to storing codes rather than expanded values?
  • 56. 2. Modify the program in Figure 2.8b to accommodate all of the following. a. Employee age is stored in positions 38 and 39 of the incoming record. b. The report should list all employees under age 30 who earn at least $30,000, regardless of title. c. The report should include the title of all selected employees in positions 41-52. 3. Match each item with its proper description. 1. A Margin 2. B Margin 3. Comment 4. IDENTIFICATION DIVISION 5. PROCEDURE DIVISION 6. Hyphen 7. Nonnumeric literal 8. Reserved word 9. Compiler 10. Literal a. An asterisk in column 7 b. First line of any COBOL program c. Often appears in data names d. Columns 12 through 72 e. Contains the logic of a program f. Limited to 160 characters, and enclosed in quotes or apostrophes Where division, section, and gparagraph headers begin h. Translates COBOL to machine language i. Preassigned meaning i A constant; may be numeric or jnonnumeric 4. Indicate the starting column (or columns) for each of the following. a. Division headers b. Comments c. Paragraph names d. Statements in the Procedure Division (except paragraph names) e. WORKING-STORAGE SECTION f. FD g. 01 entries h. 05 entries i. PICTURE clauses j. OPEN statement k. WRITE statement I. SELECT statement 5. Explain how it is possible for a program) to compile perfectly, be logically correct, and still produce invalid results; provide specific examples in conjunction with the engineering senior program.
  • 57. Overview T h e Tuition Billing P r o b l e m Structured Design Evaluating t h e Hierarchy Chart Completeness Functionality Span of Control Structured Programming Sufficiency of the B a s i c Structures Expressing Logic The Traditional Flowchart Pseudocode Wamier-Orr Diagrams Top-Down Testing Summary Fill-in True/False Problems
  • 58. C h a p t e r 3 — A Methodology tor Program Development After reading this chapter you will be able to: Describe how a hierarchy chart is developed; d i s c u s s three criteria for evaluating a completed hierarchy chart. Define structured programming; describe its three fundamental building blocks and an optional extension. Explain the one entry point/one exit point philosophy of structured programming. Differentiate between structured programming and structured design; distinguish between a functionally oriented technique and one that is procedurally oriented. Describe what is meant by top down design and implementation. We stated at the outset that programming is best learned by doing, and so our objective in the first two chapters w a s to put you on the computer a s quickly a s possible. Thus, we jumped immediately into C O B O L , without giving much thought to the underlying logic of the program you developed. While that approach works well initially, it is also important for you to learn how to properly design programs, so that they will work correctly, and further so that they c a n be easily read and maintained by someone other than yourself. Accordingly, this chapter presents a methodology for program development, embracing the techniques of structured design, structured programming, and top down testing. We stress that structured design is functionally oriented and describes what is to be accomplished; structured programming, on the other hand, is procedurally oriented and focuses on how the objectives of the program will be realized. T h e d i s c u s s i o n includes hierarchy charts, p s e u d o c o d e , flowcharts, and Warnier-Orr diagrams. The presentation is of a practical nature, and stresses application rather than theory. Accordingly, we introduce a new program at the beginning of the chapter, and develop the methodology in the context of that program. We begin with presentation of the program specifications. This s e c t i o n c o n t a i n s t h e s p e c i f i c a t i o n s for a n e w p r o b l e m , k n o w n s i m p l y a s t h e t u i t i o n billing p r o g r a m . T h e r e q u i r e m e n t s are straightforward a n d parallel t h o s e o f m a n y o t h e r COBOL p r o g r a m s , n a m e l y t o print a h e a d i n g l i n e ( s ) at t h e start o f p r o c e s s i n g , o n e o r m o r e detail l i n e s for e v e r y r e c o r d p r o c e s s e d , a n d a total line(s) at t h e e n d of p r o c e s s i n g . A s s i m p l e a s t h e s e s p e c i f i c a t i o n s m a y b e , it is critical that y o u a v o i d t h e t e m p t a t i o n t o rash i m m e d i a t e l y i n t o COBOL, a n d c o n c e n t r a t e i n s t e a d o n d e s i g n i n g t h e p r o g r a m y o u will e v e n t u a l l y write.
  • 59. The Tuition Billing Problem The a p p r o a c h w e follow begins with a determination of the m o s t general s m a l l e r p i e c e s , until t h e r e q u i r e m e n t s of e a c h p i e c e are clearly r e c o g n i z e d . Initially t h e d e s i g n p r o c e s s m a y s e e m s u p e r f l u o u s in that y o u are c o n f i d e n t o f y o u r ability to b e g i n c o d i n g i m m e d i a t e l y . Rest a s s u r e d , h o w e v e r , that d e s i g n is p r o d u c t i v e work, a n d d o e s in fact p a y d i v i d e n d s in t h e l o n g run. A w e l l - d e s i g n e d p r o g r a m is far m o r e likely to b e c o r r e c t t h a n o n e w r i t t e n off-the-cuff. Moreover, a n d this m a y b e t h e a r g u m e n t that m o s t a p p e a l s to y o u , a w e l l - d e s i g n e d p r o g r a m will u l t i m a t e l y b e c o m p l e t e d i n l e s s t i m e t h a n o n e t h a t is p o o r l y d e s i g n e d or o n e that h a s n o d e s i g n at all. R A M M I N G Program Name: Narrative: S P E C I F I C A T I O N S Tuition Billing Program This program processes a file of student records, computes and prints the tuition bill for each student, and prints the total amounts for all students. STUDENT-FILE Input Fl ( ) ie s : See Figure 3.1a Test Data: Report Layout: Processing Requirements: SMITH JAMES BAKER PART-TIMER JONES HEAVYWORKER LEE CLARK GROSSMAN FRANKEL BENWAY KERBEL JB15Y0000230 HR15 0500245 b K u y ubuujsu JR03Y0000300 PL15Y0000280 HM18 0000200 BL18 0000335 JC06 0000310 SE07 0000215 LF10 0000350 CT03 0250395 NB04 0000100 See Figure 3.1b 1. Print a suitable heading at the beginning of the report. 2. Read a file of student records. 3. Process each record read by: a. Computing an individual bill, equal to the sum of tuition, union fee, and activity fee, minus a scholarship (if any), by: i. Calculating the tuition due, at a rate of $200 per credit. ii. Billing the student $25 for the union fee, if there is a "Y" in the Union Member position. iii. Computing the activity fee based on the number of credits taken: ACTIVITY FEE CREDITS $25 6 or fewer $50 7 - 12 more than 12 $75
  • 60. C h a p t e r 3 — A Methodology for Program Development Record Layouts for Tuition Billing Program CREDITS INITIALS UNION MEMBER SCHOLARSHIP STUDENT NAME GPA LAST 1 2 3 4 5 6 7 8 9 10 11 12 13 14 1516 17 18 19 20 21 22 23 2425 26 27 v (a) Input Record Layout STUDENT CREDITS NAME XXXXXXXX XXXXXXX XXXXXXXX XXXXXXX TUITION UNION FEE ACT FEE SCHOLARSHIP TOTAL BILL X $$9 $ , $ $9 X $$9 $,$S9 $$ , $ $ 9 ,$59 $$$,$$9 $$$,$$9 $$$$,$$9 UNIVERSITY (b) Report f o r m a ! iv. Awarding a scholarship equal to the amount in the incoming record if, and only if, the GPA is greater than 2.5. (Observe that in the test data on the previous page James does not qualify for the $500 scholarship he would otherwise have been awarded.) v. Incrementing the university totals for tuition, union fee, activity fee, scholarship, and overall total. b. Printing a detail line for each record read. 4. Print a total line at the end of the report. Structured design i d e n t i f i e s t h e t a s k s a p r o g r a m is t o a c c o m p l i s h , t h e n r e l a t e s t h o s e tasks t o o n e a n o t h e r in a hierarchy chart. F i g u r e 3.2 c o n t a i n s a v e r y b a s i c e x a m p l e , a p p l i c a b l e t o a n y COBOL p r o g r a m . T h e h i e r a r c h y c h a r t d i v i d e s t h e p r o g r a m i n t o its f u n c t i o n a l c o m p o n e n t s , for e x a m p l e , initialization, p r o c e s s i n g , a n d t e r m i n a t i o n ,
  • 61. Structured Design a n d indicates the m a n a g e r / s u b o r d i n a t e relationships b e t w e e n these c o m p o n e n t s . In this e x a m p l e all t h r e e m o d u l e s are s u b o r d i n a t e t o t h e m o d u l e l a b e l e d a n y COBOL p r o g r a m . To better a p p r e c i a t e t h e significance of a hierarchy chart a n d its role in p r o g r a m d e v e l o p m e n t , c o n s i d e r Figure 3.3, d e p i c t i n g t h e h i e r a r c h y chart for t h e t u i t i o n billing p r o g r a m . T h e d e v e l o p m e n t takes p l a c e in s t a g e s , b e g i n n i n g at t h e t o p a n d w o r k i n g d o w n to t h e b o t t o m . At every level, t h e major f u n c t i o n ( s ) are s u b d i v i d e d i n t o o t h e r f u n c t i o n s that are p l a c e d o n t h e n e x t l o w e r level i n t h e h i e r a r c h y chart. T h o s e f u n c t i o n s are in turn further s u b d i v i d e d i n t o still o t h e r f u n c t i o n s , until finally t h e l o w e s t - l e v e l f u n c t i o n s c a n n o t b e further s u b d i v i d e d . T h e s p e c i f i c a t i o n s for t h e tuition billing p r o b l e m s u g g e s t a s u i t a b l e n a m e for t h e h i g h e s t - l e v e l m o d u l e , PREPARE-TUITION-REPORT. This in t u r n is d i v i d e d i n t o its b a s i c f u n c t i o n s of initialization ( c o n s i s t i n g of WRITE-HEADING-LINE a n d READ-STUDENT-FILE), processing (PROCESS-STUDENT-RECORD), and t e r m i n a t i o n (WRITE-UNIVERSITY-TOTALS). Levels 1 a n d 2 of t h e h i e r a r c h y chart are s h o w n i n Figure 3.3a. Of t h e s e four m o d u l e s , o n l y o n e , PROCESS-STUDENT-RECORD, n e e d s to b e s u b d i v i d e d . In o t h e r w o r d s ask y o u r s e l f w h i c h a d d i t i o n a l l o w e r - l e v e l f u n c t i o n s s h o u l d b e i n c l u d e d u n d e r P R O C E S S - S T U D E N T - R E C O R D in o r d e r to p r o c e s s individual s t u d e n t r e c o r d s . T h e p r o g r a m s p e c i f i c a t i o n s c o n t a i n t h e r e q u i r e m e n t to c o m p u t e t h e i n d i v i d u a l ' s bill, i n c r e m e n t t h e u n i v e r s i t y totals to i n c l u d e t h e a m o u n t just c o m p u t e d , a n d write a detail line for the particular s t u d e n t . E a c h of t h e s e tasks r e q u i r e s its o w n m o d u l e a s i n d i c a t e d i n F i g u r e 3.3b. In a d d i t i o n , PROCESSSTUDENT-RECORD m u s t also read t h e next record s o that t h e p r o g r a m c a n c o n t i n u e . (The m o d u l e READ-STUDENT-FILE a p p e a r s t w i c e in t h e h i e r a r c h y chart; o n level t w o to r e a d t h e first r e c o r d a n d o n level t h r e e to read all s u b s e q u e n t r e c o r d s . T h e n e c e s s i t y for t h e d u a l a p p e a r a n c e s t e m s f r o m a l i m i t a t i o n i n COBOL-74 rather t h a n a r e q u i r e m e n t of s t r u c t u r e d d e s i g n ) . T h e d e v e l o p m e n t of a h i e r a r c h y chart c o n t i n u e s until its l o w e s t - l e v e l m o d u l e s c a n n o t b e further s u b d i v i d e d , t h a t is, until t h e d e s i g n e r b e l i e v e s t h e y c a n b e e a s i l y t r a n s l a t e d i n t o p r o g r a m m i n g s t a t e m e n t s . T h e d e c i s i o n is subjective i n that t h e r e is n o s i n g l e correct a n s w e r ; y o u c o u l d , for e x a m p l e , s t o p at t h r e e l e v e l s o r c o n t i n u e to a fourth level a s in Figure 3.3c. W e c h o s e to d i v i d e COMPUTE-INDIVIDUAL-BILL into four additional m o d u l e s : COMPUTE-TUITION, C O M P U T E - U N I O N - F E E , COMPUTE-ACTIVITY-FEE, a n d COMPUTE-SCHOLARSHIP. T h e h i e r a r c h y chart is n o w c o m p l e t e a n d c o n s i s t s of four l e v e l s , e a c h of w h i c h will c o r r e s p o n d t o a PERFORM s t a t e m e n t in t h e e v e n t u a l C O B O L p r o g r a m ; F i g u r e 3-2 Overall C O B O L Hierarchy Chart ANY COBOL PROGRAM INITIALIZATION PROCESSING TERMINATION
  • 62. C h a p t e r .3 3 — A Methodology for Program Development Hierarchy Chart for Tuition Billing Program 1st Level 2nd Level Processing Requirements 1. 2. 3. 4. PREPARE TUITION REPORT Print a heading line Read student Process each record Print a total line WRITE HEADING LINE READ STUDENT FILE PROCESS STUDENT RECORD WRITE UNIVERSITY TOTALS PROCESS STUDENT RECORD WRITE UNIVERSITY TOTALS PREPARE TUITION REPORT WRITE HEADING LINE READ STUDENT FILE otu t-evet nuuessifiy 3a) 3a) 3a) 3a) Requirements Compute individual bill Increment totals Write a detail line Read a student record w COMPUTE INDIVIDUAL BILL INCREMENT UNIVERSITY TOTALS WRITE DETAIL LINE r READ STUDENT FILE t h a t is, t h e m o d u l e (paragraph) o n l e v e l o n e will p e r f o r m t h e m o d u l e s (paragraphs) o n l e v e l t w o , t h o s e o n l e v e l t w o will p e r f o r m t h e m o d u l e s o n l e v e l t h r e e , a n d s o o n . T h e h i e r a r c h y chart d o e s n o t s p e c i f y h o w o f t e n t h e s e p a r a g r a p h s will b e called, n o r d o e s it i n d i c a t e t h e c o n d i t i o n s for c a l l i n g o n e s u b o r d i n a t e i n l i e u o f a n o t h e r . In o t h e r w o r d s , t h e h i e r a r c h y c h a r t i n d i c a t e s o n l y w h a t f u n c t i o n s are n e c e s s a r y , b u t n o t w h e n t h e y are e x e c u t e d . It c o n t a i n s n o d e c i s i o n - m a k i n g logic, n o r d o e s it i m p l y a n y t h i n g a b o u t t h e o r d e r or f r e q u e n c y i n w h i c h v a r i o u s p a r a g r a p h s w i t h i n a p r o g r a m are e x e c u t e d . T h a t , i n turn, is s p e c i f i e d w i t h i n t h e l o g i c o f t h e p r o g r a m , d e v e l o p e d a c c o r d i n g to the discipline of structured p r o g r a m m i n g as d i s c u s s e d later i n t h e c h a p t e r . ' _<„ i * & X L, *' G < > > l^L L A s w e h a v e a l r e a d y i n d i c a t e d , t h e d e c i s i o n o f h o w m a n y m o d u l e s to i n c l u d e i n a h i e r a r c h y c h a r t a n d h o w t h e y s h o u l d b e r e l a t e d t o o n e a n o t h e r is n e c e s s a r i l y s u b j e c t i v e . N e v e r t h e l e s s , t h e r e are c e r t a i n e v a l u a t i o n criteria t h a t result i n s e l e c t i n g o n e d e s i g n o v e r a n o t h e r . A m o n g t h e s e are t h e f o l l o w i n g :
  • 63. Evaluating the F i g u r e 3.3 Hierarchy Chart (continued) PREPARE TUITION REPORT WRITE HEADING LINE READ STUDENT FILE COMPUTE INDIVIDUAL BILL PROCESS STUDENT RECORD WRITE UNIVERSITY TOTALS INCREMENT UNIVERSITY TOTALS READ STUDENT FILE 4th Level Processing Requirements COMPUTE TUITION COMPUTE UNION FEE COMPUTE ACTIVITY FEE COMPUTE SCHOLARSHIP 3a(1) 3a(2i 3a 3 3a(4) Compute tuition Compute union fee Compute activity tee Compute scholarship (c) Complete Hierarchy Chart (Levels 1-4} 1. Is t h e h i e r a r c h y chart c o m p l e t e ? 2. Are t h e m o d u l e s f u n c t i o n a l ? 3. Is t h e r e effective s p a n o f control? Completeness A h i e r a r c h y chart m u s t b e c o m p l e t e ; that is, it h a s t o p r o v i d e for e v e r y f u n c t i o n r e q u i r e d b y t h e p r o g r a m a s s p e c i f i e d i n t h e p r o g r a m m i n g s p e c i f i c a t i o n s . Y o u test for c o m p l e t e n e s s level b y level, starting a t t h e t o p o f t h e h i e r a r c h y chart, a n d w o r k i n g y o u r w a y d o w n , o n e level at a t i m e , b y a s k i n g t h e q u e s t i o n , " D o t h e s u b o r d i n a t e m o d u l e s at t h e n e x t level c o m p l e t e l y d e v e l o p their c o r r e s p o n d i n g m o d u l e s at this level?" If t h e a n s w e r is y e s , m o v e t o t h e n e x t m o d u l e o n t h e p r e s e n t level, or t o t h e first m o d u l e o n t h e next level, a n d r e p e a t t h e q u e s t i o n . If t h e a n s w e r is n o , a d d f u n c t i o n s a s n e c e s s a r y a n d c o n t i n u e t o t h e n e x t m o d u l e . For e x a m p l e , b e g i n w i t h t h e c o m p l e t e d h i e r a r c h y chart o f F i g u r e 3.3c a n d ask y o u r s e l f w h e t h e r t h e m o d u l e s o n level t w o are a d e q u a t e to e x p a n d t h e s i n g l e m o d u l e of level o n e ; t h a t is, d o t h e four m o d u l e s o n l e v e l t w o c o m p l e t e l y e x p a n d t h e PREPARE-TU1TION-REPORT m o d u l e t o w h i c h t h e y are s u b o r d i n a t e ? T h e a n s w e r is yes, s o y o u m o v e to l e v e l t h r e e a n d s e e w h e t h e r t h e m o d u l e s o n this l e v e l a d e q u a t e l y e x p a n d t h e P R O C E S S - S T U D E N T - R E C O R D m o d u l e f r o m level t w o . O n c e a g a i n t h e a n s w e r is y e s , a n d s o y o u p r o g r e s s t o level four. T h e p r o c e s s c o n t i n u e s until y o u h a v e c h e c k e d e v e r y m o d u l e o n e v e r y l e v e l a n d a r e satisfied t h a t all n e c e s s a r y f u n c t i o n s are i n c l u d e d .
  • 64. C h a o t o r 3 ' t h o d o l o g y tor Program Development Functionality , Every m o d u l e in a h i e r a r c h y chart s h o u l d b e d e d i c a t e d t o a single f u n c t i o n , t h e n a t u r e o f w h i c h s h o u l d b e clear f r o m e x a m i n i n g t h e m o d u l e ' s n a m e . E a c h o f t h e m o d u l e n a m e s in Figure 3.3 c o n s i s t s of a v e r b , a d j e c t i v e (or t w o ) , a n d a n o b j e c t — f o r e x a m p l e , C O M P U T E - I N D I V I D U A L - B I L L or WRITE-DETAIL-LINE. I n d e e d , if a m o d u l e c a n n o t b e n a m e d i n this w a y , its f u n c t i o n is p r o b a b l y n o t w e l l d e f i n e d a n d t h o u g h t s h o u l d b e g i v e n t o revising t h e h i e r a r c h y chart. S t a t e d a n o t h e r w a y , y o u s h o u l d reject (or r e d e s i g n ) a n y m o d u l e that d o e s n o t a p p e a r to b e f u n c t i o n a l ; that is, m o d u l e s w h o s e n a m e s c o n t a i n : 1. M o r e t h a n o n e v e r b — f o r e x a m p l e , READ-AND-WRITE. 2. M o r e t h a n o n e o b j e c t — f o r e x a m p l e , EI) IT-NAM E - A N D - A C C O U NT-DATA. 3. N o n d e s c r i p t i v e or t i m e - r e l a t e d t e r m s — f o r e x a m p l e , HOUSEKEEPING, T E R M I N A T I O N - R O U T I N E , INITIALIZATION, or MAINLINE. A n o t h e r w a y o f e x p r e s s i n g t h e n e e d for f u n c t i o n a l m o d u l e s is to strive for m o d u l e i n d e p e n d e n c e ; t h a t is, t h e internal w o r k i n g s of o n e m o d u l e s h o u l d n o t affect t h o s e o f a n o t h e r . P e r h a p s y o u h a v e a l r e a d y b e e n a s s o c i a t e d w i t h a w o r k i n g p r o g r a m in w h i c h c h a n g e s w e r e i m p l e m e n t e d , o n l y t o h a v e s o m e other, a p p a r e n t l y unrelated, portion of the program n o longer work properly. T h e p r o b l e m m a y b e d u e to paragraphs in the p r o g r a m being u n n e c e s s a r i l y dependent o n o n e another. W h a t w e are s a y i n g is t h a t in a n ideal s i t u a t i o n , c h a n g e s m a d e to o n e paragraph s h o u l d n o t affect t h e r e s u l t s o f a n y o t h e r . In a m o r e practical s e n s e , t h e p a r a g r a p h s h a v e t o b e s o m e w h a t related, o t h e r w i s e t h e y w o u l d n o t b e parts o f t h e s a m e p r o g r a m ; however, the a m o u n t of i n t e r d e p e n d e n c e b e t w e e n paragraphs s h o u l d be m i n i m i z e d to t h e g r e a t e s t e x t e n t p o s s i b l e . W i t h r e s p e c t t o F i g u r e 3 . 3 , for e x a m p l e , a c h a n g e i n t h e p r o c e d u r e for c o m p u t i n g t h e u n i o n f e e s h o u l d n o t affect h o w t h e activity fee is d e t e r m i n e d . T h a t is b e c a u s e t h e m o d u l e s C O M P U T E - U N I O N - F E E a n d C O M P U T E ACTIVITY-FEE are f u n c t i o n a l i n their o w n right, a n d c o n s e q u e n t l y are i n d e p e n d e n t of o n e another. Span ©f Control _ „ _ T h e span of control o f a m o d u l e is t h e n u m b e r o f s u b o r d i n a t e s it c o n t a i n s . In F i g u r e 3.3, for e x a m p l e , t h e s p a n o f c o n t r o l o f b o t h PREPARE-TUITION-REPORT a n d COMPUTE-INDIVIDUAL-BILL is four. A n effective s p a n of c o n t r o l (for h i e r a r c h y c h a r t s a s s o c i a t e d w i t h C O B O L p r o g r a m s ) is g e n e r a l l y f r o m t w o or t h r e e t o s e v e n , a l t h o u g h that m a y vary d e p e n d i n g o n t h e s i t u a t i o n . Y o u s h o u l d , h o w e v e r , a v o i d extremes in either direction. Programs w i t h ineffective s p a n s of control (too m a n y s u b o r d i n a t e s o r t o o few) are p o o r l y d e s i g n e d a n d difficult t o f o l l o w a n d / o r m a i n t a i n . Structured Pl»Qgi>gr|irf)Jng Let u s p a u s e for a m o m e n t t o s e e w h a t h a s b e e n a c c o m p l i s h e d . W e h a v e t a k e n t h e original p r o b l e m a n d d i v i d e d it i n t o a s e r i e s o f m a n a g e a b l e p i e c e s , e a c h o f w h i c h d e s c r i b e s a particular j o b that n e e d s to b e a c c o m p l i s h e d . In o t h e r w o r d s , w e h a v e said what n e e d s to be d o n e to solve the problem, but have not as yet said h o w w e will s o l v e it. T h a t in e s s e n c e is t h e d i f f e r e n c e b e t w e e n s t r u c t u r e d d e s i g n a n d structured programming. A s t r u c t u r e d p r o g r a m is o n e c o n s i s t i n g entirely o f t h r e e t y p e s o f logic structures: s e q u e n c e , s e l e c t i o n (a d e c i s i o n ) , a n d i t e r a t i o n (a l o o p ) . T h e fact t h a t t h e s e s t r u c t u r e s
  • 65. Structured Programming (or b a s i c b u i l d i n g b l o c k s ) are sufficient t o e x p r e s s a n y d e s i r e d l o g i c w a s first postulated in a now-classic paper by B o h m and Jacopini. 1 T h e e l e m e n t a r y b u i l d i n g b l o c k s o f s t r u c t u r e d p r o g r a m m i n g are s h o w n in f l o w c h a r t f o r m i n F i g u r e 3.4. F l o w c h a r t s u s e s p e c i a l s y m b o l s t o c o m m u n i c a t e information. A rectangle indicates a processing statement, a d i a m o n d indicates a d e c i s i o n , a n d a s m a l l circle c o n n e c t s p o r t i o n s of t h e f l o w c h a r t . All o f t h e f l o w c h a r t s have o n e key feature in c o m m o n , namely, a single entry point a n d a single exit point, t h a t is, t h e r e is o n l y o n e w a y t o e n t e r e a c h s t r u c t u r e a n d o n l y o n e w a y to leave. T h e sequence s t r u c t u r e i n Figure 3.4a s p e c i f i e s t h a t t h e p r o g r a m s t a t e m e n t s are e x e c u t e d s e q u e n t i a l l y , in t h e o r d e r i n w h i c h t h e y a p p e a r . T h e t w o b l o c k s , A a n d B, m a y d e n o t e a n y t h i n g f r o m s i n g l e s t a t e m e n t s t o c o m p l e t e p r o g r a m s , a n d it is clear that t h e r e is a s i n g l e entry p o i n t a n d a s i n g l e exit p o i n t t o t h e s t r u c t u r e . 1 Bohm and Jacopini, "Flow Diagrams, Turing Machines and Languages with Only Two Formation Rules," Communications of the ACM (May 1966). The Building Blocks of Structured Programming (c) Iteration (d) C s a e
  • 66. C h a p t e r T h e selection 3 — A Methodology for Program Development (or IF . . . T H E N . . . ELSE) s t r u c t u r e i n F i g u r e 3.4b s p e c i f i e s a c h o i c e b e t w e e n t w o a c t i o n s . A c o n d i t i o n i s t e s t e d w i t h o n e o f t w o o u t c o m e s ; if t h e c o n d i t i o n i s true, b l o c k A i s e x e c u t e d , w h i l e if it i s false, b l o c k B is e x e c u t e d . T h e c o n d i t i o n itself i s t h e s i n g l e e n t r y p o i n t , a n d b o t h p a t h s m e e t t o f o r m a s i n g l e exit p o i n t . T h e iteration (or D O . . . WHILE) s t r u c t u r e i n Figure 3.4c s p e c i f i e s r e p e a t e d e x e c u t i o n o f o n e o r m o r e s t a t e m e n t s w h i l e a c o n d i t i o n is true. A c o n d i t i o n i s t e s t e d and, if it is true, b l o c k A i s e x e c u t e d after w h i c h t h e c o n d i t i o n i s r e t e s t e d . If, h o w e v e r , t h e c o n d i t i o n is false, c o n t r o l p a s s e s t o t h e n e x t s e q u e n t i a l s t a t e m e n t after t h e i t e r a t i o n s t r u c t u r e . A g a i n , t h e r e i s a s i n g l e e n t r y p o i n t a n d a s i n g l e exit p o i n t f r o m the structure. T h e case structure i n Figure 3.4d e x p r e s s e s a m u l t i b r a n c h s i t u a t i o n . A l t h o u g h c a s e is actually a s p e c i a l i n s t a n c e o f s e l e c t i o n , it is c o n v e n i e n t t o e x t e n d t h e d e f i n i t i o n o f s t r u c t u r e d p r o g r a m m i n g t o i n c l u d e t h i s fourth t y p e o f b u i l d i n g block. T h e c a s e structure evaluates a c o n d i t i o n a n d b r a n c h e s to o n e o f several paths, d e p e n d i n g o n t h e v a l u e o f t h e c o n d i t i o n . A s w i t h t h e o t h e r b u i l d i n g b l o c k s , t h e r e is o n e e n t r y p o i n t a n d o n e exit p o i n t . ffficiency of t h e B a s i c S t r u c t u r e s T h e t h e o r y o f s t r u c t u r e d p r o g r a m m i n g s a y s s i m p l y that a n a p p r o p r i a t e c o m b i n a t i o n of the basic building blocks may be derived to solve any problem. This is possible b e c a u s e a n entire structure (sequence, selection, iteration, or case) m a y b e substituted a n y w h e r e b l o c k A o r B a p p e a r s . Figure 3.5 s h o w s a c o m b i n a t i o n o f the b a s i c s t r u c t u r e s t o illustrate t h i s c o n c e p t . F i g u r e 3.5 i s e s s e n t i a l l y a s e l e c t i o n s t r u c t u r e . H o w e v e r , i n s t e a d o f s p e c i f y i n g a s i n g l e s t a t e m e n t for t h e t r u e o r false b r a n c h e s , a s w a s d o n e i n F i g u r e 3.4, a c o m p l e t e b u i l d i n g b l o c k is u s e d i n s t e a d . T h u s , if c o n d i t i o n - 1 i s true, a n i t e r a t i o n s t r u c t u r e is e n t e r e d , w h e r e a s , if it is false, a s e q u e n c e s t r u c t u r e i s e x e c u t e d . B o t h t h e i t e r a t i o n a n d s e q u e n c e s t r u c t u r e s m e e t at a s i n g l e exit p o i n t w h i c h b e c o m e s t h e exit p o i n t for t h e initial s e l e c t i o n s t r u c t u r e . F i g u r e 3.5 S u f f i c i e n c y of t h e B a s i c S t r u c t u r e s FALSE TRUE J A 1 B TRUE FALSE Sequence Structure Iteration Structure
  • 67. W e n o w turn o u r attention t o w a y s in w h i c h p r o g r a m m e r s express logic, to t h e m s e l v e s a n d t o o t h e r s . W e b e g i n w i t h t h e traditional flowchart, t h e n m o v e t o newer techniques more closely associated with structured programming: p s e u d o c o d e a n d Warnier-Orr d i a g r a m s . Every p r o g r a m m e r is familiar w i t h t h e traditional flowchart's d e s c r i b e d i n Chapter 1. Although flowcharts have declined i n popularity, they remain i n w i d e s p r e a d u s e , primarily for d o c u m e n t a t i o n . O u r p e r s o n a l p r e f e r e n c e is t o u s e p s e u d o c o d e , b u t w e i n c l u d e Figure 3.6 for c o m p l e t e n e s s . T h e d e c i s i o n a s t o w h i c h t e c h n i q u e t o u s e is b e t w e e n y o u a n d y o u r instructor. T h e fact that m o s t p r o g r a m m e r s write s i m p l e n o t e s t o t h e m s e l v e s prior t o c o d i n g a p r o g r a m gave rise to pseudocode, a technique associated w i t h structured programming. A s w e indicated in Chapter 1, pseudocode is defined simply as neat n o t e s t o yourself, a n d u s e s s t a t e m e n t s similar t o c o m p u t e r i n s t r u c t i o n s t o d e s c r i b e l o g i c . Figure 3.7 r e p r e s e n t s the building blocks of structured p r o g r a m m i n g as they w o u l d b e w r i t t e n i n p s e u d o c o d e a n d c o r r e s p o n d s t o t h e flowcharts s h o w n i n Figure 3.4. P s e u d o c o d e c o m e s i n t o p l a y after t h e d e s i g n p h a s e o f a p r o g r a m h a s b e e n n a t u r e a n d i n d i c a t e s what h a s t o b e d o n e , b u t n o t n e c e s s a r i l y when or how. P s e u d o c o d e , o n t h e o t h e r h a n d , is procedural a n d c o n t a i n s s e q u e n c e a n d d e c i s i o n ­ making logic. In other words, p s e u d o c o d e c o n n e c t s t h e m o d u l e s i n a hierarchy chart t h r o u g h l o o p s a n d d e c i s i o n m a k i n g . To better appreciate h o w p s e u d o c o d e expresses programming logic, consider Figure 3.8, w h i c h c o n t a i n s p s e u d o c o d e for t h e t u i t i o n billing p r o g r a m . T w o v e r s i o n s o f t h e p s e u d o c o d e are p r e s e n t e d — a n initial a t t e m p t i n Figure 3.8a, a n d a n e x p a n d e d ( m o r e d e t a i l e d ) v e r s i o n i n Figure 3.8b. B o t h v e r s i o n s are e q u a l l y a p p r o p r i a t e , w i t h the c h o i c e b e t w e e n t h e m d e p e n d i n g entirely o n t h e individual, a n d t h e level of d e t a i l h e or s h e d e s i r e s . T h e l o g i c is straightforward a n d b e g i n s w i t h t h e s t e p s for i n i t i a l i z a t i o n ; t o o p e n files, write a h e a d i n g l i n e ( s ) , a n d read t h e first r e c o r d . T h e n , a l o o p (or i t e r a t i o n structure) i s e n t e r e d i n w h i c h t h e p r o g r a m c o m p u t e s t h e s t u d e n t ' s bill (tuition p l u s u n i o n a n d activity f e e s m i n u s s c h o l a r s h i p ) , i n c r e m e n t s t h e u n i v e r s i t y totals t o i n c l u d e t h i s a m o u n t , w r i t e s a detail l i n e , a n d finally r e a d s t h e n e x t s t u d e n t r e c o r d . T h e s t a t e m e n t s i n t h e l o o p are e x e c u t e d c o n t i n u a l l y until all t h e r e c o r d s h a v e b e e n read, at w h i c h p o i n t u n i v e r s i t y t o t a l s a r e w r i t t e n , a n d t h e p r o g r a m t e r m i n a t e s . P s e u d o c o d e h a s a d i s t i n c t b l o c k s t r u c t u r e that is c o n d u c i v e t o s t r u c t u r e d p r o g r a m m i n g . It i s n o t , h o w e v e r , b o u n d b y f o r m a l s y n t a c t i c a l rules ( a l t h o u g h s o m e o r g a n i z a t i o n s h a v e i m p l e m e n t e d s t a n d a r d s ) , n o r d o e s it h a v e s p e c i f i c rules o f i n d e n t a t i o n , w h i c h is d o n e strictly at t h e p r o g r a m m e r ' s d i s c r e t i o n . Its o n l y l i m i t a t i o n is a restriction t o t h e b u i l d i n g b l o c k s of s t r u c t u r e d p r o g r a m m i n g ( s e q u e n c e , s e l e c t i o n , iteration, a n d c a s e ) . With practice, p s e u d o c o d e c a n b e d e v e l o p e d quickly a n d easily. G o o d p s e u d o c o d e s h o u l d b e s u f f i c i e n t l y p r e c i s e t o b e a real a i d i n w r i t i n g a p r o g r a m , while informal e n o u g h to b e u n d e r s t o o d b y nonprogrammers. T h e informality of
  • 68. C h a p t e r Figure 3.6 3 — A Methodology for Program Development Flowchart for Tuition Billing Program f V PROCESS STUDENT " A J START 1 < COMPUTE TUITION OPEN FILES > f COMPUTE UNION FEE COMPUTE ACTIVITY FEE TRUE WRITE UNIVERSITY TOTALS PROCESS STUDENT COMPUTE SCHOLARSHIP / INCREMENT UNIVERSITY TOTALS 1 WRITE DETAIL LINE CLOSE FILES I < STOP ^) READ STUDENT RECORD C (a) Overall Flowchart stop ) UDENT t h e t e c h n i q u e p r e c l u d e s exact rules, but w e urge t h e u s e of c o n s i s t e n t c o n v e n t i o n s t o m a k e it e a s i e r t o r e a d . O u r s u g g e s t i o n s : 1. I n d e n t for readability. 2. U s e E N D I F , E N D D O , a n d E N D C A S E to i n d i c a t e t h e e n d o f a l o g i c structure; u s e vertical l i n e s t o i n d i c a t e t h e e x t e n t o f a b l o c k .
  • 69. Pseudocode for Building Blocks Statement A Statement B IF condition is true Statement A ELSE Statement; B ENDIF DO WHILE condition is true Statement A ENDDO DO CASE Case 1 is true Statement A Case ? is true Statement B ENDCASE 3. U s e p a r e n t h e t i c a l e x p r e s s i o n s to clarify s t a t e m e n t s a s s o c i a t e d w i t h t h e ELSE p o r t i o n o f a n IF s t a t e m e n t . 4. M i n i m i z e or a v o i d t h e u s e o f a d j e c t i v e s a n d a d v e r b s . Warnier-Orr d i a g r a m s ( n a m e d for their c o - d e v e l o p e r s , Jean D o m i n i q u e Warnier a n d K e n n e t h Orr) c o m b i n e e l e m e n t s o f s t r u c t u r e d d e s i g n a n d s t r u c t u r e d programming. T h e diagrams u s e specific s y m b o l s to represent the b a s i c building b l o c k s o f s t r u c t u r e d p r o g r a m m i n g , t h e n c o m b i n e t h e s e e l e m e n t s i n hierarchical fashion. F i g u r e 3.9 s h o w s h o w t h e b a s i c b u i l d i n g b l o c k s o f s t r u c t u r e d p r o g r a m m i n g w o u l d b e r e p r e s e n t e d i n a Warnier-Orr d i a g r a m . S e q u e n t i a l s t a t e m e n t s (Figure 3.9a) are l i s t e d vertically, o n e u n d e r t h e o t h e r , a n d are g r o u p e d i n b r a c e s . A p l u s s i g n e n c l o s e d i n a circle i n d i c a t e s s e l e c t i o n , a n d i s p l a c e d b e t w e e n t h e t r u e a n d false c o n d i t i o n s o f t h e s e l e c t i o n structure (a bar d e n o t e s t h e false c o n d i t i o n ) . P a r e n t h e s e s i n d i c a t e i t e r a t i o n (Figure 3.9c), w i t h t h e n u m b e r i n s i d e t h e p a r e n t h e s e s i n d i c a t i n g
  • 70. C h a p t e r Figure 3.8 i j ' . { j ' 3 A Methodology for Program Pseudocode for Tuition Billing Program Open files Write heading line(s) Read STUDENT-FILE at end indicate no more data DO WHILE data remains Compute tuition Compute union fee Compute activity fee Compute scholarship Compute bill Increment university totals Write detail line Read STUDENT-FILE at end indicate no more data ENDDO Write university totals Close files Stop run (a) initial attempt l | ! j | j j j j I Open files Write heading 1ine(s) Read STUDENT-FILE at end indicate no more data DO WHILE data remains Compute tuition = 200 * credits IF union member Union fee = $25 ELSE Union fee = 0 ENDIF DO CASE CASE credits <= 6 Activity fee = 25 CASE credits > 6 and <= 12 Activity fee = 50 CASE credits > 12 Activity fee = 75 END CASE - — IF gpa > 2.5 Scholarship = Scholarship amount ELSE (no scholarship) Scholarship = 0 I ENDIF Compute Bill = Tuition + Union fee + Activity fee - Scholarship Increment university totals Write detail line Read STUDENT-FILE at end indicate no more data ENDDO Write university totals Close files Stop run (b) Detailed! pseudocode Development
  • 71. l u r e 3.9 Warnier-Orr Diagrams for Building Blocks Statement A Statement B fa) The Sequence Structure Condition {statement A Condition {Statement B (b) The Selection Structure (0, End) (Statement A (c) The Iteration Structure h o w o f t e n t h e l o o p is to b e p e r f o r m e d . A variable n u m b e r o f i t e r a t i o n s is i m p l i e d b y e n c l o s i n g t w o n u m b e r s , for e x a m p l e (0, End) to i n d i c a t e e x e c u t i o n u n t i l a n e n d - o f file c o n d i t i o n is r e a c h e d . T h e r e is n o s p e c i f i c n o t a t i o n for t h e c a s e c o n s t r u c t . Figure 3.10 c o n t a i n s a Warnier-Orr d i a g r a m for t h e tuition b i l l i n g p r o g r a m . The diagram depicts the s a m e m a n a g e r / s u b o r d i n a t e relationships as the hierarchy chart of Figure 3.3c, b u t u n l i k e t h e h i e r a r c h y chart, is r e a d f r o m left t o right rather t h a n f r o m t o p to b o t t o m . T h e d i a g r a m a l s o c o n t a i n s a d d i t i o n a l i n f o r m a t i o n n o t f o u n d i n t h e h i e r a r c h y chart, n a m e l y t h e l o g i c to i n d i c a t e h o w o f t e n , a n d i n w h a t s e q u e n c e , s u b o r d i n a t e m o d u l e s are e x e c u t e d . All p r o g r a m s r e q u i r e e x t e n s i v e t e s t i n g t o e n s u r e that t h e y c o n f o r m t o t h e original s p e c i f i c a t i o n s . H o w e v e r , t h e q u e s t i o n o f w h e n c o d i n g e n d s a n d t e s t i n g b e g i n s is n o t as straightforward as it m a y a p p e a r , a n d g i v e s rise to t h e p h i l o s o p h y of top- down testing. T o p - d o w n t e s t i n g s u g g e s t s that c o d i n g a n d t e s t i n g are parallel activities, a n d e s p o u s e s t h e p h i l o s o p h y that t e s t i n g b e g i n s e v e n b e f o r e a p r o g r a m is c o m p l e t e l y f i n i s h e d . T h i s is a c c o m p l i s h e d b y initially c o d i n g t h e i n t e r m e d i a t e - a n d / o r l o w e r l e v e l p a r a g r a p h s as stubs, that is, partially c o d e d p a r a g r a p h s w h o s e p u r p o s e is t o indicate only that the paragraph has b e e n executed. The stub paragraphs do n o u s e f u l w o r k p e r s e , a n d are u s e d o n l y t o test t h e overall flow o f t h e p r o g r a m . T h e r a t i o n a l e is that t h e h i g h e s t ( a n d m o s t difficult) m o d u l e s s h o u l d b e t e s t e d earlier a n d m o r e o f t e n t h a n t h e l o w e r - l e v e l r o u t i n e s ; t h e latter c o n t a i n d e t a i l e d b u t o f t e n trivial logic, a n d are l e a s t i m p o r t a n t w i t h r e s p e c t to t h e overall p r o g r a m flow. Figure 3.11 is a n e x a m p l e o f s u c h a p r o g r a m . It is complete in t h e s e n s e t h a t it c o n t a i n s a p a r a g r a p h for e v e r y m o d u l e in t h e h i e r a r c h y chart o f F i g u r e 3.3, y e t incomplete i n t h a t m o s t o f its p a r a g r a p h s c o n s i s t o f a s i n g l e DISPLAY s t a t e m e n t .
  • 72. C h a p t e r Figure 3.10 3 A Methodology for Program Development Warnier-Orr Diagram for Tuition Billing Program I Open files Write-heading-line Read-student-file (1) Compute-tuition (1) Compute-union-fee Compute-i ndi vidual-bi11 (1) Tuition-Billing Program (1) Compute-acti vi t y - f e e (1) Compute-scholarship (1) Process-record (0, End) Increment-uni versi ty-total s (1) Wri te-detai1-1i ne (1) Read-student-file (1) Wri t e - u n i v e r s i t y - t o t a l s (1) Close f i l e s Stop run (DISPLAY is o n e o f t h e m o s t u s e f u l s t a t e m e n t s i n COBOL a s it a l l o w s t h e p r o g r a m m e r t o print a m e s s a g e o n t h e s c r e e n — f o r e x a m p l e , DISPLAY " C O M P U T E - I N D I V I D U A L BILL p a r a g r a p h h a s b e e n e n t e r e d " — o r t o print t h e c o n t e n t s o f a d a t a n a m e — f o r e x a m p l e , DISPLAY S T U D E N T - R E C O R D — w i t h o u t h a v i n g t o o p e n a file. T h e DISPLAY s t a t e m e n t is c o v e r e d i n C h a p t e r 6.) T h e p r o g r a m i n F i g u r e 3 . 1 1 w a s t e s t e d w i t h t h e d a t a o f Figure 3.12a, a n d p r o d u c e d t h e o u t p u t of Figure 3.12b. Y o u m a y n o t think that m u c h h a s b e e n a c c o m p l i s h e d , b u t c l o s e r e x a m i n a t i o n s h o w s t h a t all o f t h e p a r a g r a p h s i n t h e p r o g r a m w e r e e x e c u t e d , a n d further that t h e y w e r e e x e c u t e d i n t h e correct s e q u e n c e . T h e t e s t i n g h a s d e m o n s t r a t e d t h a t t h e overall p r o g r a m f l o w is c o r r e c t . E x e c u t i o n b e g a n w i t h t h e p a r a g r a p h PREPARE-TUITION-REPORT f o l l o w e d b y t h e t h e p a r a g r a p h WRITE-HEADING-LINE. T h e record for t h e first s t u d e n t (JB S m i t h ) w a s r e a d , a n d t h e p a r a g r a p h PROC ESS - S T U D ENT- R E C O R D w a s e n t e r e d . T h e p a r a g r a p h C O M P U T E - I N D I V I D U A L - B I L L w a s e x e c u t e d n e x t , a n d c a l l e d its four s u b o r d i n a t e s t o c o m p u t e t h e t u i t i o n , u n i o n fee, activity f e e , a n d s c h o l a r s h i p . The paragraphs to i n c r e m e n t university totals a n d to write a detail line w e r e also c a l l e d . T h e d a t a for t h e s e c o n d s t u d e n t (HR J a m e s ) w a s r e a d , a n d PROCESSS T U D E N T - R E C O R D ( a n d all its s u b o r d i n a t e s ) w e r e r e - e x e c u t e d . E v e n t u a l l y t h e e n d o f file w a s r e a c h e d , t h e p a r a g r a p h WRITE-UNIVERSITY-TOTALS w a s e x e c u t e d , a n d the program ended. Yes, t h e p r o g r a m r e q u i r e s a d d i t i o n a l d e v e l o p m e n t , b u t t h e h a r d e s t part is over. A n y errors t h a t m a y h a v e e x i s t e d in t h e h i g h e s t - l e v e l m o d u l e s h a v e a l r e a d y
  • 73. Top-Down F i g u r e 3.11 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 [ 43 ~ 44 45 46 47 48 Testing , . ...» Tuition Billing Program with Stubs IDENTIFICATION DIVISION. PROGRAM-ID. TUITI0N3. AUTHOR. CAROL VAZQUEZ VILLAR. ENVIRONMENT DIVISION. INPUT-OUTPUT SECTION. FILE-CONTROL. SELECT STUDENT-FILE ASSIGN TO 'A:CHAPTR03TUITI0N.DAT' ORGANIZATION IS LINE SEQUENTIAL. DATA DIVISION. FILE SECTION. FD STUDENT-FILE RECORD CONTAINS 27 CHARACTERS. 01 STUDENT-RECORD PIC X(27). WORKING-STORAGE SECTION. 01 DATA-REMAINS-SWITCH PIC X(2) VALUE SPACES. PROCEDURE DIVISION. PREPARE-TUIT ION-REPORT. DISPLAY 'PREPARE-TUITION-REPORT paragraph entered'. OPEN INPUT STUDENT-FILE. PERFORM WRITE-HEADING-LINE. PERFORM READ-STUDENT-FILE. PERFORM PROCESS-STUDENT-RECORD UNTIL DATA-REMAINS-SWITCH = 'NO'. PERFORM WRITE-UNIVERSITY-TOTALS. CLOSE STUDENT-FILE. STOP RUN. WRITE-HEADING-LINE. DISPLAY 'WRITE-HEADING-LINE paragraph entered'. READ-STUDENT-FILE. READ STUDENT-FILE AT END MOVE 'NO' TO DATA-REMAINS-SWITCH END-READ. PROCESS-STUDENT-RECORD. DISPLAY ' '. DISPLAY 'PROCESS-STUDENT-RECORD paragraph entered'. DISPLAY 'Student record being processed: ' STUDENT-RECORD.| PERFORM COMPUTE-INDIVIDUAL-BILL. PERFORM INCREMENT-UNIVERSITY-TOTALS PERFORM WRITE-DETAIL-LINE. Display statement shows current record PERFORM READ-STUDENT-FILE.
  • 74. C h a p t e r .11 49 50 51 52 53 54 55 3 A Methodology for Program Development (continued) COMPUTE-INDIVIDUAL-BILL. DISPLAY COMPUTE-INDIVIDUAL-BILL paragraph entered', PERFORM COMPUTE-TUITION. PERFORM COMPUTE-UNION-FEE. PERFORM COMPUTE-ACTIVITY-FEE. PERFORM COMPUTE-SCHOLARSHIP. 1 COMPUTE-UNION-FEE. DISPLAY ' COMPUTE-UNION-FEE paragraph entered'. -roqram siuc COMPUTE-ACTIVITY-FEE. DISPLAY ' COMPUTE-ACTIVITY-FEE paragraph entered'. COMPUTE-SCHOLARSHIP. DISPLAY ' COMPUTE-SCHOLARSHIP paragraph entered'. INCREMENT-UNIVERSITY-TOTALS. DISPLAY INCREMENT-UNIVERSITY-TOTALS paragraph entered'. 1 WRITE-DETAIL-LINE. DISPLAY ' WRITE-DETAIL-LINE paragraph entered'. WRITE-UNIVERSITY-TOTALS. DISPLAY ' '. DISPLAY 'WRITE-UNIVERSITY-TOTALS paragraph entered'. b e e n f o u n d , a n d w e r e e a s i e r t o correct t h a n h a d t e s t i n g b e e n d e f e r r e d . Of c o u r s e , later v e r s i o n s o f t h e p r o g r a m c a n still c o n t a i n b u g s , b u t t h e s e errors will o c c u r i n l o w e r level m o d u l e s w h e r e c o r r e c t i o n is g e n e r a l l y easier. T h e m o r e difficult p r o b l e m s will a l r e a d y h a v e b e e n r e s o l v e d i n t h e initial tests, a n d t h a t is p r e c i s e l y t h e g o a l o f t o p - d o w n testing. W e urge y o u to i m p l e m e n t the t o p - d o w n approach to program testing, and offer F i g u r e 3 . 1 3 a s o u r l a s t w o r d o n t h e s u b j e c t . I n t h e t r a d i t i o n a l m o d e o f F i g u r e 3.13a, n o t e s t i n g is d o n e until t h e w e e k e n d b e f o r e t h e p r o g r a m g o e s live (or y o u r a s s i g n m e n t is d u e ) . I n e v i t a b l y l a s t - m i n u t e p a n i c s e t s in, g i v i n g rise t o o v e r t i m e a n d c h a o s , a n environment unlikely to produce logically correct programs. B y c o n t r a s t , the t o p d o w n a p p r o a c h o f Figure 3 . 1 3 b p r o v i d e s a m o r e u n i f o r m t e s t i n g pattern, b e g i n n i n g a l m o s t i m m e d i a t e l y with the project's i n c e p t i o n a n d c o n t i n u i n g t h r o u g h o u t its d u r a t i o n . T h e r e s u l t s are v a s t l y s u p e r i o r .
  • 75. Top-Down Testing Testing the Tuition Billing Program SMITH JAMES BAKER PART-TIMER JONES HEAVYWORKER LEE CLARK GROSSMAN FRANKEL BENWAY KERBEL JB15Y0000230 HR15 0500245 SR09 0500350 JR03Y0000300 PL15Y0000280 HM18 0000200 BL18 0000335 JC06 0000310 SE07 0000215 LF10 0000350 CT03 0250395 NB04 0000100 PREPARE-TUITION-REPORT paragraph entered WRITE-HEADING-LINE paragraph entered PROCESS-STUDENT-RECORD paragraph entered JB15Y0000230 Student record being processed: SMITH COMPUTE-INDIVIDUAL-BILL paragraph entered COMPUTE-TUITION paragraph entered COMPUTE-UNION-FEE paragraph entered COMPUTE-ACTIVITY-FEE paragraph entered COMPUTE-SCHOLARSHIP paragraph entered INCREMENT-UNIVERSITY-TOTALS paragraph entered WRITE-DETAIL-LINE paragraph entered PROCESS-STUDENT-RECORD paragraph entered Student record being processed: JAMES HR15 0500245 COMPUTE-INDIVIDUAL-BILL paragraph entered COMPUTE-TUITION paragraph entered COMPUTE-UNION-FEE paragraph entered COMPUTE-ACTIVITY-FEE paragraph entered COMPUTE-SCHOLARSHIP paragraph entered INCREMENT-UNIVERSITY-TOTALS paragraph entered WRITE-DETAIL-LINE paragraph entered PROCESS-STUDENT-RECORD paragraph entered Student record being processed: KERBEL NB04 0000100 COMPUTE-INDIVIDUAL-BILL paragraph entered COMPUTE-TUITION paragraph entered COMPUTE-UN ION-FEE paragraph entered COMPUTE-ACTIVITY-FEE paragraph entered COMPUTE-SCHOLARSHIP paragraph entered INCREMENT-UNIVERSITY-TOTALS paragraph entered WRITE-DETAIL-LINE paragraph entered WRITE-UNIVERSITY-TOTALS paragraph entered
  • 76. C h a p t e r F i g u r e 3.13 J— - A Methodology (or Program Development Advantages of Top-Down Testing Last-minute panic A c o o E < Time (a) Traditional Mode Time (b) Top-Down Mode SUMMARY j o i n t s to Remember Structured design is a functionally oriented technique that Identifies the tasks a program is to accomplish, then relates those tasks to one another in a hierarchy chart. in a COBOL program. A module (paragraph) can be entered only from the module immediately above it, and must return control to that module when execution is complete. A hierarchy chart is evaluated for completeness, functionality, and span of control. Structured programming is procedural in nature and contains decision­ making logic depicting the sequence in which the program tasks will be executed. A structured program consists entirely of the basic building blocks of sequence, selection, and iteration; a fourth construct, case, is commonly included in the definition of structured programming. Each of the elementary building blocks in structured programming has one entry point and one exit point. Flowcharts and/or pseudocode (defined as neat notes to yourself) describe the logic in a program. Warnier-Orr diagrams combine elements of structured design and structured programming. Top down testing begins early in the development process, even before a program is completely coded; it is accomplished through the use of program stubs.
  • 77. Fill-in Bohm and Jacopini Case structure Selection structure Flowchart Functional technique Sequence structure Span of control Hierarchy chart Structured design Iteration structure One entry point/one exit point Procedural technique Program stub I Pseudocode Structured programming Top-down development Warnier-Orr diagram L L 1. The fundamental building blocks of structured programming are: and . ?. The construct is a fourth structure, which is convenient for expressing multibranch situations. 3, All of the basic building blocks of structured programming have entry point and exit point. 4. In the iteration, or DO WHILE construct, the condition is tested (before/after) the procedure is executed. 5. The primary tool of structured design is the. . diagrams combine elements of a hierarchy chart and pseudocode. 7. A hierarchy chart is evaluated according to the criteria of , and . 8. Structured design is a programming is 9. oriented technique, whereas structured in nature. , rather than flowcharting, is the most common technique for expressing program logic. 10. Each module in a represents a in a COBOL program. 11. is the management term for the number of subordinate modules. 12. A well-chosen paragraph name should indicate the function of that paragraph, and consist of a , , and . 13. and postulating the structured theorem. are the individuals credited with first 14. Structured (programming/design) is intended to produce a solution with the same components and relationships as the problem it is intended to solve. 15. A program should be tested from the (top down/bottom up).
  • 78. C h a p t e r 3 A Methodology for Program Development T R U E/ FA L SE 1. A structured program is guaranteed not to contain logical errors. 2. Structured programming can be implemented in a variety of programming languages. 3. INITIALIZATION and TERMINATION are good module names. 4. The logic of any program can be expressed as a combination of only three types of logic structures. 5. The one entry/one exit philosophy is essential to structured programming. 6. Decision making should generally occur in higher-level, rather than lower-level, modules. 7. The case construct is one of the three basic logic structures. 8. A flowchart is the only way to communicate program logic. 9. Pseudocode has precise syntactical rules. 10. A program's hierarchy chart is developed from the bottom up. 11. A program must be completely coded before testing can begin. 12. A Warnier-Orr diagram combines elements of structured design and structured programming. 13. READ-WRITE-AND-COMPUTE is a good module name. 14. A single COBOL paragraph should accomplish many functions for optimal efficiency. 15. Program testing should be concentrated in the last 25% of the development phase. 16. A span of control from 15 to 25 COBOL paragraphs is desirable for the highestlevel modules. 17. The optimal number of modules in a system is equal to the number of programmers available for coding. 18. A module in a hierarchy chart can be called from another module on its own level. P R O B L EMS 1. Given the flowchart in Figure 3.14, respond "true" or "false" to the following on the basis of the flowchart. a. If X > Y and W > Z, then always add 1 to B. b. If X < Y, then always add 1 to D. c. If Q > T, then always add 1 to B. d. If X < Y and W < Z, then always add 1 to D. e. There are no conditions under which 1 will be added to both A and B simultaneously. f. If W > Z and Q < T, then always add 1 to C. 2. Assume that a robot is sitting on a chair, facing a wall a short distance away. Restricting yourself to the basic building blocks of structured programming, develop the necessary logic to have the robot walk to the wall and return to its initial position. Express your solution in pseudocode. The robot understands the following commands:
  • 79. sure 3 . 1 4 Flowchart for Problem 1 ADD 1 TO D ADD 1 TO A 1 ADD 1 TO C ADO 1 TO B STAND SIT TURN (turns right 90 degrees) STEP In addition, the robot can raise its arms and sense the wall with its fingertips. (However, it cannot sense the chair on its return trip, since the chair is below arm level.) Accordingly the robot must count the number of steps to the wall or chair by using the following commands: ADD (increments counter by 1) SUBTRACT (decrements counter by 1) ZERO COUNTER (sets counter to zero) ARMS UP ARMS DOWN The wall is assumed to be an integer number of steps away. Select a volunteer to act as the robot, and see whether the submitted solutions actually accomplish the objective.
  • 80. 3. Identify the elementary building blocks in Figure 3.15. Be sure you get all of them (the authors can find eight). 4. Indicate the output that will be produced by each of the following DISPLAY statements. a. DISPLAY 'STUDENT RECORD'. b. DISPLAY STUDENT-RECORD. c. DISPLAY 'STUDENT RECORD IS ' STUDENT-RECORD. d. DISPLAY. e. DISPLAY STUDENT-NAME, SOC-SEC-NUM. 5. This non-data-processing problem specifically avoids a business context, and was chosen because you are unlikely to have a preexisting bias toward a solution.
  • 81. Develop a hierarchy chart to allow a user to play a series of tic-tac-toe games interactively against a computer. The following modules were used in the author's solution: PLAY-SERIES, PLAY-GAME, CLEAR-BOARD, GET-USER-MOVE, VALIDATE-USER-MOVE, CHECK-FOR-WINNER, UPDATE-BOARD, GETCOMPUTER-MOVE, DISPLAY-BOARD, DISPLAY-MESSAGE. (The last module, DISPLAY-MESSAGE, may be called from several places.) The module names should in themselves be indicative of the module functions. 6. Again we have chosen a nonbusiness problem to give you further practice with structured design. This time you are asked to develop a hierarchy chart for the game of blackjack (also known as "21"). The game is played with a deck of 52 cards (or more commonly with multiple decks). The player places a bet, and the player and dealer are each dealt two cards. Both of the player's cards are face up (showing), but one of the dealer's cards is hidden. The player is asked whether he or she wishes to draw additional card(s), after which the dealer has the same option (provided the player has not gone over 21). The player closest to 21 (without going over) wins. The rules of the game require the dealer to draw with 16 or less, and stand (not draw) with 17 or more. Your hierarchy chart should contain the necessary modules to keep a runningtotalof the player's winnings (or losses) as well as the following special situations: a. Doubling down—if the player's first two cards total 11, he or she may double the bet and receive one additional card. b. Purchasing insurance—if the dealer's "up" card is an ace, the player may place an additional side bet. If the dealer has "blackjack," the player receives a payout of 2 to 1 on the side bet, but loses the initial bet. If the dealer does not have blackjack, the side bet is lust and play continues. c. Splitting pairs—if the player has a pair, he or she may double the bet and play two hands.
  • 82. Overview C O B O L Notation IDENTIFICATION DIVISION ENVIRONMENT DIVISION CONFIGURATION SECTION INPUT-OUTPUT S E C T I O N S H I M uiviaivn FILE SECTION File Description ( F D ) Record Description P I C T U R E Clause Level Numbers Assumed Decimal Point WORKING-STORAGE SECTION V A L U E Clause T h e Tuition Billing Program Programming Specifications C O B O L Entries Limitations of C O B O L - 7 4 Summary Fill-in True/False Problems
  • 83. C h a p t e r O B J E C T 4 i 'NORI.'ficatiort, Environment, and Data Divisions IVES After reading this chapter you will be able to: Describe the COBOL notation and determine the appropriate syntax for any statement. Complete the Identification Division of a COBOL program. Complete the Environment Division of a COBOL program. Code a record description to show hierarchical relationships among fields containing numeric and alphanumeric entries. Code a Working-Storage Section to define various print lines. Explain the use of an assumed decimal point. D 1 / cr p 1 / / c: 1/1/ The overall approach of this book is to provide a rapid introduction to computer programming; thus we presented a complete COBOL program in Chapter 1. Our objective at that time was to put you on the computer immediately, without too much concern for the syntactical rules, which you must eventually master. We move now to a formai study of COBOL, beginning with a notation that fully explains the variations permitted within any COBOL statement. The chapter focuses on the Identification, Environment, and Data Divisions, and concludes with a COBOL listing expanding on this material. w w d u l . Notation COBOL is a n E n g l i s h - l i k e l a n g u a g e w i t h i n h e r e n t flexibility i n t h e w a y a particular e n t r y m a y b e e x p r e s s e d . In o t h e r w o r d s , t h e r e are a n u m b e r o f different, b u t e q u a l l y a c c e p t a b l e , w a y s to s a y t h e s a m e t h i n g . It is n e c e s s a r y , t h e r e f o r e , to d e v e l o p a s t a n d a r d n o t a t i o n to p r o v i d e a clear a n d u n a m b i g u o u s m e a n s o f i n d i c a t i n g p r e c i s e l y w h a t is, a n d is n o t , p e r m i t t e d w i t h i n a n y g i v e n s t a t e m e n t . T h e n o t a t i o n is i l l u s t r a t e d in Figure 4.1 a n d a d h e r e s to t h e f o l l o w i n g c o n v e n t i o n s : 1. L o w e r c a s e letters signify p r o g r a m m e r - s u p p l i e d i n f o r m a t i o n — f o r e x a m p l e , identifier-1 or literal-1. 2. U p p e r c a s e letters i n d i c a t e r e s e r v e d w o r d s — f o r e x a m p l e , IF, GREATER, or THAN. 3. U p p e r c a s e letters that are u n d e r l i n e d are required; u p p e r c a s e letters that are n o t u n d e r l i n e d are o p t i o n a l r e s e r v e d w o r d s . 4. Brackets [ ] s y m b o l i z e a n o p t i o n a l e n t r y — f o r e x a m p l e , [ N O T ]. 5. B r a c e s {} i m p l y that o n e o f t h e e n c l o s e d i t e m s m u s t b e c h o s e n — f o r e x a m p l e , a c h o i c e is r e q u i r e d b e t w e e n identifier-1, literal-1, a n d a r i t h m e t i c expression-1. 6. T h r e e d o t s . . . m e a n t h a t t h e last s y n t a c t i c a l u n i t c a n b e r e p e a t e d a n arbitrary n u m b e r o f t i m e s .
  • 84. IDENTIFICATION DIVISION COBOL Notation UDtiona; entry. GREATER THAN /Programmer supplied LESS THAN EQUAL TO GREATER THAN OR EQUAL TO identlfier-1 If identifier-2 is [NOT] 1iteral-1 LESS THAN OR EQUAL TO literal-2 arithmetic expression-1 arithmetic expression-2 Optional reserved womisi ^Reouiivd word T h e e x a m p l e i n Figure 4.1 i s a s s o c i a t e d w i t h t h e c o n d i t i o n p o r t i o n i n t h e IF s t a t e m e n t . IF is u n d e r l i n e d a n d a p p e a r s in capital letters, i n d i c a t i n g it i s a r e q u i r e d r e s e r v e d w o r d . It is f o l l o w e d b y a set o f b r a c e s c o n t a i n i n g t h r e e o p t i o n s , o n e o f w h i c h m u s t b e c h o s e n . T h e r e s e r v e d w o r d IS a p p e a r s i n u p p e r c a s e letters b u t i s n o t u n d e r l i n e d , m e a n i n g its u s e is o p t i o n a l . T h e b r a c k e t s s u r r o u n d i n g N O T i m p l y that t h e c l a u s e i s o p t i o n a l , b u t if t h e c l a u s e is c h o s e n , N O T is r e q u i r e d b e c a u s e it is u n d e r l i n e d . T h e n e x t s e t o f b r a c e s i n d i c a t e s a s e c o n d m a n d a t o r y c h o i c e a m o n g five r e l a t i o n s h i p s : GREATER T H A N , GREATER T H A N OR EQUAL TO, LESS T H A N , LESS T H A N OR EQUAL TO, o r EQUAL TO. T h e r e s e r v e d w o r d s THAN a n d TO are n o t u n d e r l i n e d a n d are, therefore, o p t i o n a l . Alternatively, y o u c a n c h o o s e t h e a p p r o p r i a t e s y m b o l : >, >= <, <=, o r = i n s t e a d o f s p e l l i n g o u t t h e r e l a t i o n s h i p . T h e third s e t o f b r a c e s i n d i c a t e s y e t a n o t h e r c h o i c e , this t i m e f r o m t h e e n t r i e s i d e n t i f i e r - 2 , literal-2, and arithmetic expression-2. Returning t o t h e e n g i n e e r i n g s e n i o r p r o b l e m o f C h a p t e r 1, i n w h i c h S T U MAJOR is c o m p a r e d to e n g i n e e r i n g , w e s e e that all o f t h e f o l l o w i n g are a c c e p t a b l e as t h e c o n d i t i o n p o r t i o n o f t h e IF s t a t e m e n t : IF STU-MAJOR IS EQUAL TO 'ENGINEERING' IF STU-MAJOR EQUAL 'ENGINEERING' IF 'ENGINEERING' IS EQUAL TO STU-MAJOR IF STU-MAJOR = 'ENGINEERING' < ^C, ' , i , ^ T h e IDENTIFICATION D I V I S I O N is t h e first o f t h e four d i v i s i o n s i n a COBOL 11,11 p r o g r a m . Its f u n c t i o n is t o p r o v i d e i d e n t i f y i n g i n f o r m a t i o n a b o u t the p r o g r a m , s u c h U s '#tsl a s author, d a t e w r i t t e n , a n d security. T h e d i v i s i o n c o n s i s t s of a d i v i s i o n h e a d e r a n d u p t o six p a r a g r a p h s : IDENTIFICATION DIVISION. PROGRAM-ID. program-name. rAUTHOR. [comment-entry] ["INSTALLATION. [comment-entry] [DATE-WRITTEN. [comment-entry] rPATE-COMPILED. [comment-entry] fSECURITY. [comment-entry]
  • 85. C h a p t e r 4 The Identification, Environment, and Data Divisions T h e d i v i s i o n h e a d e r a n d PROGRAM-ID p a r a g r a p h are t h e o n l y r e q u i r e d e n t r i e s . T h e five r e m a i n i n g p a r a g r a p h s are o p t i o n a l (as i n d i c a t e d b y t h e C O B O L n o t a t i o n ) , a n d o n l y t h e D A T E - C O M P I L E D p a r a g r a p h m e r i t s s p e c i a l m e n t i o n . If t h e p a r a g r a p h is s p e c i f i e d , t h e c o m p i l e r will insert t h e c u r r e n t d a t e d u r i n g p r o g r a m c o m p