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 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 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 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.