Chapter 2 Quiz: COBOL Program Structure
Test your understanding of COBOL's division structure, reference format, and program organization. Each question has one correct answer. Try to answer without referring back to the chapter, then check your answers using the hidden solution blocks.
Question 1. Which of the following is the correct order of COBOL divisions?
A) IDENTIFICATION, DATA, ENVIRONMENT, PROCEDURE B) IDENTIFICATION, ENVIRONMENT, DATA, PROCEDURE C) ENVIRONMENT, IDENTIFICATION, DATA, PROCEDURE D) IDENTIFICATION, PROCEDURE, DATA, ENVIRONMENT
Answer
**B) IDENTIFICATION, ENVIRONMENT, DATA, PROCEDURE** The four divisions must always appear in this exact order. A useful mnemonic: "I Enjoy Data Processing" (IDENTIFICATION, ENVIRONMENT, DATA, PROCEDURE).Question 2. Which is the ONLY required division in a COBOL program?
A) DATA DIVISION B) PROCEDURE DIVISION C) IDENTIFICATION DIVISION D) ENVIRONMENT DIVISION
Answer
**C) IDENTIFICATION DIVISION** The IDENTIFICATION DIVISION is the only required division. While virtually every useful program will also have a PROCEDURE DIVISION, technically it is not required by the language specification. The IDENTIFICATION DIVISION with its PROGRAM-ID paragraph is always mandatory.Question 3. In fixed-format COBOL, what is the purpose of column 7?
A) It marks the start of Area A B) It is the indicator area for comments, continuation, and debugging C) It is part of the sequence number area D) It marks the end of the identification area
Answer
**B) It is the indicator area for comments, continuation, and debugging** Column 7 is the indicator area. An asterisk (*) marks a comment line, a hyphen (-) marks a continuation line, and the letter D marks a debugging line.Question 4. Which columns define Area A in fixed-format COBOL?
A) Columns 1-6 B) Columns 7-11 C) Columns 8-11 D) Columns 12-72
Answer
**C) Columns 8-11** Area A spans columns 8 through 11. Division headers, section headers, paragraph names, and level numbers 01 and 77 must begin in Area A.Question 5. What character in column 7 indicates a debugging line?
A) *
B) -
C) D
D) #
Answer
**C) D** The letter D (or d) in column 7 marks a debugging line. These lines are compiled only when WITH DEBUGGING MODE is specified in the SOURCE-COMPUTER paragraph. Otherwise, they are treated as comments.Question 6. Which paragraph in the IDENTIFICATION DIVISION is required?
A) AUTHOR B) DATE-WRITTEN C) PROGRAM-ID D) SECURITY
Answer
**C) PROGRAM-ID** PROGRAM-ID is the only required paragraph in the IDENTIFICATION DIVISION. All other paragraphs (AUTHOR, INSTALLATION, DATE-WRITTEN, DATE-COMPILED, SECURITY) are optional and classified as obsolete in COBOL-2002 and later.Question 7. What does the IS INITIAL clause on a PROGRAM-ID do?
A) Makes the program run first in a batch job B) Returns the program to its initial state each time it is called C) Initializes all files automatically D) Makes the program the main entry point
Answer
**B) Returns the program to its initial state each time it is called** When IS INITIAL is specified, WORKING-STORAGE variables are re-initialized to their VALUE clauses each time the program is called. Without it, variables retain their values between calls.Question 8. Which SPECIAL-NAMES clause would you use to display numbers in European format (e.g., 1.234,56 instead of 1,234.56)?
A) CURRENCY SIGN IS "EUR"
B) DECIMAL-POINT IS COMMA
C) NUMERIC FORMAT IS EUROPEAN
D) COLLATING SEQUENCE IS EUROPEAN
Answer
**B) DECIMAL-POINT IS COMMA** The DECIMAL-POINT IS COMMA clause swaps the roles of the period and comma in numeric formatting and in PICTURE clauses, following the European convention.Question 9. In the FILE-CONTROL paragraph, what does the FILE STATUS clause do?
A) Opens the file automatically B) Stores a two-character status code after each file operation C) Determines whether the file is read-only or read-write D) Sets the file organization type
Answer
**B) Stores a two-character status code after each file operation** The FILE STATUS clause directs the runtime to store a two-character code in the specified variable after every file operation (OPEN, READ, WRITE, CLOSE, etc.). A value of "00" indicates success, "10" indicates end-of-file, and other codes indicate various errors.Question 10. Which file organization allows both sequential and random access when used with ACCESS MODE IS DYNAMIC?
A) SEQUENTIAL B) LINE SEQUENTIAL C) RELATIVE or INDEXED D) Any organization supports DYNAMIC access
Answer
**C) RELATIVE or INDEXED** ACCESS MODE IS DYNAMIC is only valid with RELATIVE or INDEXED file organization. It allows the program to switch between sequential and random access during execution. Sequential and line sequential organizations only support sequential access.Question 11. What is the key difference between WORKING-STORAGE and LOCAL-STORAGE?
A) WORKING-STORAGE is for files; LOCAL-STORAGE is for variables B) WORKING-STORAGE persists between calls; LOCAL-STORAGE re-initializes each call C) LOCAL-STORAGE is faster than WORKING-STORAGE D) WORKING-STORAGE is for the main program; LOCAL-STORAGE is for subprograms
Answer
**B) WORKING-STORAGE persists between calls; LOCAL-STORAGE re-initializes each call** When a program is called multiple times, WORKING-STORAGE items retain their values from the previous call. LOCAL-STORAGE items are re-initialized to their VALUE clauses at the start of each call. This distinction matters for programs used as subprograms.Question 12. Why are VALUE clauses (except for 88-levels) not allowed in the LINKAGE SECTION?
A) It is a compiler limitation B) LINKAGE SECTION items do not own their storage -- the calling program does C) VALUE clauses are obsolete in modern COBOL D) LINKAGE SECTION items are always numeric
Answer
**B) LINKAGE SECTION items do not own their storage -- the calling program does** LINKAGE SECTION items describe the layout of data passed from a calling program. Since the storage belongs to the caller, it would be meaningless to initialize it with VALUE clauses in the called program. The exception for 88-level items is because those are condition names (logical tests), not data storage.Question 13. What does the following code display when WS-VALUE is 3?
IF WS-VALUE > 0
DISPLAY "A".
DISPLAY "B"
.
A) A B) A and B C) A and B (both always displayed) D) Compiler error
Answer
**C) A and B (both always displayed)** The period after `DISPLAY "A"` terminates the IF statement. The `DISPLAY "B"` is outside the IF block and executes unconditionally. When WS-VALUE is 3, "A" displays because the condition is true, and "B" displays regardless. If WS-VALUE were -1, only "B" would display.Question 14. Which level number is used for condition names (Boolean-like values)?
A) 66 B) 77 C) 88 D) 99
Answer
**C) 88** Level 88 defines condition names. They associate meaningful names with specific values of the parent data item. For example: `88 END-OF-FILE VALUE 'Y'.` Level 66 is for RENAMES, and 77 is for independent elementary items.Question 15. In which area must the FD entry begin?
A) Area A (columns 8-11) B) Area B (columns 12-72) C) Either Area A or Area B D) Column 1
Answer
**A) Area A (columns 8-11)** FD (File Description) and SD (Sort Description) entries are level indicators and must begin in Area A, just like 01-level and 77-level items.Question 16. What is the standard file status code for "end of file"?
A) "00" B) "10" C) "23" D) "99"
Answer
**B) "10"** File status "10" indicates that a READ operation reached the end of the file. "00" is successful completion, "23" is record not found (indexed files), and "99" is not a standard file status code.Question 17. In free-format COBOL, how do you indicate a comment?
A) * in column 7
B) // at the start of the line
C) *> anywhere on the line
D) -- at the start of the line
Answer
**C) `*>` anywhere on the line** In free-format COBOL, comments begin with `*>` and can appear anywhere on a line, including as inline comments after code. This replaces the fixed-format convention of `*` in column 7.Question 18. What happens to code written beyond column 72 in fixed-format COBOL?
A) It causes a compiler error B) It wraps to the next line C) It is silently ignored (treated as identification area) D) It is treated as a comment
Answer
**C) It is silently ignored (treated as identification area)** Columns 73-80 are the identification area and are ignored by the compiler. Any code that extends past column 72 is silently discarded, which can cause extremely subtle bugs.Question 19. Which of the following is a valid COBOL data name?
A) TOTAL-AMOUNT
B) -BALANCE
C) AMOUNT-
D) MOVE
Answer
**A) TOTAL-AMOUNT** COBOL data names must begin with a letter or digit, cannot end with a hyphen, and cannot be reserved words. `-BALANCE` starts with a hyphen, `AMOUNT-` ends with a hyphen, and `MOVE` is a reserved word.Question 20. What does PERFORM 2000-PROCESS UNTIL END-OF-FILE do?
A) Executes 2000-PROCESS once, then checks END-OF-FILE B) Checks END-OF-FILE first, then executes 2000-PROCESS if false C) Executes 2000-PROCESS until the file is physically deleted D) Executes 2000-PROCESS exactly once
Answer
**B) Checks END-OF-FILE first, then executes 2000-PROCESS if false** The standard PERFORM UNTIL tests the condition BEFORE each execution. If END-OF-FILE is already true when the PERFORM is first reached, the paragraph is never executed. This is called a "test before" loop. To get "test after" behavior, you would use PERFORM WITH TEST AFTER.Question 21. What does the REDEFINES clause do?
A) Renames a data item B) Creates two different views of the same storage location C) Copies a data definition from another program D) Changes the data type of an item at runtime
Answer
**B) Creates two different views of the same storage location** REDEFINES allows two or more data descriptions to share the same physical storage. This is useful for interpreting the same bytes in different ways, such as viewing a date as either a single 8-digit number or as separate year, month, and day fields.Question 22. In the numeric paragraph naming convention, what range is typically reserved for error handling?
A) 0000-0999 B) 2000-2999 C) 8000-8999 D) 9000-9999
Answer
**D) 9000-9999** The conventional ranges are: 0000-0999 for main control, 1000-1999 for initialization, 2000-2999 for main processing, 3000-3999 for output, 4000-4999 for finalization, 8000-8999 for utility routines, and 9000-9999 for error handling.Question 23. Which compiler directive enables free-format source in GnuCOBOL?
A) >>SOURCE FORMAT IS FREE
B) $SET SOURCEFORMAT"FREE"
C) PROCESS FREE
D) All of the above
Answer
**A) `>>SOURCE FORMAT IS FREE`** For GnuCOBOL, the source directive `>>SOURCE FORMAT IS FREE` enables free format. You can also use the `-free` command-line flag. Option B is for Micro Focus, and option C is for IBM Enterprise COBOL.Question 24. Which scope terminator closes a READ statement?
A) END-READ B) END-FILE C) END-INPUT D) READ does not have a scope terminator
Answer
**A) END-READ** END-READ explicitly terminates a READ statement, particularly when using AT END and NOT AT END clauses. Using END-READ is a best practice that eliminates ambiguity about where the READ statement ends.Question 25. When you PERFORM a SECTION, what happens?
A) Only the first paragraph in the section executes B) All paragraphs in the section execute from beginning to end C) You must specify which paragraph within the section to execute D) Sections cannot be PERFORMed, only paragraphs can
Answer
**B) All paragraphs in the section execute from beginning to end** When you PERFORM a section, execution begins at the first paragraph and continues through all paragraphs until the end of the section is reached (typically the EXIT paragraph). This is different from performing a single paragraph, which executes only that paragraph.Question 26. What is the maximum line length in free-format COBOL?
A) 72 characters B) 80 characters C) 132 characters D) 255 characters (compiler-dependent)
Answer
**D) 255 characters (compiler-dependent)** Free-format COBOL allows lines up to 255 characters, though the exact maximum may vary by compiler. This is significantly longer than the 72-character effective limit of fixed format (columns 8-72).Question 27. What does the EXIT statement do?
A) Terminates the program B) Provides a common end point for a section or paragraph; it does nothing C) Returns to the calling program D) Exits a loop
Answer
**B) Provides a common end point for a section or paragraph; it does nothing** The EXIT statement is a no-operation statement. It is conventionally placed in an exit paragraph at the end of a section to provide a clear, defined endpoint. It does not terminate the program (that is STOP RUN) or return to a caller (that is GOBACK).Question 28. Which of the following must start in Area A in fixed-format COBOL?
A) DISPLAY "HELLO"
B) 05 WS-NAME PIC X(20).
C) 01 WS-RECORD.
D) MOVE 5 TO WS-COUNT
Answer
**C) `01 WS-RECORD.`** Level 01 items must begin in Area A (columns 8-11). DISPLAY and MOVE are statements that belong in Area B. Level 05 items also belong in Area B. Only level 01, level 77, FD, SD, division headers, section headers, and paragraph names start in Area A.Question 29. What is the purpose of the I-O-CONTROL paragraph?
A) Controls input validation B) Specifies checkpoint/restart and shared buffer areas C) Defines the I/O access mode for files D) Controls screen I/O formatting
Answer
**B) Specifies checkpoint/restart and shared buffer areas** The I-O-CONTROL paragraph is used for special I/O techniques such as SAME RECORD AREA (shared buffers) and RERUN (checkpoint/restart). It is part of the INPUT-OUTPUT SECTION and is rarely used in modern programs.Question 30. A COBOL program has this structure. What is wrong?
IDENTIFICATION DIVISION.
PROGRAM-ID. TEST-PROG.
DATA DIVISION.
WORKING-STORAGE SECTION.
01 WS-NUM PIC 9(5).
FILE SECTION.
FD MY-FILE RECORD CONTAINS 80 CHARACTERS.
01 MY-RECORD PIC X(80).
A) Nothing is wrong B) FILE SECTION must come before WORKING-STORAGE SECTION C) The ENVIRONMENT DIVISION is missing D) FD should be in WORKING-STORAGE
Answer
**B) FILE SECTION must come before WORKING-STORAGE SECTION** Within the DATA DIVISION, sections must appear in a specific order: FILE SECTION, WORKING-STORAGE SECTION, LOCAL-STORAGE SECTION, LINKAGE SECTION. The FILE SECTION must always precede WORKING-STORAGE SECTION. Additionally, a FILE SECTION with an FD entry requires a corresponding SELECT in the ENVIRONMENT DIVISION's FILE-CONTROL paragraph.Scoring Guide
| Score | Assessment |
|---|---|
| 27-30 | Excellent -- ready to move on to Chapter 3 |
| 23-26 | Good -- review the topics you missed |
| 18-22 | Fair -- reread the relevant sections before proceeding |
| Below 18 | Review the entire chapter and reattempt the quiz |