IBM i message

CPF4131: Level check on file

CPF4131 is a level check. The record format a program was compiled against doesn't match the format the file has now, so the system refuses to open the file for that program. The usual fix is to recompile the program.

Other names for this code

Also written as CPF4131 level check, MSGID CPF4131, level check on file, level check error, RPG level check, LVLCHK.

What it means

CPF4131 is an escape message sent when a file is opened. Its text reads "Level check on file &2 in library &3 with member &4." It is one of the open failures in the CPF4101 to CPF43FF range, so the file can't be used.

Every record format of an externally described file has a record format level identifier. The system works it out from the format's description, including the record format name, the field names, their order, data types, lengths and decimal positions, whether each field allows nulls, and the total record length. When an RPG, COBOL or CL program is compiled, it stores the identifier of each format it uses. At open time the system compares the stored value with the file's current value. If they differ and the file has LVLCHK(*YES), the open fails with CPF4131.

The check protects data. A program working from an old layout would read fields from the wrong positions and could write the wrong bytes back. Key fields, select and omit rules and join specifications don't feed into the identifier, so changing those alone doesn't cause a level check.

In ILE RPG the open error comes back as file status 01216 or 01217, and the default handler sends RNQ1216 with CPF4131 named in its text.

Common causes

  • A file was changed and re-created, for example a field was added or resized, and the programs that use it weren't recompiled.
  • A program was moved to production without the matching file, or the file was moved without its programs.
  • The job's library list finds a different copy of the file from the one the program was compiled against, such as a test copy with a newer layout.
  • An override points the program at a file with a different record format.
  • IBM's own display and printer files in QSYS were changed to LVLCHK(*YES), usually by a mass change across all libraries. IBM ships them with LVLCHK(*NO), and some system commands then fail with CPF4131.

How to find the problem

  1. Run DSPJOBLOG and press F1 on CPF4131 to see the file, library and member. The messages around it name the program that was opening the file.
  2. Run DSPFD FILE(ACCTLIB/CUSTMAST) TYPE(*RCDFMT) to see the format level identifier the file has now.
  3. Run DSPPGMREF PGM(ACCTLIB/CUSTINQ) to see the files and record formats the program uses. Sent to an output file, it includes the level identifier the program was compiled with, so you can compare the two values.
  4. Check the library list (DSPLIBL) and any overrides (DSPOVR) to make sure the program is opening the copy of the file you think it is.
  5. Look at the file's and program's change dates (DSPOBJD) to see which one changed last.

How to fix it

  • Recompile every program that uses the changed file. DSPDBR on the physical file and DSPPGMREF across your application libraries help you build the list.
  • If the file layout change was a mistake, put the old file back so the programs match it again.
  • Fix the library list or override so the program opens the copy of the file it was compiled against.
  • Only when you are sure the change doesn't affect the program, bypass the check for that program alone with OVRDBF FILE(CUSTMAST) LVLCHK(*NO). IBM advises against turning level checking off on database files in general, because a field whose length or type changed can then damage data.
  • For IBM display and printer files that fail this way, set them back with CHGDSPF or CHGPRTF and LVLCHK(*NO) on the file in QSYS that the failing command uses.

What it looks like

Level check on file CUSTMAST in library ACCTLIB with member CUSTMAST.
Error message CPF4131 appeared during OPEN for file CUSTMAST (C S D F).

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(CPF4131) MSGF(QSYS/QCPFMSG)

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

Report a correction to WND Software.

Questions

I added a field at the end of the file. Why did old programs fail?

Adding a field changes the record format, so the level identifier changes too. Every program that uses that format needs recompiling, even if it never uses the new field.

Is LVLCHK(*NO) safe?

Only when the program truly doesn't depend on the changed part of the format. If a field moved, changed length or changed type, the program will read and write the wrong bytes. Recompiling is the safe fix.

Do changes to keys cause a level check?

No. Key fields, select and omit rules and join specifications aren't part of the record format level identifier, so changing only those doesn't trigger CPF4131.