Chapter 4 Quiz: The WORKING-STORAGE and LOCAL-STORAGE Sections
Test your understanding of WORKING-STORAGE, LOCAL-STORAGE, level numbers, INITIALIZE, REDEFINES, and 88-level condition names. Each question has one correct answer unless otherwise stated. Try to answer before revealing the solution.
Question 1
What is the primary difference between WORKING-STORAGE and LOCAL-STORAGE in a called subprogram?
A) WORKING-STORAGE can hold numeric fields; LOCAL-STORAGE cannot B) WORKING-STORAGE values persist between calls; LOCAL-STORAGE values reset on each call C) LOCAL-STORAGE is only available in COBOL 85 D) There is no difference; they are synonyms
Answer
**B) WORKING-STORAGE values persist between calls; LOCAL-STORAGE values reset on each call.** WORKING-STORAGE is initialized once when the program is first loaded. Its values persist across subsequent calls to the subprogram. LOCAL-STORAGE fields are re-initialized to their VALUE clauses on every invocation of the program, making them ideal for work fields in recursive or reentrant programs.Question 2
Which level number is used for condition names that do not allocate storage?
A) 66 B) 77 C) 88 D) 01
Answer
**C) 88** Level 88 items define condition names -- meaningful names for specific values of a data item. They do not allocate any storage themselves; they simply associate a name with one or more values of their parent (conditional variable) item.Question 3
What does the INITIALIZE statement do to an alphanumeric field?
A) Sets it to ZEROS B) Sets it to SPACES C) Sets it to LOW-VALUES D) Leaves it unchanged
Answer
**B) Sets it to SPACES** The basic INITIALIZE statement sets alphanumeric (PIC X) fields to SPACES and numeric (PIC 9) fields to ZEROS. This type-aware behavior is what makes INITIALIZE safer than MOVE SPACES or MOVE ZEROS for mixed-type records.Question 4
What is wrong with this REDEFINES?
05 WS-CODE PIC X(05).
01 WS-CODE-R REDEFINES WS-CODE PIC X(05).
A) The REDEFINES item is larger than the original B) The REDEFINES item must have the same level number as the original C) You cannot REDEFINES an alphanumeric field D) The names are too similar
Answer
**B) The REDEFINES item must have the same level number as the original.** `WS-CODE` is a level-05 item, but `WS-CODE-R` is a level-01 item. The REDEFINES clause requires both items to have the same level number. The correct definition would be `05 WS-CODE-R REDEFINES WS-CODE PIC X(05).`Question 5
In the following definition, what value does WS-MONTH contain after MOVE 20240315 TO WS-DATE-FULL?
01 WS-DATE-FULL PIC 9(08).
01 WS-DATE-PARTS REDEFINES WS-DATE-FULL.
05 WS-YEAR PIC 9(04).
05 WS-MONTH PIC 9(02).
05 WS-DAY PIC 9(02).
A) 20 B) 03 C) 15 D) 24
Answer
**B) 03** The REDEFINES makes `WS-DATE-PARTS` overlay the same storage as `WS-DATE-FULL`. When 20240315 is stored, the first 4 bytes (positions 1-4) are 2024 (WS-YEAR), the next 2 bytes (positions 5-6) are 03 (WS-MONTH), and the last 2 bytes (positions 7-8) are 15 (WS-DAY).Question 6
Which of the following is NOT a valid use of the FILLER keyword?
A) Spacing between fields in a print line B) Labels in a report header line C) Padding a record to a required length D) Referencing the item by name in PROCEDURE DIVISION
Answer
**D) Referencing the item by name in PROCEDURE DIVISION** FILLER items cannot be referenced by name in the PROCEDURE DIVISION -- that is the entire point of FILLER. They exist to occupy space in a record structure without being individually addressable. FILLER is used for spacing (A), labels (B), and padding (C).Question 7
What does SET WS-ACTIVE TO TRUE do if WS-ACTIVE is defined as 88 WS-ACTIVE VALUE 'A' under 01 WS-STATUS PIC X(01)?
A) Sets WS-ACTIVE to TRUE B) Sets WS-STATUS to 'A' C) Sets WS-STATUS to TRUE D) Causes a compilation error
Answer
**B) Sets WS-STATUS to 'A'** `SET condition-name TO TRUE` moves the VALUE associated with the condition name into the conditional variable. Since `WS-ACTIVE` has `VALUE 'A'`, the SET statement moves 'A' into `WS-STATUS`, making the condition `WS-ACTIVE` true.Question 8
What is the purpose of level-66 items?
A) Define independent elementary items B) Define condition names for values C) Create alternative groupings of existing data items using RENAMES D) Define table/array items
Answer
**C) Create alternative groupings of existing data items using RENAMES** Level 66 with the RENAMES clause creates an alternative name for a contiguous range of data items within a record, without allocating additional storage. It allows you to group non-adjacent conceptual fields under a single name. Level 66 items must appear immediately after the record they reference.Question 9
How does INITIALIZE treat FILLER items by default?
A) Sets them to SPACES B) Sets them to ZEROS C) Leaves them unchanged D) Deletes them from memory
Answer
**C) Leaves them unchanged** By default, INITIALIZE does not modify FILLER items. This is usually the desired behavior because FILLER items often have VALUE clauses that define static content like spacing or labels. To also initialize FILLER items, use `INITIALIZE ... WITH FILLER` or `INITIALIZE ... ALL TO VALUE`.Question 10
Which of the following 88-level definitions uses a range correctly?
A) 88 WS-VALID VALUE 'A' THROUGH 'Z' '0' THROUGH '9'.
B) 88 WS-VALID VALUE 'Z' THRU 'A'.
C) 88 WS-VALID VALUE 1 THROUGH.
D) 88 WS-VALID VALUE THRU 100.
Answer
**A) `88 WS-VALID VALUE 'A' THROUGH 'Z' '0' THROUGH '9'.`** This correctly defines a condition that is true when the field contains any uppercase letter or any digit. Multiple ranges can be combined. Option B has the range reversed (though some compilers may accept it, it is poor practice). Options C and D have incomplete range specifications.Question 11
What happens when you execute MOVE SPACES TO WS-RECORD where WS-RECORD is a group item containing both alphanumeric and numeric subordinate fields?
A) Alphanumeric fields get spaces; numeric fields get zeros B) All fields get the space character, including numeric fields C) The compiler rejects this statement D) Only the alphanumeric fields are affected
Answer
**B) All fields get the space character, including numeric fields** When you MOVE to a group item, the group is treated as alphanumeric regardless of its subordinate items' data types. Every byte in the group receives the space character. This means numeric fields now contain spaces -- attempting arithmetic on them will cause a runtime error (S0C7 on mainframes). This is why INITIALIZE is preferred for mixed-type records.Question 12
In what order should WORKING-STORAGE items be organized according to industry best practices?
A) Alphabetical order by data name B) By level number (01 first, then 05, etc.) C) Constants, flags, counters, work fields, record layouts, display fields D) In the order they are used in the PROCEDURE DIVISION
Answer
**C) Constants, flags, counters, work fields, record layouts, display fields** The recommended organizational convention places constants first (they set the program's context), followed by flags/switches (they control flow), counters/accumulators, work fields, input/output record layouts, and finally display/report formatting fields. This logical grouping makes the WORKING-STORAGE section easy to navigate.Question 13
What is the size in bytes of a group item that contains these subordinates?
01 WS-GROUP.
05 WS-A PIC X(10).
05 WS-B PIC 9(05)V99.
05 WS-C PIC X(03).
A) 15 bytes B) 18 bytes C) 20 bytes D) 22 bytes
Answer
**C) 20 bytes** WS-A is PIC X(10) = 10 bytes. WS-B is PIC 9(05)V99 = 7 bytes (5 digits before the implied decimal + 2 digits after; the V does not occupy storage). WS-C is PIC X(03) = 3 bytes. Total: 10 + 7 + 3 = 20 bytes. The implied decimal point (V) does not take up a byte in storage.Question 14
Level 77 items are functionally equivalent to which of the following?
A) Level-01 group items B) Level-01 elementary items C) Level-88 condition names D) Level-05 subordinate items
Answer
**B) Level-01 elementary items** A level-77 item is an independent elementary item -- it has a PIC clause and cannot be subdivided or contain subordinate items. This is functionally identical to a level-01 item with a PIC clause and no subordinates. The difference is purely conventional: 77 signals "this is standalone" more explicitly.Question 15
What does INITIALIZE WS-RECORD REPLACING NUMERIC DATA BY 9 do to a PIC 9(05) field?
A) Sets it to 00009 B) Sets it to 99999 C) Sets it to 9 D) Causes a compilation error
Answer
**B) Sets it to 99999** INITIALIZE REPLACING sets every numeric field to the specified value. When the replacement value is 9, each digit position in the numeric field is filled with 9. A PIC 9(05) field has five digit positions, so it becomes 99999.Question 16
Which of the following statements about REDEFINES is FALSE?
A) The REDEFINES item must immediately follow the item it redefines B) The REDEFINES item must have the same level number as the redefined item C) You can REDEFINES a level-88 condition name D) Multiple items can REDEFINES the same original item
Answer
**C) You can REDEFINES a level-88 condition name** You cannot use REDEFINES with level-66, level-77, or level-88 items. Level-88 condition names do not allocate storage, so there is nothing to redefine. The other statements are all true: REDEFINES must follow immediately (A), have the same level (B), and multiple REDEFINES of the same item are allowed (D).Question 17
When should you use LOCAL-STORAGE instead of WORKING-STORAGE?
A) When you need fields to persist between calls to a subprogram B) When the subprogram is recursive or reentrant and needs fresh values each call C) When defining constants that never change D) When defining file record layouts
Answer
**B) When the subprogram is recursive or reentrant and needs fresh values each call** LOCAL-STORAGE is specifically designed for situations where work fields must be re-initialized on every invocation. This is critical for recursive programs (where the same program calls itself) and reentrant programs (where multiple threads may execute the same program simultaneously). Each invocation gets a fresh set of LOCAL-STORAGE values.Question 18
What is the VALUE/REDEFINES pattern used for with tables?
A) Validating table entries at runtime B) Pre-loading table data at compile time, then accessing it via subscripts C) Sorting table entries D) Dynamically resizing tables
Answer
**B) Pre-loading table data at compile time, then accessing it via subscripts** The VALUE/REDEFINES pattern defines a series of FILLER items with VALUE clauses containing the table data, then overlays this with a REDEFINES containing an OCCURS clause. This allows you to initialize a lookup table at compile time without needing runtime initialization code. For example, month names can be defined as 12 FILLER PIC X(09) VALUE items, then redefined as an OCCURS 12 TIMES table.Question 19
Given this definition, which condition is TRUE when WS-SCORE contains 725?
01 WS-SCORE PIC 9(03).
88 WS-SCORE-LOW VALUE 0 THRU 399.
88 WS-SCORE-MED VALUE 400 THRU 699.
88 WS-SCORE-HIGH VALUE 700 THRU 850.
88 WS-SCORE-VALID VALUE 0 THRU 850.
A) Only WS-SCORE-HIGH B) Only WS-SCORE-VALID C) Both WS-SCORE-HIGH and WS-SCORE-VALID D) WS-SCORE-MED, WS-SCORE-HIGH, and WS-SCORE-VALID
Answer
**C) Both WS-SCORE-HIGH and WS-SCORE-VALID** 725 falls within the range 700 THRU 850 (WS-SCORE-HIGH is TRUE) and also within the range 0 THRU 850 (WS-SCORE-VALID is TRUE). Multiple 88-level conditions on the same field can be true simultaneously if the current value satisfies multiple condition definitions. WS-SCORE-MED (400-699) is false because 725 is outside that range.Question 20
What is the conventional prefix for a WORKING-STORAGE counter field?
A) WS-F- B) WS-C- C) WS-CTR- D) WS-ACC-
Answer
**C) WS-CTR-** The conventional prefixes are: WS-C- for constants, WS-F- for flags/switches, WS-CTR- for counters, WS-ACC- for accumulators, WS-WK- for work fields, and WS-DSP- for display fields. These prefixes make the purpose of each field immediately apparent.Question 21
What happens if you define a REDEFINES item that is larger than the original item?
A) The compiler automatically pads the original item B) It is always a compilation error in all compilers C) Some compilers allow it with a warning, but it can corrupt adjacent data D) The extra bytes are safely allocated in a separate area
Answer
**C) Some compilers allow it with a warning, but it can corrupt adjacent data** Standard COBOL requires that the REDEFINES item be the same size as or smaller than the original. However, some compilers (like GnuCOBOL) will compile a larger REDEFINES with a warning. Using such a REDEFINES is dangerous because writing to the extended portion overwrites adjacent data items. This is a classic source of production bugs.Question 22
What is the maximum nesting depth for subordinate level numbers (02-49)?
A) 7 levels B) 15 levels C) 48 levels (from 02 to 49) D) There is no specific limit other than the range 02-49
Answer
**C) 48 levels (from 02 to 49)** Since subordinate items can use level numbers from 02 through 49, and each nested level only needs to be higher than its parent, you can theoretically nest up to 48 levels deep (02, 03, 04, ..., 49). In practice, however, data structures rarely exceed 4-5 levels of nesting. Using the 05/10/15 convention limits practical nesting to about 9 levels (05, 10, 15, 20, 25, 30, 35, 40, 45), which is still far more than typically needed.Question 23
Which statement correctly makes the condition WS-MARRIED true?
01 WS-STATUS PIC X(01).
88 WS-SINGLE VALUE 'S'.
88 WS-MARRIED VALUE 'M'.
A) MOVE TRUE TO WS-MARRIED
B) SET WS-MARRIED TO TRUE
C) SET WS-STATUS TO 'M'
D) MOVE 'M' TO WS-MARRIED
Answer
**B) `SET WS-MARRIED TO TRUE`** The SET statement with condition names is the proper way to make a condition true. `SET WS-MARRIED TO TRUE` moves the VALUE associated with WS-MARRIED ('M') into the conditional variable WS-STATUS. Option A is invalid syntax. Option C is invalid because SET is not used with literal values for non-index items this way. Option D is invalid because you cannot MOVE to an 88-level item directly.Question 24
What does the SYNCHRONIZED (SYNC) clause do?
A) Ensures two fields always contain the same value B) Aligns binary or packed-decimal items on word boundaries for performance C) Synchronizes WORKING-STORAGE across multiple threads D) Forces sequential access to a field
Answer
**B) Aligns binary or packed-decimal items on word boundaries for performance** SYNCHRONIZED requests that the compiler align a data item on a hardware-specific boundary (halfword, fullword, or doubleword). This can improve performance for binary (COMP) items on mainframes by avoiding cross-boundary access. However, it adds slack bytes (padding) that change the record's physical size. It is most relevant on IBM mainframes and rarely needed on distributed platforms.Question 25
In a called subprogram without the INITIAL attribute, when is WORKING-STORAGE initialized?
A) Every time the subprogram is called B) Only on the first call (first load of the program) C) Only when explicitly initialized with the INITIALIZE statement D) It is never automatically initialized
Answer
**B) Only on the first call (first load of the program)** WORKING-STORAGE VALUE clauses are applied when the program is first loaded into memory. On subsequent calls, the values remain as they were left by the previous call. This is why counters and accumulators in WORKING-STORAGE accumulate across calls. If you need fresh values on each call, use LOCAL-STORAGE or add explicit INITIALIZE statements.Question 26
How many bytes does the implied decimal point (V) occupy in storage?
A) 1 byte B) 2 bytes C) 0 bytes -- it is positional only D) It depends on the USAGE clause
Answer
**C) 0 bytes -- it is positional only** The V in a PICTURE clause marks the position of an implied decimal point but does not occupy any storage. A field defined as PIC 9(05)V99 occupies 7 bytes (5 + 2), not 8. The compiler tracks the decimal position internally for arithmetic operations. Only an actual decimal point (.) in an edited field occupies a byte.Question 27
What is the maximum length for a COBOL data name in COBOL-85?
A) 8 characters B) 15 characters C) 30 characters D) 60 characters
Answer
**C) 30 characters** COBOL-85 allows data names up to 30 characters long. COBOL 2014 extended this to 60 characters. Data names must contain at least one letter, can include letters, digits, and hyphens, and cannot begin or end with a hyphen.Question 28
Given the following code, what is the value of WS-FULL-RECORD after the INITIALIZE?
01 WS-FULL-RECORD.
05 WS-NAME PIC X(10) VALUE 'JOHN'.
05 WS-AGE PIC 9(03) VALUE 25.
05 WS-CODE PIC X(02) VALUE 'AB'.
A) 'JOHN 025AB'
B) ' 000 '
C) 'JOHN 025AB' (unchanged from VALUE clauses)
D) SPACES throughout
Answer
**B) `' 000 '`** INITIALIZE sets alphanumeric fields to SPACES and numeric fields to ZEROS, overriding any existing values or VALUE clauses. After `INITIALIZE WS-FULL-RECORD`: WS-NAME becomes 10 spaces, WS-AGE becomes 000, and WS-CODE becomes 2 spaces. The original VALUE clause values are not restored. To restore VALUE clauses, use `INITIALIZE ... ALL TO VALUE`.Question 29
Which of the following is a valid figurative constant in COBOL? (Select all that apply)
A) SPACES B) NULLS C) HIGH-VALUES D) ALL '*' E) EMPTY
Answer
**A) SPACES, C) HIGH-VALUES, D) ALL '*'** SPACES (or SPACE), HIGH-VALUES (or HIGH-VALUE), and ALL literal are valid COBOL figurative constants. Other valid figurative constants include ZEROS/ZEROES/ZERO, LOW-VALUES/LOW-VALUE, and QUOTES/QUOTE. NULLS is valid in some COBOL dialects (representing null pointers), but EMPTY is not a COBOL figurative constant.Question 30
Why is it recommended to use 05/10/15 for level numbers instead of consecutive numbers like 02/03/04?
A) The compiler processes them faster B) It leaves room to insert new hierarchy levels without renumbering C) Consecutive numbers are invalid in COBOL D) It uses less memory
Answer
**B) It leaves room to insert new hierarchy levels without renumbering** Using level numbers with gaps (05, 10, 15, 20...) allows you to add new intermediate grouping levels between existing ones without changing the level numbers of the existing items. For example, if you need to add a group level between 10 and 15, you can use level 12. With consecutive numbers, adding a level between 03 and 04 would require renumbering all subsequent levels.Scoring Guide
| Score | Rating |
|---|---|
| 28-30 | Expert -- You have mastered WORKING-STORAGE concepts |
| 24-27 | Advanced -- Strong understanding with minor gaps |
| 20-23 | Proficient -- Solid foundation; review the areas you missed |
| 15-19 | Developing -- Re-read the chapter sections for missed topics |
| Below 15 | Beginning -- Study the chapter thoroughly before proceeding |