Q: What is the difference between COMP and COMP-3 in COBOL?
COMP (COMPUTATIONAL) - Pure binary format
- Stored in binary (base-2)
- Used for subscripts and counts
- Efficient for arithmetic operations
- PIC S9(4) COMP = 2 bytes
- PIC S9(9) COMP = 4 bytes
COMP-3 (PACKED DECIMAL)
- Each digit takes 4 bits (nibble)
- Last nibble holds sign
- Used for business calculations
- PIC S9(5) COMP-3 = 3 bytes
- Formula: (n+1)/2 rounded up
When to use:
- COMP - Array subscripts, counters, loops
- COMP-3 - Money, quantities, business data
Q: How do I fix S0C7 Data Exception ABEND?
S0C7 occurs when the program tries to perform arithmetic on non-numeric data.
Common Causes:
- Uninitialized numeric fields (contains spaces/garbage)
- Moving alphanumeric data to numeric field
- Reading file with wrong record layout
- Array subscript accessing wrong memory
How to Fix:
- Initialize all numeric fields to ZEROS
- Validate input before arithmetic
- Check file layouts match
- Use DISPLAY to debug field contents
* Always initialize
INITIALIZE WS-RECORD.
MOVE ZEROS TO WS-AMOUNT.
* Validate before use
IF WS-INPUT IS NUMERIC
COMPUTE WS-RESULT = WS-INPUT * 2
END-IF.
Q: What is ROW_NUMBER()?
Q: What is the difference between COND and IF/THEN/ELSE in JCL?
COND Parameter:
- Tests return codes from previous steps
- Bypasses step if condition is TRUE
- Works opposite to programming logic!
- COND=(4,LT) means: Skip if 4 < any previous RC
IF/THEN/ELSE:
- More intuitive programming-like syntax
- Executes steps when condition is TRUE
- Supports AND, OR operators
- Can check ABEND conditions
Example:
// Using COND (skip if RC < 4) //STEP2 EXEC PGM=PROG2,COND=(4,LT) // Using IF/THEN/ELSE // IF STEP1.RC = 0 THEN //STEP2 EXEC PGM=PROG2 // ELSE //ERROR EXEC PGM=ERRPROC // ENDIF
Q: When should I use COMMIT in DB2?
COMMIT saves all changes since the last COMMIT and releases locks.
When to COMMIT:
- After processing a logical unit of work
- Periodically in long-running batch (every N records)
- Before ending the program successfully
Frequency Guidelines:
- Too frequent: Performance overhead
- Too rare: Lock contention, large log
- Typical: Every 100-1000 records in batch
Best Practice:
MOVE 0 TO WS-COMMIT-COUNT.
PERFORM PROCESS-RECORD.
ADD 1 TO WS-COMMIT-COUNT.
IF WS-COMMIT-COUNT >= 500
EXEC SQL COMMIT END-EXEC
MOVE 0 TO WS-COMMIT-COUNT
END-IF.
Note: In CICS, syncpoint (COMMIT) happens automatically at task end. Explicit SYNCPOINT is rarely needed.
Q: What is CTE (Common Table Expression)?
Q: What is the difference between KSDS and ESDS?
KSDS (Key Sequenced Data Set):
- Records accessed by unique key
- Records stored in key sequence
- Has both data and index components
- Supports random and sequential access
- Can delete and reinsert records
- Most commonly used VSAM type
ESDS (Entry Sequenced Data Set):
- Records stored in arrival order
- Accessed by RBA (Relative Byte Address)
- No index component
- Cannot delete records (only mark inactive)
- Similar to sequential files
- Good for logs, audit trails
Use KSDS when: You need key-based access, updates, deletes
Use ESDS when: Sequential processing only, append-only data
Q: What is pseudo-conversational programming in CICS?
Pseudo-conversational programming is a technique where the program ends between user interactions, freeing system resources.
How it works:
- Program sends screen to user and ends (RETURN TRANSID)
- User enters data and presses Enter
- CICS starts a new task with same program
- Program retrieves saved data from COMMAREA
- Process continues
Benefits:
- Efficient resource usage
- Better response times
- More concurrent users
Implementation:
* End task, wait for user
EXEC CICS RETURN
TRANSID('MENU')
COMMAREA(WS-COMM)
LENGTH(100)
END-EXEC.
* On return, check EIBCALEN
IF EIBCALEN = 0
PERFORM FIRST-TIME
ELSE
MOVE DFHCOMMAREA TO WS-COMM
PERFORM PROCESS-INPUT
END-IF.
Q: 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.
Q: 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.
Q: What is UDF (User Defined Function)?
Q: Explain REDEFINES clause with an example.
REDEFINES allows the same storage area to be referenced by different data names with different definitions.
Rules:
- Must be at same level as item being redefined
- Cannot redefine item with OCCURS
- Redefined item must appear first
- Lengths should match or redefining should be shorter
01 WS-DATE. 05 WS-DATE-NUM PIC 9(8). 01 WS-DATE-X REDEFINES WS-DATE. 05 WS-YEAR PIC 9(4). 05 WS-MONTH PIC 9(2). 05 WS-DAY PIC 9(2).
Same 8 bytes can be accessed as single number or individual components.
Q: How to handle SQLCODE -805?
Q: 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
Q: What is the difference between PARM and SYSIN for passing parameters?
PARM (EXEC statement):
- Limited to 100 characters
- Passed in memory to program
- Accessed via LINKAGE SECTION
- Good for small, simple parameters
SYSIN (DD statement):
- No practical size limit
- Read as a file by program
- Can contain multiple records
- Good for control cards, complex input
// PARM example //STEP1 EXEC PGM=MYPROG,PARM='PARAM1,PARAM2' // SYSIN example //SYSIN DD * CONTROL OPTION1 DATE=20231215 LIMIT=1000 /*
Q: What is SQLCODE and what are common values?
SQLCODE is a return code in SQLCA indicating the result of SQL execution.
Common SQLCODE values:
| 0 | Successful execution |
| 100 | No data found / End of cursor |
| -803 | Duplicate key on insert |
| -811 | Multiple rows returned for singleton SELECT |
| -904 | Unavailable resource |
| -911 | Deadlock/timeout |
| -922 | Authorization failure |
| -927 | DB2 not available |
Negative = Error, 0 = Success, 100 = No data
Q: What is RECOVER utility?
Q: Explain the difference between INNER JOIN and LEFT OUTER JOIN.
INNER JOIN:
- Returns only matching rows from both tables
- If no match, row is excluded
LEFT OUTER JOIN:
- Returns all rows from left table
- Matching rows from right table
- NULL for right table if no match
-- INNER JOIN SELECT E.NAME, D.DEPT_NAME FROM EMPLOYEE E INNER JOIN DEPARTMENT D ON E.DEPT_ID = D.DEPT_ID; -- LEFT OUTER JOIN SELECT E.NAME, D.DEPT_NAME FROM EMPLOYEE E LEFT OUTER JOIN DEPARTMENT D ON E.DEPT_ID = D.DEPT_ID;
Use LEFT JOIN when you want all employees even those without department.
Q: How to create image copy?
Q: What is the purpose of COMMAREA in CICS?
COMMAREA (Communication Area) is used to pass data between programs or between transactions in pseudo-conversational programming.
Uses:
- Pass data between LINK/XCTL programs
- Save data between pseudo-conversational transactions
- Maximum size: 32KB
How it works:
- Calling program: COMMAREA option on LINK/XCTL/RETURN
- Called program: DFHCOMMAREA in LINKAGE SECTION
- Check EIBCALEN for length (0 = no COMMAREA)
* Calling program
EXEC CICS LINK
PROGRAM('SUBPROG')
COMMAREA(WS-DATA)
LENGTH(100)
END-EXEC.
* Called program
LINKAGE SECTION.
01 DFHCOMMAREA PIC X(100).
IF EIBCALEN > 0
MOVE DFHCOMMAREA TO WS-DATA
END-IF.