IBM i message

CPF0006: Errors occurred in command

CPF0006 means IBM i found errors in a command while analyzing it, so the command didn't run. The text reads "Errors occurred in command." The diagnostic messages just before it, usually CPD messages, say what was wrong.

Other names for this code

Also written as MSGCPF0006, CPF0006 errors occurred in command, errors occurred in command AS400, QCMDEXC CPF0006, iSeries CPF0006, CPF0006 ODBC.

What it means

Some commands arrive as a text string rather than as compiled CL. That happens when a program calls QCMDEXC, when someone types on a command line, and when a client runs a command through ODBC or a remote command server. The system has to parse the string, find the command, and check its keywords and values. IBM documents that when QCMDEXC finds a syntax error, it sends CPF0006.

Like CPF0001, it is a summary. The diagnostic messages before it, usually with CPD IDs, describe each problem. A common one is CPD0030, which means the command wasn't found in the library given or in the library list.

Because the string is built at run time, CPF0006 problems often come from the way the string was put together, or from the environment the string runs in, more than from the command itself.

Common causes

  • The command isn't found because its library isn't on the library list of the job running it. Jobs started from ODBC, JDBC or remote command servers often have a short library list.
  • Quotes in the command string are unbalanced, often because a value contained an apostrophe that wasn't doubled.
  • A keyword is misspelled or isn't valid for that command.
  • A value is too long or has the wrong type for its parameter.
  • The length passed to QCMDEXC doesn't match the string, so the command is cut off or picks up trailing junk.

How to find the problem

  1. Run DSPJOBLOG, press F10 for detailed messages, and read the messages just before CPF0006.
  2. Press F1 on each CPD message to see the parameter or keyword at fault.
  3. Log the exact command string your program passes to QCMDEXC. Paste it on a command line and press F4 to see what the prompter makes of it.
  4. For commands sent by a client, find the server job that ran them with WRKACTJOB (database server jobs are named QZDASOINIT) and check its library list with option 13 on WRKJOB.

How to fix it

  • Fix the command string so it parses. Double any apostrophe inside a quoted value.
  • Qualify the command with its library, such as MYLIB/MYCMD, or add the library to the job's library list first with ADDLIBLE.
  • For client connections, set the library list in the connection settings or the user's job description.
  • Pass QCMDEXC a length that covers the whole command string. A length that is too short cuts the command off.
  • Monitor for it in CL with MONMSG MSGID(CPF0006) if the command may legitimately fail.

IBM documentation

IBM Display Message Descriptions (DSPMSGD). Use the documentation for your installed release.

This link opens the relevant IBM reference library or lookup instructions. Match the complete code and your installed product release; it is not a code-specific review.

Read the installed message description:

DSPMSGD MSGID(CPF0006) MSGF(QSYS/QCPFMSG)

Also inspect the full job log and second-level message text, including substitution values.

Report a correction to WND Software.

Questions

What is the difference between CPF0006 and CPF0001?

Both mean the command didn't run because errors were found while checking it. CPF0006 is the general message for errors found while analyzing a command string, for example in QCMDEXC. CPF0001 names the command that failed.

Why does my command work on a command line but fail with CPF0006 from ODBC?

The server job that runs it has a different library list or user than your interactive session. Check the library list of that job and qualify the command or add the library.

How do I see what was wrong?

Look at the messages just before CPF0006 in the job log. They have CPD IDs and name the parameter or keyword at fault.