Module 11: CICS Error Handling and Debugging
EIBTASKN
EIBTASKN holds the task number that CICS assigned to the running task. While EIBTRNID tells you which transaction is running, EIBTASKN tells you which instance of it. Every task gets a unique number, so it is perfect for tagging log records and tracing one user's session through the system.
What is EIBTASKN
- EIBTASKN is a numeric field in the EIB holding the task sequence number assigned by CICS.
- It is unique across running tasks. Two users running the same transaction at the same time get different task numbers.
- Like EIBTRNID, it stays constant for the whole task and does not change from command to command.
- Operators see task numbers in CEMT INQUIRE TASK displays, so quoting the task number helps them find your task.
Common uses of EIBTASKN
- Error logs: tag every error record with the task number so related messages can be grouped together.
- Temporary storage queues: build unique queue names with the task number, for example STRING 'WORK' EIBTASKN, so concurrent tasks do not clash.
- Debugging: when several users hit the same error, the task number tells support exactly which session to trace.
- Audit trails: record who-did-what by logging transaction id plus task number plus terminal id together.
Example: task-tagged error logging
- The example below builds an error log record tagged with transaction, task, and terminal:WORKING-STORAGE SECTION. 01 ERROR-LOG-REC. 05 LOG-TRNID PIC X(4). 05 LOG-TASKN PIC 9(7). 05 LOG-TRMID PIC X(4). 05 LOG-RESP PIC S9(8) COMP. 05 LOG-MSG PIC X(40). PROCEDURE DIVISION. 9000-WRITE-ERROR-LOG. MOVE EIBTRNID TO LOG-TRNID. MOVE EIBTASKN TO LOG-TASKN. MOVE EIBTRMID TO LOG-TRMID. MOVE EIBRESP TO LOG-RESP. MOVE 'FILE UPDATE FAILED' TO LOG-MSG. EXEC CICS WRITEQ TS QUEUE('ERRLOGQ') FROM(ERROR-LOG-REC) LENGTH(LENGTH OF ERROR-LOG-REC) END-EXEC.
EIBTASKN good practices
- Always log EIBTRNID together with EIBTASKN. The task number alone does not say which transaction ran.
- Do not use the task number as a permanent key. Task numbers are reused after tasks end; they identify a session, not a business entity.
- When building unique TS queue names from the task number, delete the queue when done so the TS pool does not fill up.
