LESSON 5 · Intermediate

Jobs, CL and batch work management

Plain-English notes, safe code skeletons, IBM i commands, and a checkpoint you can use before opening the deeper question bank.

After this lesson

Learning notes

A job is the runtime boundary

A job carries identity, library lists, environment values, routing data, and a job log. Interactive and batch jobs can call the same program but have different response and monitoring expectations. A job queue holds work until a subsystem has an available activity level.

When a program behaves differently in batch, compare the job attributes and library list before changing code. The diagnostic message often tells you which resolution or authority assumption failed.

Observe the work-management path

WRKACTJOB SBS(QBATCH)
WRKJOBQ JOBQ(APPDATA/BATCHQ)
DSPJOB JOB(*) OPTION(*JOBLOG)
DSPJOBLOG JOB(*)
  1. Submit or start a job
  2. Job enters a job queue or is routed directly
  3. A subsystem selects the job for an activity level
  4. The program runs with its job context
  5. Messages and completion status go to the job log

Let CL coordinate and report

CLLE is a good boundary for setting the library list, creating temporary objects, calling programs in order, and reacting to expected messages. Keep business rules in RPG or SQL, where they can be tested with data. Use MONMSG narrowly and preserve the original message information.

An operator should be able to tell whether a failure is retryable, data-related, or a configuration problem. Send a useful diagnostic or escape message instead of allowing a silent fall-through.

CLLE orchestration skeleton

PGM PARM(&RUNID)
  DCL VAR(&RUNID) TYPE(*CHAR) LEN(20)
  MONMSG MSGID(CPF0000) EXEC(GOTO CMDLBL(ERROR))
  CALL PGM(APPDATA/LOADORDERS) PARM(&RUNID)
  CALL PGM(APPDATA/POSTORDERS) PARM(&RUNID)
  RETURN
ERROR:
  SNDPGMMSG MSG('Batch run failed; inspect the job log.') TOPGMQ(*SAME) MSGTYPE(*ESCAPE)
ENDPGM

Make batch processing restartable

A restartable batch design has deterministic selection, a status or work table, an operation identifier, and a defined commit boundary. Mark a row complete only after the business effect succeeds. Reconcile the small failure window where the business effect succeeds but the status update does not.

Schedule the job with an owner, expected duration, alert rule, and operator runbook. A schedule entry without a recovery plan is only a timer.

Schedule and inspect a run

ADDJOBSCDE JOB(APPDATA/NIGHTLY) CMD(CALL PGM(APPDATA/NIGHTLY)) FRQ(*WEEKLY)
WRKJOBSCDE
DSPJOBLOG JOB(APPDATA/NIGHTLY)

Open the detailed question chapters

Practice checkpoint

Answer all five, then review the explanations. The interactive site stores your completed learning checkpoints in this browser.

  1. 1. Which command creates an ILE CL module?
    1. CRTCLPGM
    2. CRTPF
    3. CRTCLMOD
    4. SBMJOB
  2. 2. Where does command-level MONMSG belong?
    1. Only at the end of the source
    2. Inside a DDS record format
    3. In a binding directory
    4. Immediately after the monitored command
  3. 3. Which is a suitable CL responsibility?
    1. Establish environment and orchestrate calls
    2. Replace every database query with text parsing
    3. Change all system values on startup
    4. Suppress all exceptions
  4. 4. What should a broad error handler preserve?
    1. Only a success message
    2. Original diagnostic context and failure status
    3. Only the last cleanup message
    4. Nothing after cleanup
  5. 5. A called RPG program expects packed(9:2). The caller must:
    1. Pass any nine-character text
    2. Always use an integer
    3. Pass a compatible representation and size
    4. Rely on the display value only
Show answer key and explanations

1. C — CRTCLMOD CRTCLMOD produces a module that can be bound into an ILE object.

2. D — Immediately after the monitored command Placement determines which command it monitors.

3. A — Establish environment and orchestrate calls CL wrappers are useful for controlled orchestration.

4. B — Original diagnostic context and failure status Cleanup should not hide the cause or falsely signal success.

5. C — Pass a compatible representation and size Parameter compatibility includes storage layout and scale, not just appearance.

IBM documentation for this path