VSAM Realtime (Scenario based) Interview Questions (21 - 30)

21. Explain how to handle errors when accessing a VSAM dataset in COBOL.

Errors are handled using the FILE STATUS clause in COBOL.

  • Declare FILE STATUS in FILE-CONTROL:
    SELECT VSAM-FILE ASSIGN TO INFILE
           FILE STATUS IS WS-FILE-STATUS.
  • Define the status variable in WORKING-STORAGE:
    01 WS-FILE-STATUS PIC XX.
  • Check WS-FILE-STATUS after each operation:
    IF WS-FILE-STATUS = '10'
       DISPLAY 'End of File'
    ELSE IF WS-FILE-STATUS NOT = '00'
       DISPLAY 'Error: ' WS-FILE-STATUS
    END-IF.

22. How are records stored in an ESDS?

In an ESDS (Entry-Sequenced Data Set), records are stored in the order they are written, one after another. ESDS stores records in entry order, and each is accessed by its RBA, not by key.

  • Each record is assigned a Relative Byte Address (RBA).
  • Records cannot be deleted; only updated or added at the end.
  • Access is done sequentially or directly using RBA.

23. What is the ORGANIZATION for a KSDS in COBOL SELECT statement?

INDEXED

24. Do primary key values and alternate key values have to be unique?

  • Primary Key (in KSDS) → Must be unique.
  • Alternate Key → Can be unique or non-unique, depending on how it's defined.

25. What are Unique Cluster?

A Unique Cluster in VSAM refers to a KSDS (Key-Sequenced Data Set) where the primary key values are unique.

  • Each key identifies only one record.
  • Ensures no duplicate keys exist in the dataset.
  • Enforced by VSAM indexing structure.

26. What are Sub-allocated Clusters?

Sub-allocated clusters are VSAM datasets that share the same physical dataset (data component) but have different logical definitions, typically through alternate indexes.

  • Common in alternate index structures.
  • Data component is shared, but each cluster has its own index.
  • Reduces storage usage by sharing data among multiple clusters.

27. What is Upgrade and Noupgrade option in Alternate Index?

UPGRADE keeps the AIX updated with base KSDS changes, while NOUPGRADE requires manual synchronization.

UPGRADE:

  • Automatically updates the alternate index whenever the base cluster (KSDS) is updated.
  • Keeps AIX in sync with the base data.

NOUPGRADE:

  • The alternate index is not automatically updated.
  • You must manually rebuild the AIX using BLDINDEX.

28. How do you calculate an alternate cluster’s record size for unique and non-unique cases?

  • For Unique Alternate Key: Record Size = Alternate Key Length + RBA (4 bytes)
  • For Non-Unique Alternate Key: Record Size = Alternate Key Length + RBA (4 bytes) × Number of Duplicates

29. How can you fix the issue of VSAM running out of space?

  • Redefine the Cluster with More Space: Use a larger SPACE parameter (e.g., more cylinders or tracks) in the DEFINE CLUSTER.
  • Use the EXTEND Option (if supported): Enables automatic allocation of additional space when the dataset grows.
  • Reorganize the Dataset: Use IDCAMS REPRO to copy data to a newly defined larger cluster.
  • Use FREESPACE Wisely: Allocate FREESPACE to prevent frequent CI/CA splits, which consume extra space.
  • Delete Unused Records: Remove obsolete data if deletions are supported.

30. What are the Upgrade and Noupgrade options in the Alternate index?

  • KSDS → 2 buffers (data + index)
  • ESDS → 1 buffer (data only)