Notice that the answers tell you WHAT happened, but not always WHY! 

Eventually, you will need to know the WHY!

 

What happens if you:

1.      capitalize IDENTIFICATION DIVISION? Nothing… cobol is not case sensitive

2.      delete the period after identification division? Compiler error… line2: Warning: ‘.’ expected, PROGRAM-ID found

3.      put an * in column 7 on the first statement (identification division)? Nothing… weird, huh?!

4.      change the program-id from prelab to sample?  Nothing… Remember that the program-id does not have to match the file name.  I’ll point out in a later question where this is used.

5.      put the program-id name, prelab. (don’t forget to include the period) on the next line starting in column 10?  Nothing…

6.      put the program-id name, prelab. (don’t forget to include the period) on the next line starting in column 12?  Nothing…

7.      move data division to start in column 11?  Nothing…

8.      move data division to start in column 12?  Compiler error… line12: Warning: Must start in Area A

9.      delete the period on the line before the data division i.e. after the second organization is line sequential?  Compiler error… line 12: warning:  Area A should be blank, line 12: numeric literal expected, DIVISION found, line 14: syntax error

10.  comment out the 3 statements environment division, input-output section and file-control by putting an * in column 7 of each statement?  Nothing… weird, huh?!

11.  comment out the file section statement?  6 compiler errors with the 7th one saying “Can’t recover, good bye!”

NOTE:  Delete the * on the accept omitted statement (before the stop run statement) for the next question only.

12.  in the file section, change the pic x(20) on 05 employee-name-in to pic x(18)? Run error occurs 5 times… non-numeric data in numeric field at 000083 in PRELAB.  The 000083 is a memory location which will probably change each time the program is run.  The value is a hex value (binary = base 2, octal = base 8, decimal = base 10, hexadecimal = base 16). The PRELAB is the program-id variable name!  The change also causes not just a run error, but a logic error as well!  Notice that the output file has incorrect data…

13.  change the 77 level number in the working-storage section to an 01 level number?  nothing

14.  change the non-numeric literal on the value clause for the are-there-more-records variable to “no”?  a logic error occurs where in the output file, the page and column headers as well as the underline appear, but no data

15.  in the file section, put a $ in front of the 9.99 on the pic clause for rate-out (i.e. pic $9.99)?  a $ appears on the data under the $/hr column; notice the earnings data was moved over one position

16.  delete the period on the weekly-wages-out pic clause (i.e. pic 99999 instead of 999.99)?  in the output file, leading zeroes and no decimal values appear on the data

17.  delete the period before the working-storage section statement?  Compiler errors… line 30: Warning: Area A should be blank; line 30: syntax error scanning WORKING-STORAGE; line 31: illegal level number

18.  in the file section, change the variable name hours-worked-in to hrs-wrk-in?  compiler error - line 65: undefined data item:  HOURS-WORKED-IN.  Notice error on use of variable name, not declaration.

19.  in the file section, change the variable name weekly-wages-out to wkly-wgs-out?  Compiler error - Line 69: same as above with WEEKLY-WAGES-OUT

20.  change the variable name employee-data on the read statement to employee-record? Compiler error - Line 55 or 71:  no SELECT for file: EMPLOYEE-RECORD

21.  change the variable name hours-out in 200-wage-routine paragraph to hrs-out? Compiler error – line 66: undefined data item:  HRS-OUT

22.  change 05 levels on employee-record in the file section to 01 levels? Compiler error – line 17: warning: must start in Area A, line 17: warning: no space in item: EMPLOYEE –RECORD i.e. no pic clause; same two errors for line 18

23.  change the double quotes to single quotes on the select statement? nothing

24.  change the double quotes to single quotes for all the “no” non-numeric literals? nothing

25.  change “no” to “NO” on the perform statement (in paragraph 100-main-module)? Run error… box hard to see… press enter, maximize the window, and re-run the program.  File error 46 on prelabin.dat. COBOL error at 00008C in prelab <OK>.  Also, notice the output file has extra/duplicate last data line.  Why is this an error?!  Because non-numeric literal are case sensitive!!! i.e. “no” is not the same as “NO”.

26.  comment out the 100-main-module paragraph name? compiler error line 46: identifier expected, OPEN found; line 46: missing PARA/SECTION; line 46: Can’t recover, good-bye!

27.  comment out the 1st line in the 100-main-module paragraph (open input employee-data)? Compiler error – line 47: verb expected, OUTPUT found.  What if comment out the entire OPEN statement i.e. open line and next line as well?!  You get a run error… box says file error 48.02 on prelabout.dat.  COBOL error at 000010 in prelab <OK>.

28.  delete all the periods under the 100-main-module paragraph? Compiler error – line 62: warning: missing period.

29.  delete all the periods under the 100-main-module paragraph except on the stop run statement? Logic error!  Output file has up to the first data line under page and column headers with underline.

30.  correct the change you made to the above question and forget to save before recompiling? You get the same error since prelab.cob was not actually updated; just the screen version was updated, not the stored version.

31.  change the line before the read statement to after advancing 0 lines (instead of 1 lines)? It looks like the column headers are deleted.  Actually, this underlines the column headers but since the screen cannot put two characters in one location/space, the dashes overwrote the column header info.  If you print the output, you will see the underlined column headers without advancing the print head one line (to be discussed in more detail when talk about the WRITE statement).

32.  change the line before the read statement to after advancing 1 line (deleting the s off the word lines)? nothing

33.  comment out the close statement? nothing

34.  put employee-data on the close statement on a different line, starting column 12 or after? nothing

35.  comment out the stop run statement? Same as #27!  Why?!  Because without a stop run, the program continues to run statements in sequential order including over the paragraph name and to the first statement in the paragraph, etc. and you can’t write to a file that you have already closed!

 

Other:

36.  Notice that the 3rd line and the 11th line are blank; there is no * in the 7th column to denote a comment.  Why is this okay?!  COBOL ignores “white space”!

37.  Notice that the non-numeric literal “Employee Name” has a length of 13, but the pic clause has a length of 23.  Why is this okay? Because the data is stored to the left so allows for open positions to the right.

38.  Notice that there are no variable names on the 05 levels under both page-header and column-headers.  Why is this okay?  Because I don’t need to access those memory locations

39.  List the first 20 statements executed by the program.  Open, write, write, write, read, perform, move, move, move, move, multiply, write, read, perform, move, move, move, move, multiply, write

40.  Delete the * on the accept omitted statement.  Add the following display statement between the first read statement and the perform statement.  Also add the following display statement at the end of the 2nd paragraph (i.e. the last sequential statement for the program).  What output do you see on the screen?  Employee record is (data line information for each record) except the last (i.e.5th) record is repeated, so there are 6 output lines to the screen

What happens if you delete the period after the second read statement?  Only two lines of output appear; one for the first record, one for the last record.

           

                        display “employee-record is “ employee-record.