Q1
What are the four divisions of a COBOL program?
- IDENTIFICATION DIVISION - Program identification (PROGRAM-ID)
- ENVIRONMENT DIVISION - Hardware/software environment, file assignments
- DATA DIVISION - Data definitions (FILE, WORKING-STORAGE, LINKAGE SECTION)
- PROCEDURE DIVISION - Executable code and business logic
Only IDENTIFICATION and PROCEDURE DIVISION are mandatory.
Q2
What is the difference between SECTION and PARAGRAPH in COBOL?
SECTION:
- Contains one or more paragraphs
- Ends with next SECTION or end of program
- Used for logical grouping
- Can be performed as a unit
PARAGRAPH:
- Basic unit of code
- Named block of statements
- Ends at next paragraph name or SECTION
PERFORM SECTION-NAME executes all paragraphs in the section.
PERFORM PARA-NAME executes only that paragraph.
Q3
What is a copybook and why is it used?
A copybook is a reusable code file that can be included in multiple programs using the COPY statement.
Uses:
- Standard record layouts
- Common working storage definitions
- Reusable paragraphs
- Ensures consistency across programs
Syntax:
COPY EMPREC. COPY EMPREC REPLACING ==EMP== BY ==WS-EMP==.
Benefits:
- Reduces code duplication
- Easier maintenance
- Standard definitions across team
Q4
Explain the four divisions of a COBOL program.
IDENTIFICATION DIVISION: Program identification (PROGRAM-ID required). ENVIRONMENT DIVISION: Hardware/software configuration, file definitions. DATA DIVISION: Variable declarations, file records, working storage. PROCEDURE DIVISION: Executable code, business logic.
Q5
Explain COMP, COMP-1, COMP-2, and COMP-3 data types.
COMP: Binary (2/4/8 bytes based on PIC). COMP-1: Single precision floating point (4 bytes). COMP-2: Double precision floating point (8 bytes). COMP-3: Packed decimal (2 digits per byte + sign nibble).
Q6
How does SEARCH differ from SEARCH ALL?
SEARCH: Sequential search from current index position. SEARCH ALL: Binary search requiring sorted table with KEY clause. SEARCH ALL is faster for large tables but requires sorted data and indexed table.
Q7
What is COPY statement and how does REPLACING work?
COPY includes copybook at compile time. REPLACING substitutes text: COPY copybook REPLACING ==OLD== BY ==NEW==. Used for code reuse and standardization across programs.
Q8
Explain the PERFORM verb variations.
PERFORM para: Execute once. PERFORM para THRU para-exit: Execute range. PERFORM para n TIMES: Execute n times. PERFORM para UNTIL condition: Loop until true. PERFORM VARYING: Counter-controlled loop.
Q9
What is EVALUATE statement and its advantages?
EVALUATE is COBOL's case construct. EVALUATE TRUE WHEN condition-1 action WHEN OTHER default. Cleaner than nested IF, can evaluate multiple subjects, supports ALSO for multiple conditions, uses THRU for ranges.
Q10
What is INITIALIZE and what doesn't it initialize?
INITIALIZE sets fields to defaults: alphabetic to SPACES, numeric to ZEROS. Does NOT initialize: FILLER items, REDEFINES items, index data items. Can use REPLACING for custom values.
Q11
What is the purpose of LINKAGE SECTION?
LINKAGE SECTION defines parameters received from calling program. Items have no memory until CALL provides addresses. Used for passed parameters and dynamically addressed data.
Q12
What is GOBACK vs STOP RUN?
STOP RUN terminates entire run unit. GOBACK returns to caller; if main, acts like STOP RUN. Always use GOBACK in subprograms. STOP RUN from subprogram terminates everything.