Exercises — Chapter 4: Data Description Mastery

Exercise 4.1: PICTURE Clause Identification

For each of the following PIC clauses, state: (a) the data type (numeric, alphanumeric, or edited), (b) the number of storage bytes in DISPLAY usage, and (c) the range or capacity of values.

  1. PIC 9(7)V99
  2. PIC S9(5)
  3. PIC X(30)
  4. PIC ZZZ,ZZ9.99
  5. PIC $$$,$$9.99CR
  6. PIC 9(3)PP
  7. PIC PPP9(3)
  8. PIC A(15)
  9. PIC +(6)9.99
  10. PIC **,**9.99

Exercise 4.2: Edited Picture Output Prediction

Given the following declarations and a source value of WS-SOURCE PIC S9(7)V99 COMP-3, predict the exact output (including spacing) for each target field. Do this for both WS-SOURCE = +1234.56 and WS-SOURCE = -0007.80.

       01  WS-EDIT-A       PIC ZZZ,ZZ9.99.
       01  WS-EDIT-B       PIC $$$,$$$,$$9.99.
       01  WS-EDIT-C       PIC ----,--9.99.
       01  WS-EDIT-D       PIC ***,**9.99.
       01  WS-EDIT-E       PIC ZZZ,ZZ9.99CR.
       01  WS-EDIT-F       PIC $ZZZ,ZZ9.99-.

Exercise 4.3: USAGE Storage Calculation

Calculate the storage (in bytes) for each of the following declarations. Show your work.

  1. PIC S9(7)V99 USAGE DISPLAY
  2. PIC S9(7)V99 USAGE COMP-3
  3. PIC 9(4) USAGE COMP
  4. PIC 9(9) USAGE COMP
  5. PIC 9(18) USAGE COMP
  6. PIC S9(13)V99 USAGE COMP-3
  7. PIC S9(5)V99 SIGN IS LEADING SEPARATE CHARACTER
  8. PIC S9(7)V99 USAGE COMP-3 (an array of 12 using OCCURS)

Exercise 4.4: Condition Name Design

Design complete 88-level condition names for the following business scenarios. Include a "valid" condition that encompasses all legal values.

  1. Payment method: Cash (C), Check (K), Credit Card (CC), Debit Card (DC), Wire Transfer (WT), ACH (AC)
  2. Employee status: Active (A), On Leave (L), Suspended (S), Terminated (T), Retired (R)
  3. Temperature range (Fahrenheit, PIC S9(3)): Extreme Cold (-99 to -1), Freezing (0 to 31), Cold (32 to 49), Cool (50 to 64), Comfortable (65 to 78), Warm (79 to 89), Hot (90 to 109), Extreme Heat (110 to 999)
  4. HTTP status code (PIC 9(3)): Success codes (200-299), Redirect codes (300-399), Client Error codes (400-499), Server Error codes (500-599)

Exercise 4.5: REDEFINES Design

Write a complete 01-level record layout for a financial transaction file that contains three types of transactions. The common header should include: transaction ID, date, amount, and a two-character type code. The three types are:

  • Deposit (DP): Source (cash/check/wire), reference number, teller ID
  • Withdrawal (WD): Destination (cash/ATM/wire), ATM ID (if ATM), authorization code
  • Transfer (TR): From-account, to-account, transfer type (internal/external), routing number (if external)

Use REDEFINES for the type-specific detail area. Include 88-levels for all coded fields. Choose appropriate USAGE for each field.

Exercise 4.6: OCCURS and Table Design

Design a COBOL table structure for a grade book that stores: - Up to 50 students - Each student has: student ID, name, and up to 20 assignment grades - The number of students and number of assignments are variable (use OCCURS DEPENDING ON) - Each grade is a numeric value from 0.0 to 100.0 with one decimal place

Write the complete data description and a PROCEDURE DIVISION paragraph that calculates the average grade for a given student.

Exercise 4.7: Record Layout Analysis

