DB2

DB2 SQLCODE +100 in COBOL Batch: Separate a Missing Control Row from End of Cursor

A `SQLCODE` of `+100` is often described as “not found,” but that description is too broad for batch support. This guide shows how to distinguish a normal end-of-cursor from a missing control-table row that should stop a job before it produces incomplete or incorrectly scoped output.

ProgramPlanPackageDB2 access
Original DBala learning flow — a visual summary of this article’s practical decision path.

A SQLCODE of +100 is often described as “not found,” but that description is too broad for batch support. This guide shows how to distinguish a normal end-of-cursor from a missing control-table row that should stop a job before it produces incomplete or incorrectly scoped output.

The same code can mean two very different things

In embedded SQL, DB2 returns +100 when a FETCH has no next row. In a cursor loop, that is normally the expected signal to finish processing. DB2 can also return +100 after a singleton SELECT ... INTO finds no matching row. That outcome may be harmless, such as an optional description not being present. Or it may mean the batch run has no authorized processing date, no interface control record, or no configuration required to decide what to do.

Treating both cases as the same event creates two opposite risks:

The right response comes from the SQL statement’s role, not from the numeric code alone. The examples below use fictional table and program names; adapt names, return-code rules, and restart standards to the local environment.

A batch control example

Assume program PAYLOAD1 first reads a row that authorizes the current processing cycle. The row records the cycle date and a RUN-STATUS value. Only an authorized cycle may be selected for processing. It then opens a cursor over eligible payment rows.

The control lookup is a singleton SELECT. The payment work is a cursor FETCH. Both can return +100, but they require separate branches.

       EXEC SQL
           SELECT CYCLE_DATE, RUN_STATUS
             INTO :WS-CYCLE-DATE, :WS-RUN-STATUS
             FROM BATCH_CONTROL
            WHERE JOB_NAME = :WS-JOB-NAME
              AND RUN_STATUS = 'READY'
       END-EXEC

EVALUATE SQLCODE
WHEN 0
CONTINUE
WHEN 100
MOVE 'Required READY control row was not found'
TO WS-ERROR-MSG
MOVE 12 TO RETURN-CODE
GO TO PROGRAM-END
WHEN OTHER
MOVE 'Control lookup failed; retain SQL diagnostics'
TO WS-ERROR-MSG
MOVE 12 TO RETURN-CODE
GO TO PROGRAM-END
END-EVALUATE

EXEC SQL
DECLARE PAY-CUR CURSOR FOR
SELECT PAYMENT_ID, AMOUNT
FROM PAYMENT_STG
WHERE CYCLE_DATE = :WS-CYCLE-DATE
ORDER BY PAYMENT_ID
END-EXEC

EXEC SQL OPEN PAY-CUR END-EXEC
IF SQLCODE NOT = 0
MOVE 12 TO RETURN-CODE
GO TO PROGRAM-END
END-IF

PERFORM UNTIL WS-END-OF-CURSOR = 'Y'
EXEC SQL
FETCH PAY-CUR INTO :HV-PAYMENT-ID, :HV-AMOUNT
END-EXEC
EVALUATE SQLCODE
WHEN 0
PERFORM PROCESS-PAYMENT
WHEN 100
MOVE 'Y' TO WS-END-OF-CURSOR
WHEN OTHER
MOVE 12 TO RETURN-CODE
MOVE 'Cursor fetch failed; do not infer restart point'
TO WS-ERROR-MSG
MOVE 'Y' TO WS-END-OF-CURSOR
END-EVALUATE
END-PERFORM
```

The ORDER BY is intentional. If the program records a last-successful business key for restart, a stable, documented sequence is necessary. The example does not prove that PAYMENT_ID alone is a safe restart key; that depends on uniqueness and the program’s commit design.

Decide the meaning before writing the branch

A compact decision table is more useful than a universal IF SQLCODE = 100 rule.

| SQL operation | +100 means | Typical action | Unsafe shortcut |
| --- | --- | --- | --- |
| Required singleton control lookup | No qualifying control row | Stop before business updates; issue an actionable message | Defaulting cycle date or status |
| Optional singleton lookup | No optional attribute | Use an explicitly approved default or report absence | Assuming optional without a business rule |
| Cursor FETCH | No more rows in the result set | Close cursor and complete normal end-of-input processing | Treating it as an application failure |
| UPDATE or DELETE | No row met the predicate | Compare with expected row count; decide whether it is a control failure | Calling the update successful without checking expectation |

For a control lookup, make the predicate state the intended rule. A query that searches only by job name may find an old completed row or multiple historical rows. A query that expects one active cycle should make its status and cycle-selection logic visible. If the data model permits more than one qualifying row, a singleton SELECT can return -811 instead of +100; that is a different integrity issue and should not be hidden by retrying.

Evidence to capture when the run stops on `+100`

Before changing a row, rerunning a job, or changing a program, collect enough evidence to classify the statement:

1. Program name, DB2 subsystem or environment, job step, timestamp, and the exact SQL statement context from the log or diagnostic trace.
2. The host-variable values used in the predicate, especially cycle date, job name, company code, and status. Do not place sensitive values in broadly visible logs.
3. Whether the statement was a singleton lookup, a cursor FETCH, or a searched update/delete.
4. For a cursor, the number of rows successfully processed, commit count, last committed business key, and any output records already written.
5. For a required control lookup, approved evidence of the expected cycle and its intended status. A missing row can be an upstream scheduling or control-maintenance issue rather than a DB2 availability problem.
6. Any accompanying SQLSTATE, DB2 message text, and program return code. +100 alone does not establish whether a transaction committed.

This evidence avoids an especially common support error: adding a control row merely to get past +100, without confirming that it belongs to the intended run. A row can remove the symptom while authorizing the wrong scope of processing.

Failure cases that deserve separate handling

Zero eligible payments after a valid control lookup. The cursor can return +100 on its first FETCH. That is a valid technical end-of-data, but whether the job should end with RC=0, RC=4, or a hold depends on the business contract. Record both “control found” and “eligible row count is zero” so operations can distinguish them.

A control row exists but is not visible. An uncommitted insert in another unit of work, a wrong subsystem, or a predicate built from an incorrectly formatted host variable can all look like a missing row. Check environment and data representation before concluding that control maintenance was omitted.

Restart after partial processing. Do not use the first post-restart +100 as proof that the prior run completed. Examine commit boundaries, checkpoint records, output disposition, and downstream side effects. Local standards may require reconciliation or a controlled backout rather than a rerun.

What to verify before rerun or promotion

Practical takeaway

SQLCODE +100 is an outcome, not a recovery instruction. Tie its handling to the SQL statement’s business purpose: normal completion for a cursor fetch, explicit decision for an optional lookup, and a safe stop for a missing required control row. That small distinction makes batch behavior clearer to both developers and production support.

← Back to all articles