👁 0
Q: When should I use COMMIT in DB2?
Answer:
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.
👁 0
Q: What is UDF (User Defined Function)?
Answer:
UDF extends SQL with custom functions. CREATE FUNCTION name(params) RETURNS type AS BEGIN logic END. Scalar returns single value. Table function returns rows. Use in SELECT, WHERE like built-in functions.
👁 0
Q: How to handle SQLCODE -805?
Answer:
-805 is DBRM or package not found. Plan bound but package missing or invalidated. REBIND PACKAGE. Check collection, package name. Verify BIND completed successfully. May need BIND PLAN to add package.
👁 0
Q: What is SQLCODE and what are common values?
Answer:
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
👁 0
Q: What is dynamic SQL?
Answer:
Dynamic SQL constructed at runtime. PREPARE creates executable. EXECUTE runs it. EXECUTE IMMEDIATE for one-time. DECLARE CURSOR for queries. More flexible but less efficient than static. Security concerns (injection).
👁 0
Q: How to handle -551 SQLCODE?
Answer:
-551 is authorization failure. No privilege for operation. Check GRANT statements. May need SELECT, UPDATE, DELETE, INSERT authority. GRANT privilege ON object TO user/role. Check SYSIBM.SYSTABAUTH.
👁 0
Q: How to handle CLOB in COBOL?
Answer:
Declare: 01 CLOB-VAR SQL TYPE IS CLOB(1M). Or use LOB locator: 01 CLOB-LOC SQL TYPE IS CLOB_LOCATOR. FREE LOCATOR releases. DBMS_LOB procedures for manipulation. Large CLOBs need special handling.
👁 0
Q: How to handle SQLCODE 100?
Answer:
SQLCODE 100 means not found or end of data. For SELECT INTO: no matching row. For FETCH: no more rows. For UPDATE/DELETE: no rows affected. Check context - may be normal condition, not error.
👁 0
Q: Explain EXEC SQL statements
Answer:
EXEC SQL marks embedded DB2 SQL. EXEC SQL SELECT col INTO :host-var FROM table WHERE key = :key-var END-EXEC. Colon prefix for host variables. SQLCODE in SQLCA indicates result. Precompiler converts to COBOL calls.
👁 0
Q: What is a DB2 plan vs package?
Answer:
Plan is executable form of program's SQL, bound from DBRM. Package is independent unit, can be shared. Plans contain packages or direct SQL. Packages allow separate rebind. Modern approach: package collections with small plans.
👁 0
Q: Explain CICS DB2 connection
Answer:
CICS connects to DB2 via thread. EXEC SQL in CICS program. RCT (Resource Control Table) defines. Thread pool for efficiency. DB2 subsystem parameter.
👁 0
Q: How to handle -904 SQLCODE?
Answer:
-904 is resource unavailable. Tablespace/index in restricted state, stopped, or unavailable. Check display status. May need START DATABASE command. Check for REORG, RECOVER, LOAD running. Wait and retry.
👁 0
Q: What is stored procedure?
Answer:
Stored procedure is saved SQL code. CREATE PROCEDURE name(params) BEGIN SQL statements END. CALL name(values) executes. Can have IN/OUT/INOUT parameters. Reduces network traffic. Logic in database. Security benefits.
👁 0
Q: Explain host variable rules
Answer:
Host variables prefixed with : in SQL. Declare in WORKING-STORAGE. Must be compatible types. Use indicator for NULL. Cannot use in dynamic object names. VARCHAR needs two-part structure in COBOL.
👁 0
Q: How to prevent SQL injection?
Answer:
Use parameter markers (?), not concatenation. PREPARE stmt FROM 'SELECT * FROM t WHERE c = ?'. EXECUTE stmt USING :hostvar. Never build SQL with user input directly. Validate input. Use static SQL when possible.
👁 0
Q: How to handle -818 SQLCODE?
Answer:
-818 is timestamp mismatch between plan and DBRM. DBRM precompiled after last BIND. Solutions: REBIND plan/package, ensure DBRM library current, check promotion procedures. Timestamp in DBRM must match bound plan.
👁 0
Q: What causes -911 SQLCODE?
Answer:
-911 is deadlock or timeout. Two processes waiting for each other's resources. Solutions: consistent lock order, shorter transactions, COMMIT frequently, appropriate isolation level. -913 is similar (deadlock victim). Retry transaction.
👁 0
Q: What is SQLCA structure?
Answer:
SQLCA (SQL Communication Area) contains execution results. SQLCODE for return code. SQLERRM for message. SQLERRD(3) for rows affected. SQLWARN for warnings. INCLUDE SQLCA in WORKING-STORAGE. Check after each SQL statement.
👁 0
Q: How to handle -803 SQLCODE?
Answer:
-803 is duplicate key violation. Primary key or unique index constraint. Check SQLERRD(3) for index ID. Solutions: check data, use IGNORE_DUPLICATE, handle in program logic. May indicate data quality issue.
👁 0
Q: What is SPUFI?
Answer:
SPUFI (SQL Processing Using File Input) is TSO tool for interactive SQL. Input dataset with SQL statements. Output shows results. Good for testing queries, DDL, quick data checks. Not for production processing.
👁 0
Q: What is FETCH SENSITIVE cursor?
Answer:
SENSITIVE cursor reflects concurrent changes by other processes. EXEC SQL DECLARE cursor SENSITIVE STATIC/DYNAMIC SCROLL CURSOR. INSENSITIVE does not see changes. Affects isolation behavior. Consider performance impact.