Examine the following record layout. Identify at least five design problems and explain how you would fix each one.

       01  customer-record.
           05  id             PIC 9(5).
           05  name           PIC A(20).
           05  balance        PIC 9(7)V99.
           05  rate           PIC 9V99.
           05  status         PIC X.
           05  txn-count      PIC 9(3).
           05  detail-area    PIC X(100).
           05  detail-medical REDEFINES detail-area.
               10  diag       PIC X(7).
               10  proc       PIC X(7).
               10  filler     PIC X(86).

Exercise 4.8: Storage Optimization Challenge

You have been given the following record layout that is 200 bytes in DISPLAY usage. Rewrite it using appropriate USAGE clauses to minimize storage while maintaining all data. Calculate the storage savings.

       01  ORIG-RECORD.
           05  OR-ACCT-NUM       PIC 9(10).
           05  OR-NAME           PIC X(40).
           05  OR-BALANCE        PIC S9(11)V99.
           05  OR-YTD-INTEREST   PIC S9(7)V99.
           05  OR-TXN-COUNT      PIC 9(7).
           05  OR-RATE           PIC 9V9(6).
           05  OR-OPEN-DATE      PIC 9(8).
           05  OR-STATUS         PIC X(2).
           05  OR-MONTHLY-BAL    PIC S9(11)V99
                                 OCCURS 12 TIMES.

Exercise 4.9: Debugging Challenge

The following program has five data description bugs. Find them all, explain what symptom each would cause, and provide the corrected declaration.

       IDENTIFICATION DIVISION.
       PROGRAM-ID. BUGGY.

       DATA DIVISION.
       WORKING-STORAGE SECTION.
       01  WS-PRICE          PIC 9(5)V99 COMP-3.
       01  WS-QUANTITY        PIC 9(3).
       01  WS-TAX-RATE        PIC V99.
       01  WS-SUBTOTAL        PIC 9(5)V99.
       01  WS-TAX-AMOUNT      PIC 9(3)V99.
       01  WS-TOTAL           PIC 9(5)V99.
       01  WS-DISPLAY-TOTAL   PIC ZZ,ZZ9.99.
       01  WS-REFUND-AMT      PIC 9(5)V99.

       PROCEDURE DIVISION.
           MOVE 150.00 TO WS-PRICE
           MOVE 25 TO WS-QUANTITY
           MOVE .085 TO WS-TAX-RATE
           COMPUTE WS-SUBTOTAL = WS-PRICE * WS-QUANTITY
           COMPUTE WS-TAX-AMOUNT = WS-SUBTOTAL * WS-TAX-RATE
           ADD WS-SUBTOTAL WS-TAX-AMOUNT
               GIVING WS-TOTAL
           MOVE WS-TOTAL TO WS-DISPLAY-TOTAL
           COMPUTE WS-REFUND-AMT = WS-TOTAL * -1
           DISPLAY "TOTAL: " WS-DISPLAY-TOTAL
           DISPLAY "REFUND: " WS-REFUND-AMT
           STOP RUN.

Exercise 4.10: Comprehensive Record Design

Design a complete record layout for a university student enrollment system. The record should include:

  • Student ID (9 digits)
  • Student name (first, middle initial, last)
  • Date of birth (YYYYMMDD with redefined components)
  • Major code (2 characters) with at least 6 condition names
  • GPA (0.00 to 4.00) with condition names for academic standing
  • Enrollment status with condition names
  • Financial aid flag
  • Current semester course enrollments (variable, 1-8 courses per student), each with:
  • Course code (e.g., "COBOL301")
  • Section number
  • Credits (1-6)
  • Grade (if assigned) with condition names
  • Instructor ID
  • Audit trail fields (created timestamp, modified timestamp, modified by user ID)
  • Reserved FILLER for future expansion

Use appropriate USAGE for all fields. Follow the naming conventions and design patterns described in this chapter. The total record should not exceed 500 bytes.