COBOL Interview Questions and Answers (11 - 20)


11. What is the significance of the WORKING-STORAGE SECTION?

The WORKING-STORAGE SECTION is part of the DATA DIVISION and is used to define variables, constants, and temporary storage areas needed during program execution.

Variables remain available throughout the program's execution (unlike variables declared in the LINKAGE SECTION, which only exist during the CALL).

12. What is the use of LINKAGE SECTION?

The LINKAGE SECTION is a part of the DATA DIVISION used to define variables that receive data from calling programs, passed parameters, or shared memory areas. It is primarily used when -

  • Passing Data Between Programs
  • Receiving Data from JCL (for Mainframe Batch Programs)
  • In CICS applications, the LINKAGE SECTION is used to access COMMAREA (communication area), which holds data shared across transactions.

13. What is a level number in COBOL, and why is it important? Describe the significance of the level number in COBOL data definitions?

A Level Number is a numeric identifier used in the DATA DIVISION to define the hierarchy and structure of data items (variables). It indicates -

  • Defines Data Hierarchy and Structure - Level numbers establish the parent-child relationship between data items.
  • Helps in Grouping Related Data - Data items under the same 01 level belong together and can be moved together.
  • Allows Redefining Storage (Using REDEFINES Clause) - 66 level number redfine the variables.
  • Defines the individual items - 77 level number define individual items.
  • Used for Conditional Processing (Using 88 Level Number) - 88 level numbers define condition names, making programs more readable.

14. What is 77 level used for?

The 77 level number is used to declare standalone elementary data items that are not part of any group. Unlike 01 level, it cannot have subfields and must be a single variable. It can be used for constants that remain unchanged throughout the program. It is old memory optimization in older COBOL versions.

15. What is 88 level used for?

The 88 level number is used to define condition names, which act as meaningful names for specific values of a variable. Instead of using hardcoded values, 88 level allows assigning meaningful names to conditions. For example - MALE & FEMALE condition names having a single value.

 01 WS-GENDER       PIC X(01).
   88 WS-MALE         VALUE 'M'.
   88 WS-FEMALE       VALUE 'F'.

With the above definition, we can write -

 IF WS-MALE ...

Instead of -

 IF WS-GENDER EQUAL "M" ...

16. What are the different data types supported by COBOL?

A data type defines the type of data, a variable can hold, such as numeric values, alphabetic characters, or alpha-numeric strings. It specifies the nature of the data (e.g., numbers or letters), its format (e.g., decimal places or positions), and the operations can perform on it. There are five data types in COBOL, and those are -

  • Alphabetic
  • Alpha-numeric
  • Numeric
  • Sign
  • Decimal Point

17. What is PIC 9v99 indicates?

The v means an implied or assumed decimal point. PIC 9v99 is a three position numeric field with an implied or assumed decimal point after the first position.

18. What is the difference between PIC 9.99 and PIC9v99?

Both PIC 9.99 and PIC 9V99 are used to represent numeric data with decimal values, but they have key differences in storage, display, and arithmetic operations.

FeaturePIC 9.99PIC 9V99
Decimal RepresentationExplicit (Stored physically)Implied (Not stored physically, only assumed)
Storage in MemoryStores the decimal pointStores only digits, the decimal is assumed
Stored Value for 5.755.75 (4 bytes)575 (3 bytes)
Arithmetic OperationsUsed mainly for display, calculations may require conversionUsed directly in calculations
UsageFormatting for reporting and printingEfficient storage and arithmetic calculations

19. What is COMP-1? COMP-2? Difference between them?

COMP-1 (Single-Precision Floating-Point) is a 4-byte (32-bit) floating-point representation. It stores numbers in an approximate format using an exponent and mantissa.

COMP-2 (Double-Precision Floating-Point) is an 8-byte (64-bit) floating-point representation. It provides higher accuracy and precision than COMP-1.

FeatureCOMP-1 (Single Precision)COMP-2 (Double Precision)
Storage Size4 bytes8 bytes
PrecisionLess precise (approx. 7 decimal digits)More precise (approx. 15 decimal digits)
UsageGeneral scientific calculationsHigh-precision financial or scientific calculations
SpeedFasterSlower (due to higher precision)
Example Value Stored3.141592 (approximate)3.14159265358979 (more accurate)
Ideal Use CaseCalculations where precision is not criticalApplications requiring high-precision (e.g., banking, scientific computing)

20. What is the difference between comp and comp-3 usage?

Both COMP (Binary) and COMP-3 (Packed Decimal) are storage formats used in COBOL for efficient numeric data representation. They differ in how they store numbers, their performance, and their use cases.

FeatureCOMP (Binary)COMP-3 (Packed Decimal)
Storage FormatBinary (pure 0s and 1s)Packed Decimal (BCD format)
Storage Size2(1-4 digits), 4(5-9 digits), or 8(10-18 digits) bytes1 digit = ½ byte (+ 1 for sign)
PrecisionSuitable for whole numbers (integers) Best for decimal numbers (financial data)
Arithmetic SpeedFaster (CPU performs direct binary operations)Slower (needs unpacking and conversion)
Sign StorageUses full byteStored in the last half-byte (C = Positive, D = Negative))
Best Use CasesHigh-speed integer calculationsPrecise financial computations (banking, payroll)