Top Interview Questions
Introduction
COBOL, which stands for Common Business-Oriented Language, is one of the oldest high-level programming languages, specifically designed for business, finance, and administrative systems for companies and governments. It was developed in the late 1950s to early 1960s as a part of a drive to create a universal programming language that could be easily read and understood by both programmers and non-programmers alike. Despite being decades old, COBOL continues to run a significant portion of the world’s financial systems, from banking to insurance, and government operations, underscoring its reliability and robustness.
COBOL’s history traces back to 1959, when the Conference on Data Systems Languages (CODASYL) was formed to create a standardized language for business data processing. Prior to COBOL, businesses relied on machine-specific assembly languages, which were difficult to understand, maintain, and port across different computers.
A committee led by Grace Hopper, often referred to as the “Grandmother of COBOL,” contributed significantly to the language's design. COBOL was officially standardized in 1960, and its adoption spread rapidly due to its readability, portability, and suitability for business applications. Over the decades, COBOL has undergone multiple standardizations, such as COBOL-68, COBOL-74, COBOL-85, and modern versions that integrate object-oriented features.
COBOL was designed with business applications in mind, particularly those involving processing large volumes of data, such as payroll, accounting, billing, and inventory management. The language’s main objectives include:
Readability: COBOL syntax is highly English-like, making it easier for non-technical personnel, such as business analysts, to understand the code.
Portability: Programs written in COBOL can run on different computer systems with minimal modifications.
Data Processing Efficiency: Optimized for handling large-scale batch and transactional processing.
Maintainability: Designed to be easy to modify and extend, crucial for long-term business applications.
COBOL’s syntax prioritizes clarity over brevity. While modern programming languages often favor compact code, COBOL emphasizes self-documenting statements like ADD SALARY TO TOTAL-PAY.
A typical COBOL program is divided into four main divisions, each serving a specific purpose:
IDENTIFICATION DIVISION
This division provides the program's metadata, such as its name, author, and date of creation. Example:
IDENTIFICATION DIVISION.
PROGRAM-ID. PAYROLL.
AUTHOR. YASH YADAV.
ENVIRONMENT DIVISION
Defines the hardware and software environment in which the program will run, including file handling and input/output configurations.
DATA DIVISION
Specifies all the variables, records, and data structures used in the program. It is divided into sections like WORKING-STORAGE SECTION, FILE SECTION, and LOCAL-STORAGE SECTION.
DATA DIVISION.
WORKING-STORAGE SECTION.
01 EMPLOYEE-NAME PIC A(20).
01 SALARY PIC 9(6)V99.
PROCEDURE DIVISION
Contains the executable statements of the program. This division implements the logic for processing data, performing calculations, and managing control flow.
PROCEDURE DIVISION.
ADD SALARY TO TOTAL-PAY.
DISPLAY 'TOTAL PAY: ' TOTAL-PAY.
STOP RUN.
The division-based structure, along with verbose English-like commands, makes COBOL programs highly readable and easier to maintain.
COBOL offers several distinctive features that set it apart from other programming languages:
English-Like Syntax:
Statements such as IF, THEN, PERFORM, DISPLAY, and ADD make the code readable and intuitive.
Precision in Data Handling:
COBOL allows fixed-point arithmetic and precise data definitions using the PICTURE clause, making it ideal for financial calculations.
File Handling Capabilities:
COBOL has robust support for sequential, indexed, and relative file operations, essential for business applications that manage massive datasets.
Batch and Transaction Processing:
COBOL is designed to handle large-scale batch processing (processing a batch of records at once) and online transaction processing (real-time data handling).
Portability:
Programs can be moved across different hardware and operating systems with minimal changes.
Structured Programming Support:
Modern COBOL supports structured programming constructs, reducing the reliance on GOTO statements and promoting modularity.
Object-Oriented COBOL:
Recent COBOL standards (like COBOL 2002) introduced object-oriented programming features, allowing developers to create classes, objects, and methods.
Despite its age, COBOL remains vital in many industries due to its reliability and scalability. Key applications include:
Banking and Financial Systems:
COBOL is widely used for ATM systems, loan processing, transaction management, and core banking applications.
Insurance Industry:
COBOL handles policies, claims processing, and customer information in life insurance, health insurance, and property insurance companies.
Government Systems:
COBOL powers social security systems, tax computation, pension management, and other large-scale administrative applications.
Retail and Inventory Management:
COBOL is used to track inventory, manage sales, generate invoices, and forecast demand.
Airline and Transportation Industry:
Reservation systems, ticketing, and logistics tracking in airlines and railways rely heavily on COBOL.
High Readability:
English-like syntax makes it easier for developers and non-programmers to understand and maintain code.
Scalability and Reliability:
COBOL is designed to handle large-scale applications efficiently, with minimal system downtime.
Legacy Integration:
Many businesses still rely on COBOL programs, and the language integrates well with modern systems through APIs and middleware.
Precision and Accuracy:
COBOL is excellent for handling financial transactions requiring exact decimal computations.
Longevity and Proven Track Record:
COBOL has been running mission-critical systems for over six decades, proving its durability.
Verbose Code:
Programs can be lengthy and time-consuming to write compared to modern concise languages like Python or Java.
Declining Workforce:
Fewer young programmers are learning COBOL, leading to a shortage of skilled developers for maintaining legacy systems.
Limited Modern Features:
Although object-oriented COBOL exists, it lacks many modern language features available in contemporary programming languages.
Difficult Modernization:
Updating or integrating COBOL systems with modern cloud-based architectures can be challenging and expensive.
Despite predictions of its decline, COBOL remains highly relevant due to several factors:
Legacy Systems Dependency:
Many banks, insurance companies, and government agencies still run core systems on COBOL. Rewriting these systems in a new language is risky and expensive.
Integration with Modern Technology:
COBOL programs can now interface with Java, .NET, and web services, allowing organizations to modernize applications gradually.
Support from Modern Platforms:
Platforms like IBM Z mainframes and Micro Focus COBOL provide enhanced performance, security, and connectivity features, ensuring COBOL’s continued relevance.
High Demand During Crises:
During critical times, like the COVID-19 pandemic, COBOL programmers were in demand to update unemployment and social benefits systems.
While COBOL is not as prominent in computer science curricula as languages like Python, Java, or C++, it remains essential in vocational training and enterprise IT programs. Learning COBOL provides insights into legacy system maintenance, business-oriented programming, and mainframe computing. For students or IT professionals looking to specialize in financial systems, insurance, or government applications, COBOL remains a valuable skill.
Answer:
COBOL (Common Business Oriented Language) is a high-level programming language developed in 1959, primarily used for business, finance, and administrative systems. It is designed for processing large volumes of data and is widely used in mainframe environments.
Key features:
English-like syntax (easy to read and maintain)
Platform-independent
Supports structured and procedural programming
Mainly used in business applications such as banking, insurance, and payroll systems
Answer:
A COBOL program is divided into four main divisions:
IDENTIFICATION DIVISION:
Provides the program name and author information.
Mandatory for all COBOL programs.
IDENTIFICATION DIVISION.
PROGRAM-ID. SampleProgram.
AUTHOR. Yash Yadav.
ENVIRONMENT DIVISION:
Describes the computer environment where the program will run.
Specifies input/output devices and files.
ENVIRONMENT DIVISION.
INPUT-OUTPUT SECTION.
FILE-CONTROL.
SELECT EmployeeFile ASSIGN TO 'EMP.DAT'.
DATA DIVISION:
Declares all variables and data structures used in the program.
Subdivisions include WORKING-STORAGE SECTION, FILE SECTION, and LINKAGE SECTION.
PROCEDURE DIVISION:
Contains the logic and instructions of the program.
Executable statements are written here.
PROCEDURE DIVISION.
DISPLAY 'Hello COBOL'.
STOP RUN.
Answer:
COBOL supports the following main data types:
Numeric: Holds numeric values.
PIC 9(5) → 5-digit number
PIC S9(4)V99 → Signed number with 2 decimal places
Alphabetic: Holds only letters.
PIC A(10) → 10 letters
Alphanumeric: Holds letters, digits, and special characters.
PIC X(20) → 20 characters
Alphanumeric Edited: Stores formatted strings for display.
PIC Z(5).99 → Displays numbers with formatting
Answer:
Section: A logical division in the PROCEDURE DIVISION. It groups related paragraphs.
Paragraph: A set of COBOL statements within a section. It ends with a period (.).
Example:
PROCESS-EMPLOYEE SECTION.
ADD-SALARY.
ADD BONUS TO SALARY.
DISPLAY SALARY.
Answer:
The PIC (Picture) clause defines the type, size, and format of a variable. It is used in the DATA DIVISION.
9 → Numeric
A → Alphabetic
X → Alphanumeric
S → Signed number
V → Implied decimal point
Example:
01 EMPLOYEE-NAME PIC A(20).
01 EMPLOYEE-AGE PIC 99.
01 SALARY PIC S9(5)V99.
Answer:
Data Movement Statements: MOVE, ACCEPT, DISPLAY
Arithmetic Statements: ADD, SUBTRACT, MULTIPLY, DIVIDE
Conditional Statements: IF, EVALUATE
Looping Statements: PERFORM
File Handling Statements: OPEN, CLOSE, READ, WRITE, REWRITE
Answer:
The PERFORM statement is used to execute a paragraph, section, or range of statements repeatedly or conditionally.
Types:
Simple PERFORM: Executes a paragraph or section once
PERFORM UNTIL: Repeats until a condition is met
PERFORM VARYING: Loop with increment/decrement
Example:
PERFORM PROCESS-EMPLOYEE UNTIL EMPLOYEE-END = 'Y'.
Answer:
| DISPLAY | WRITE |
|---|---|
| Outputs data to the screen | Outputs data to a file or report |
| Used for debugging or user interaction | Used for file handling |
Example: DISPLAY 'Hello' |
Example: WRITE EMPLOYEE-RECORD |
Answer:
ADD: Used for simple addition of numeric values.
ADD 100 TO SALARY.
COMPUTE: Can perform arithmetic operations (+, -, *, /) in a single statement.
COMPUTE NET-SALARY = SALARY + BONUS - TAX.
Answer:
Intrinsic functions are built-in functions to perform operations on data. Some common functions:
| Function | Description |
|---|---|
| NUMVAL | Converts string to numeric value |
| LENGTH | Returns the length of a string |
| FUNCTION UPPER-CASE | Converts string to uppercase |
| FUNCTION TRIM | Removes leading/trailing spaces |
Example:
MOVE FUNCTION LENGTH(EMPLOYEE-NAME) TO NAME-LENGTH.
Answer:
COBOL supports several file types:
Sequential File: Records stored one after another
Indexed File: Records accessed using a key field
Relative File: Records stored with relative record numbers
Example of file handling statements:
OPEN INPUT EmployeeFile
READ EmployeeFile
WRITE EmployeeOutput
CLOSE EmployeeFile
Answer:
| STOP RUN | GOBACK |
|---|---|
| Terminates the program completely | Returns control to the calling program |
| Used in main programs | Used in subprograms |
| Ends execution | Does not end the main program |
Answer:
PROCEDURE DIVISION USING: Defines parameters for subprograms
CALL: Invokes a subprogram and passes data
Example:
CALL 'SUBPROG' USING EMPLOYEE-NAME, SALARY.
Answer:
Sequential Access: Records are read in order from first to last.
Random/Direct Access: Records are accessed directly using keys or record numbers.
Answer:
Subprograms also have the following divisions:
IDENTIFICATION DIVISION – Program name
ENVIRONMENT DIVISION – Optional
DATA DIVISION – Variables and linkage section
PROCEDURE DIVISION USING – Receives parameters
Answer:
REDEFINES: Allows one memory area to be used by multiple data items with different data types.
RENAMES: Groups several contiguous data items under a new name.
Example:
01 EMPLOYEE-INFO.
05 EMP-NAME PIC X(20).
05 EMP-AGE PIC 99.
01 PERSON REDEFINES EMPLOYEE-INFO.
05 FULL-INFO PIC X(22).
Answer:
EVALUATE is similar to a switch-case statement in other languages. It simplifies multiple IF conditions.
Example:
EVALUATE GRADE
WHEN 'A' DISPLAY 'Excellent'
WHEN 'B' DISPLAY 'Good'
WHEN OTHER DISPLAY 'Average'
END-EVALUATE.
Answer:
Easy to read and maintain due to English-like syntax
Efficient for processing large datasets
Platform-independent
Strong file-handling capabilities
Long-standing support in mainframes and banking systems
Answer:
Verbose and long code
Not ideal for modern GUIs or web applications
Limited support for object-oriented programming (before COBOL 2002)
Performance may lag compared to modern languages for complex computations
Answer:
COBOL handles runtime errors using the FILE STATUS clause for file operations
Use ON SIZE ERROR, INVALID KEY, or AT END to detect errors in arithmetic or file handling
Example:
OPEN INPUT EmployeeFile
IF FILE-STATUS NOT = '00'
DISPLAY 'File Error'
END-IF
Answer:
WORKING-STORAGE SECTION:
Variables retain their values throughout the program execution.
Declared at the program level.
LOCAL-STORAGE SECTION:
Variables are reinitialized every time a program or subprogram is called.
Useful for temporary storage in subprograms.
Example:
WORKING-STORAGE SECTION.
01 TOTAL-SALES PIC 9(5) VALUE 0.
LOCAL-STORAGE SECTION.
01 TEMP-TOTAL PIC 9(5) VALUE 0.
Answer:
| FILE SECTION | WORKING-STORAGE SECTION |
|---|---|
| Used to define file structures and records | Used to define temporary or permanent variables |
| Required when working with files | Optional |
| Used with OPEN, READ, WRITE statements | Used for calculations, intermediate storage |
Answer:
Level numbers define the hierarchy of data items in DATA DIVISION.
01: Top-level structure
02-49: Subordinate fields
66: RENAMES
77: Independent elementary item (no subfields)
88: Condition names
Example:
01 EMPLOYEE-RECORD.
05 EMP-NAME PIC X(20).
05 EMP-AGE PIC 99.
05 EMP-SALARY PIC 9(6).
77 STATUS-CODE PIC 9.
88 ACTIVE VALUE 1.
88 INACTIVE VALUE 0.
Answer:
88-level items define condition names for a variable.
Used for readability and conditional checks.
Example:
01 EMP-STATUS PIC 9.
88 ACTIVE VALUE 1.
88 INACTIVE VALUE 0.
IF ACTIVE
DISPLAY 'Employee is active'.
Answer:
PERFORM THRU: Executes a range of paragraphs
PERFORM UNTIL: Executes until a condition is true
PERFORM VARYING: Loop with increment/decrement variable
PERFORM TIMES: Loop executes a fixed number of times
Example:
PERFORM VARYING I FROM 1 BY 1 UNTIL I > 5
DISPLAY I
END-PERFORM.
Answer:
| File Type | Access Method | Key Feature |
|---|---|---|
| Sequential | Read in order | Simple, fast for reading all records |
| Indexed | Access by key | Allows direct record access |
| Relative | Access by record number | Fixed-size records |
Answer:
00 → Successful operation
10 → End of file
90 → Duplicate key (for indexed files)
91 → Not found (for indexed files)
35 → Invalid key
Example:
READ EMP-FILE
AT END DISPLAY 'End of File'
NOT AT END DISPLAY EMP-NAME
END-READ.
Answer:
REDEFINES: Allows one memory area to be used by multiple data items. Only one is active at a time.
RENAMES: Groups contiguous fields under a new name for convenience.
Example (RENAMES):
01 EMPLOYEE-INFO.
05 EMP-NAME PIC X(10).
05 EMP-AGE PIC 99.
05 EMP-SALARY PIC 9(5).
01 EMP-DETAILS RENAMES EMPLOYEE-INFO FOR 1 THRU 3.
Answer:
MOVE: Copies a value from one variable to another.
COMPUTE: Performs arithmetic or calculations and stores the result.
Example:
MOVE 100 TO SALARY.
COMPUTE NET-SALARY = SALARY + BONUS - TAX.
Answer:
IF: Checks a single condition at a time.
EVALUATE: Similar to switch-case; checks multiple conditions and executes matching branch.
Example:
EVALUATE GRADE
WHEN 'A' DISPLAY 'Excellent'
WHEN 'B' DISPLAY 'Good'
WHEN OTHER DISPLAY 'Average'
END-EVALUATE.
Answer:
| ACCEPT | DISPLAY |
|---|---|
| Accepts input from user or system | Shows output on screen or report |
Example: ACCEPT EMP-NAME |
Example: DISPLAY EMP-NAME |
Answer:
Indexed: Access records using key values. Keys are unique or non-unique.
Relative: Access records using relative record numbers.
Answer:
Procedural COBOL: Traditional COBOL using divisions, paragraphs, and procedural logic.
Object-Oriented COBOL (OO-COBOL): Introduced in COBOL 2002; supports classes, objects, inheritance, and methods.
Answer:
File errors: Use FILE STATUS clause and check the code after each operation.
Arithmetic errors: Use ON SIZE ERROR clause.
Example:
ADD 100 TO SALARY ON SIZE ERROR
DISPLAY 'Overflow Error'
END-ADD.
Answer:
Elementary item: Cannot be subdivided (e.g., PIC X(10), PIC 9(5)).
Group item: Contains subfields (e.g., 01 EMPLOYEE with EMP-NAME, EMP-AGE).
Answer:
CALL: Invokes a subprogram.
LINKAGE SECTION: Declares variables passed from calling program to subprogram.
Example:
CALL 'SUBPROG' USING EMPLOYEE-NAME, SALARY.
Answer:
STOP RUN: Terminates the entire program.
GOBACK: Returns control to the calling program (used in subprograms).
Answer:
77: Independent elementary item (not part of any group).
88: Condition names for 77 or other data items.
Answer:
INSPECT: Counts, replaces, or removes characters in a string.
UNSTRING: Breaks a string into multiple parts based on delimiters.
Example (UNSTRING):
UNSTRING FULL-NAME DELIMITED BY SPACE
INTO FIRST-NAME, LAST-NAME
END-UNSTRING.
Answer:
INITIALIZE: Sets numeric fields to zero and alphanumeric fields to spaces.
MOVE: Copies a specific value to a variable.
Answer:
SELECT: Links a logical file name with the physical file.
ASSIGN: Specifies the physical file location (like path or DD name).
Example:
SELECT EMP-FILE ASSIGN TO 'EMP.DAT'.
Answer:
PERFORM TIMES: Repeats a set of statements a fixed number of times.
PERFORM UNTIL: Repeats until a condition becomes true.
Answer:
Numeric data: Stores numbers without formatting (e.g., 9(5)).
Numeric edited: Stores numbers with formatting (e.g., commas, decimal points).
Answer:
Functions like LENGTH, NUMVAL, UPPER-CASE, TRIM, etc., are built-in and used for operations on variables.
Example:
MOVE FUNCTION NUMVAL('12345') TO NUM-VALUE.
Answer:
Open multiple files using OPEN INPUT/OUTPUT/EXTEND
Read, write, or rewrite each file separately
Close all files at the end
Example:
OPEN INPUT EMP-FILE
OPEN OUTPUT REPORT-FILE
READ EMP-FILE
WRITE REPORT-FILE
CLOSE EMP-FILE REPORT-FILE
Answer:
SORT: Arranges records in ascending or descending order.
MERGE: Combines two or more sorted files into one sorted file.
Answer:
01: Top-level group item that can have subfields.
77: Elementary item, independent, cannot have subfields.
Answer:
IDENTIFICATION DIVISION
ENVIRONMENT DIVISION
DATA DIVISION
PROCEDURE DIVISION
Answer:
Use VALUE clause in WORKING-STORAGE section.
Example:
01 PI-VALUE PIC 9(1)V99 VALUE 3.14.
Answer:
Declared with 88-level items.
Makes code readable by replacing numeric values with meaningful names.
Answer:
Readable syntax: English-like, easy to maintain for business logic.
File handling: Supports sequential, indexed, and relative files.
Structured programming: Supports PERFORM, EVALUATE, and modularization.
Report generation: Built-in capabilities for formatted reports.
Mainframe compatibility: Works efficiently with CICS, DB2, VSAM.
Long-standing use: Widely used in banking, insurance, and payroll systems.
Answer:
01: Top-level group item, may have subfields.
77: Elementary item, standalone, cannot have subfields.
88: Condition names for meaningful conditional checks.
Example:
01 EMP-RECORD.
05 EMP-NAME PIC X(20).
05 EMP-AGE PIC 99.
77 STATUS-CODE PIC 9.
88 ACTIVE VALUE 1.
88 INACTIVE VALUE 0.
Answer:
Sequential Files: Simple read/write operations.
Indexed Files (VSAM): Direct access using keys, supports duplicates.
Relative Files: Access via record numbers.
Dynamic File Handling: Using SELECT … ASSIGN TO at runtime.
Error Handling: Using FILE STATUS codes to catch errors during OPEN, READ, WRITE.
Example:
OPEN INPUT EMP-FILE
IF FILE-STATUS NOT = '00'
DISPLAY 'File error occurred'
END-IF.
Answer:
Subprogram: A modular program invoked by a main program to perform specific tasks.
Calling Methods:
CALL 'SUBPROG' USING var1, var2
Parameters are passed via LINKAGE SECTION in the subprogram.
Example (Subprogram):
LINKAGE SECTION.
01 EMP-NAME PIC X(20).
PROCEDURE DIVISION USING EMP-NAME.
DISPLAY 'Employee Name: ' EMP-NAME.
GOBACK.
Main Program:
CALL 'SUBPROG' USING EMP-NAME.
Answer:
Static CALL: Subprogram is linked at compile time.
Dynamic CALL: Subprogram is linked at runtime; allows flexibility for multiple programs without recompilation.
Answer:
Open files sequentially or simultaneously.
Perform read/write operations separately for each file.
Close all files after processing.
Example:
OPEN INPUT EMP-FILE
OPEN OUTPUT REPORT-FILE
PERFORM UNTIL EOF = 'Y'
READ EMP-FILE AT END MOVE 'Y' TO EOF
NOT AT END
WRITE REPORT-FILE
END-READ
END-PERFORM
CLOSE EMP-FILE REPORT-FILE.
Answer:
NUMVAL: Converts numeric strings to numbers.
LENGTH: Returns length of a string.
UPPER-CASE / LOWER-CASE: Case conversion.
DATE / DAY-OF-WEEK: Used in financial/reporting programs.
TRIM: Removes spaces for data normalization.
Example:
MOVE FUNCTION NUMVAL(EMP-ID-STR) TO EMP-ID.
DISPLAY 'Length of Name: ' FUNCTION LENGTH(EMP-NAME).
Answer:
| PERFORM Type | Description |
|---|---|
| PERFORM | Executes a paragraph or section once |
| PERFORM THRU | Executes a range of paragraphs sequentially |
| PERFORM UNTIL | Executes repeatedly until a condition is satisfied |
| PERFORM VARYING | Loop with increment/decrement variable |
Example:
PERFORM VARYING I FROM 1 BY 1 UNTIL I > 10
DISPLAY I
END-PERFORM.
Answer:
EVALUATE is similar to switch-case in other languages.
WHEN OTHER handles all unmatched conditions.
Example:
EVALUATE GRADE
WHEN 'A' DISPLAY 'Excellent'
WHEN 'B' DISPLAY 'Good'
WHEN OTHER DISPLAY 'Average'
END-EVALUATE.
Answer:
COMP / BINARY: Efficient numeric storage for arithmetic; takes less memory.
COMP-3 / Packed Decimal: Stores two digits per byte; used for financial data.
Usage: Improves performance for calculations in mainframe systems.
Example:
01 SALARY PIC S9(7) COMP-3.
Answer:
Use indexed files for large datasets.
Minimize nested PERFORM loops.
Use COMP / COMP-3 for numeric processing.
Avoid unnecessary DISPLAY statements in production.
Properly manage memory and working-storage variables.
Answer:
FILE STATUS for file operations
ON SIZE ERROR for arithmetic overflow
INVALID KEY for indexed files
AT END for end-of-file detection
Example:
READ EMP-FILE
AT END DISPLAY 'End of file reached'
INVALID KEY DISPLAY 'Key not found'
END-READ.
Answer:
COBOL allows calling subprograms from another subprogram.
Linkage Section passes variables correctly.
Avoid deep nesting to maintain performance and readability.
Answer:
Reusable data or procedure segments included in programs using COPY statement.
Helps maintain consistency and reduces coding effort.
Example:
COPY EMPLOYEE-RECORDS.
Answer:
COBOL programs can access DB2 databases using embedded SQL.
EXEC SQL statements are used to perform SELECT, INSERT, UPDATE, DELETE.
Example:
EXEC SQL
SELECT NAME, SALARY INTO :EMP-NAME, :EMP-SALARY
FROM EMPLOYEE
WHERE EMP-ID = :EMP-ID
END-EXEC.
Answer:
Use DISPLAY statements to check variable values.
Use DEBUGGING TOOLS like Xpediter or IBM Debug Tool.
Check FILE STATUS and RETURN-CODES.
Comment out sections to isolate issues.
Answer:
Use EVALUATE instead of multiple nested IFs.
Use 88-level condition names for better readability.
Example:
IF ACTIVE OR TEMPORARY DISPLAY 'Employee can access system'.
Answer:
Use ACCEPT DATE or FUNCTION CURRENT-DATE to get system date.
Perform date arithmetic using numeric fields.
Example:
ACCEPT TODAY FROM DATE.
MOVE FUNCTION CURRENT-DATE TO SYS-DATE.
Answer:
SORT: Sorts large datasets efficiently.
MERGE: Combines multiple sorted files into a single sorted file.
Advanced: Using USING / GIVING clauses for optimized memory and file handling.
Example:
SORT EMP-FILE ON ASCENDING KEY EMP-NAME
USING UNSORTED-FILE
GIVING SORTED-FILE.
Answer:
Use CALL / LINKAGE SECTION for subprograms.
Use COPYBOOKS for reusable code.
Group related logic in sections and paragraphs for maintainability.
Answer:
VSAM (Virtual Storage Access Method) is used for indexed and direct access files.
Supports KSDS, RRDS, and ESDS file structures.
Efficient for large datasets in mainframes.
Example:
SELECT VSAM-EMP-FILE ASSIGN TO EMP-VSAM
ORGANIZATION IS INDEXED
RECORD KEY IS EMP-ID
FILE STATUS IS WS-FILE-STATUS.
Answer:
Use indexed or relative files for direct access.
Minimize nested loops.
Use SORT / MERGE utilities for large-scale sorting.
Use COMP-3 for numeric calculations to reduce memory usage.
Answer:
Introduced in COBOL 2002.
Supports classes, objects, methods, inheritance, polymorphism.
Useful for modernizing legacy COBOL applications.
Example:
CLASS-ID. Employee.
METHOD-ID. DisplayInfo.
DISPLAY 'Employee Details'.
END METHOD DisplayInfo.
END CLASS Employee.
Answer:
Use copybooks for standardization.
Use commenting and meaningful variable names.
Avoid hard-coded values; use constants or configuration files.
Implement error handling using FILE STATUS and RETURN-CODES.
Optimize loops and arithmetic operations.
Answer:
CICS: For online transaction processing.
DB2: For relational database access.
JCL: For batch processing and job scheduling.
Web services / REST APIs: Modern integration using wrappers or middleware.
Answer:
VSAM (Virtual Storage Access Method) is a file storage system used in mainframes for large datasets.
Types of VSAM files:
KSDS (Key-Sequenced Data Set): Records are accessed using a unique key. Supports sequential and random access.
RRDS (Relative Record Data Set): Records accessed via relative record numbers.
ESDS (Entry Sequenced Data Set): Records stored in the order they are entered.
Example of KSDS File Handling:
SELECT EMP-VSAM ASSIGN TO EMPFILE
ORGANIZATION IS INDEXED
RECORD KEY IS EMP-ID
FILE STATUS IS WS-FILE-STATUS.
OPEN INPUT EMP-VSAM
READ EMP-VSAM
AT END DISPLAY 'End of File'
NOT AT END DISPLAY EMP-NAME
END-READ
CLOSE EMP-VSAM.
Answer:
OCCURS: Defines a fixed array with a fixed number of elements.
OCCURS DEPENDING ON (ODO): Array size is dynamic; the number of occurrences is determined by a variable at runtime.
Example:
01 EMP-DETAILS.
05 EMP-NAME PIC X(20) OCCURS 10 TIMES.
05 EMP-AGE PIC 99 OCCURS 1 TO 10 TIMES DEPENDING ON EMP-COUNT.
Answer:
Use 88-level condition names for readability.
Use EVALUATE instead of nested IFs.
Example with 88-level:
01 EMP-STATUS PIC 9.
88 ACTIVE VALUE 1.
88 INACTIVE VALUE 0.
IF ACTIVE DISPLAY 'Employee Active'
ELSE DISPLAY 'Employee Inactive'.
Answer:
Common intrinsic functions include:
FUNCTION LENGTH: Returns the length of a string.
FUNCTION TRIM: Removes leading/trailing spaces.
FUNCTION UPPER-CASE / LOWER-CASE: Converts case.
FUNCTION NUMVAL: Converts numeric string to number.
Example:
MOVE FUNCTION NUMVAL(EMP-ID-STR) TO EMP-ID.
DISPLAY 'Length: ' FUNCTION LENGTH(EMP-NAME).
Answer:
Use DISPLAY statements for variable tracing.
Use mainframe debugging tools: IBM Debug Tool, Xpediter, Abend-AID.
Check FILE STATUS and RETURN-CODES after operations.
Use paragraph isolation to find logical errors.
Comment out sections to narrow down issues.
Answer:
Indexed VSAM (KSDS): Records have unique key values; supports sequential and random access.
Access Methods:
Sequential Read: First-to-last record.
Random Read: Using the key.
COBOL Example:
READ EMP-VSAM KEY IS EMP-ID
INVALID KEY DISPLAY 'Record Not Found'
NOT INVALID KEY DISPLAY EMP-NAME.
Answer:
CICS (Customer Information Control System): A transaction processing system for mainframes.
Integration:
COBOL programs are invoked as CICS transactions.
Use EXEC CICS commands for data input/output, file access, and communication.
Example:
EXEC CICS READ FILE('EMPFILE') INTO(EMP-RECORD) RIDFLD(EMP-ID)
RESP(RESP-CODE)
END-EXEC.
Answer:
| Type | Description | Example |
|---|---|---|
| Static Call | Subprogram linked at compile time | CALL 'SUBPROG' USING VAR1 |
| Dynamic Call | Subprogram linked at runtime | CALL VAR-PROG-NAME USING VAR1 |
Answer:
Use FUNCTION CURRENT-DATE to get system date and time.
Use arithmetic operations to calculate age, difference between dates.
Example:
MOVE FUNCTION CURRENT-DATE TO WS-CUR-DATE.
COMPUTE AGE = (WS-CUR-DATE - DOB) / 10000.
Answer:
COMP-3: Stores two digits per byte; last nibble contains sign.
Advantages:
Saves memory.
Faster arithmetic operations.
Widely used in financial applications.
Example:
01 SALARY PIC S9(7)V99 COMP-3.
Answer:
Use FILE STATUS after every OPEN, READ, WRITE, or REWRITE.
Example:
READ EMP-FILE
AT END MOVE 'Y' TO EOF-FLAG
INVALID KEY DISPLAY 'Record Not Found'
NOT INVALID KEY DISPLAY EMP-NAME
END-READ.
Answer:
SORT: Sorts input file into a new output file.
MERGE: Merges multiple sorted files into one sorted file.
Example (SORT):
SORT EMP-FILE ON ASCENDING KEY EMP-NAME
USING UNSORTED-FILE
GIVING SORTED-FILE.
Example (MERGE):
MERGE FINAL-FILE
ON ASCENDING KEY EMP-ID
USING FILE1 FILE2 FILE3.
Answer:
Reusable blocks of code or data definitions included using COPY statement.
Advantages:
Reduces code duplication.
Simplifies maintenance.
Ensures consistency across multiple programs.
Example:
COPY EMPLOYEE-RECORDS.
Answer:
Use CALL / LINKAGE SECTION for subprograms.
Use COPYBOOKS for reusable data structures.
Group related paragraphs and sections for logical separation.
Example:
CALL 'CALC-SALARY' USING EMP-ID, EMP-SALARY.
Answer:
Use IBM Debug Tool or Xpediter to set breakpoints and watch variables.
Capture abend dumps to analyze errors.
Use FILE STATUS monitoring and logs.
Step through program execution with trace tables.
Answer:
Use indexed/relative files instead of sequential files for large datasets.
Minimize nested PERFORM loops.
Use COMP / COMP-3 for numeric operations.
Avoid unnecessary DISPLAY statements in production.
Optimize SORT / MERGE operations with USING / GIVING clauses.
Answer:
Handles complex conditions efficiently.
Replaces multiple nested IF statements.
Example:
EVALUATE TRUE
WHEN AGE < 18 AND EMP-STATUS = 'ACTIVE' DISPLAY 'Minor Active'
WHEN AGE >= 18 AND EMP-STATUS = 'INACTIVE' DISPLAY 'Adult Inactive'
WHEN OTHER DISPLAY 'Other Case'
END-EVALUATE.
Answer:
Use EXEC CICS commands:
READ and WRITE for files
SEND and RECEIVE for terminal I/O
HANDLE CONDITION for error handling
Example:
EXEC CICS READ FILE('EMPFILE') INTO(EMP-RECORD) RIDFLD(EMP-ID) RESP(RESP-CODE) END-EXEC.
Answer:
Scenario 1: Handling duplicate records in VSAM indexed file.
Use INVALID KEY to detect duplicates, REWRITE to update records.
Scenario 2: Processing large payroll files efficiently.
Use indexed files or SORT / MERGE utilities.
Use COMP-3 fields for numeric calculations.
Scenario 3: Calling multiple subprograms in batch job.
Modularize with CALL and LINKAGE SECTION.
Use COPYBOOKs for shared structures.
Answer:
Use COMP-3 / packed decimal for precision.
Avoid floating-point; use numeric edited fields for display.
Example:
COMPUTE NET-SALARY = BASIC + BONUS - TAX.
Answer:
Use embedded SQL (EXEC SQL) inside COBOL.
Example:
EXEC SQL
SELECT NAME, SALARY INTO :EMP-NAME, :EMP-SALARY
FROM EMPLOYEE
WHERE EMP-ID = :EMP-ID
END-EXEC.
Answer:
UNSTRING: Breaks a string into multiple variables based on a delimiter.
STRING: Concatenates multiple strings with delimiters.
Example (UNSTRING):
UNSTRING FULL-NAME DELIMITED BY SPACE
INTO FIRST-NAME LAST-NAME
END-UNSTRING.
Example (STRING):
STRING FIRST-NAME DELIMITED BY SPACE
LAST-NAME DELIMITED BY SPACE
INTO FULL-NAME
END-STRING.
Answer:
Use READ … INVALID KEY to check record existence.
Use REWRITE to update existing records.
Use WRITE to insert new records.
Example:
READ EMP-VSAM KEY IS EMP-ID
INVALID KEY WRITE EMP-RECORD
NOT INVALID KEY REWRITE EMP-RECORD
END-READ.
Answer:
Validate input using ACCEPT and IF conditions.
Check FILE STATUS for file operations.
Use ON SIZE ERROR for arithmetic overflows.
Handle NULL or unexpected data.
Example:
ADD SALARY BONUS ON SIZE ERROR DISPLAY 'Overflow Error'.
Answer:
Use indexed/relative files instead of sequential files.
Minimize nested loops.
Use COMP / COMP-3 fields for numeric operations.
Reduce disk I/O by batching writes.
Use SORT / MERGE efficiently with USING / GIVING clauses.
Modularize code for maintainability and reduced CPU time.