Module 1: Abend Codes
S0C4- Protection Exception
S0C4 is a program interrupt (code 4) raised when a program tries to read or write storage it is not allowed to touch. It is almost always a storage violation.
What it means
- S0C4 means Protection Exception: the program referenced an address outside its own storage, or a protected area like the operating system.
- It is a program interrupt with interrupt code 4, hence the name S0C4.
- The typical IEF450I message looks like: IEF450I STEP1 - ABEND=S0C4 U0000 REASON=00000004.
Common causes
- A subscript or index going beyond an OCCURS table, e.g. reading EMP-TABLE(500) when the table has only 100 entries.
- A bad pointer: using a POINTER item that was never set, or a LINKAGE SECTION address passed incorrectly.
- Overlaying the save area or return address, for example by moving too many bytes into a small field.
- Referencing storage that was freed, or a file record area after the file was closed.
How to find it
- Get a dump with //SYSUDUMP DD SYSOUT=* (or SYSABEND for a full dump) and check the PSW for the failing instruction address.
- Look at the registers: one of them usually holds the bad address the program tried to use.
- Match the failing offset with the compiler listing to find the statement, then check the subscript, index or pointer used there.
How to fix it
- Validate every subscript before using it: IF WS-SUB > 0 AND WS-SUB <= 100.
- When using OCCURS DEPENDING ON, make sure the depending-on field is initialized and within range.
- Initialize pointer items and check them for NULL before use.
- Review any MOVE statements that could overlay storage: check field lengths on both sides of the MOVE.
Example
- Add a SYSUDUMP DD to capture the storage violation; the typical COBOL scenario is a subscript running past an OCCURS table:-
//STEP1 EXEC PGM=MYPROG //SYSUDUMP DD SYSOUT=* //* //* In the COBOL program, this kind of code causes S0C4: //* //* 01 EMP-TABLE. //* 05 EMP-ENTRY OCCURS 100 TIMES PIC X(20). //* //* MOVE 500 TO WS-SUB //* DISPLAY EMP-ENTRY(WS-SUB) *> S0C4: subscript 500 is out of range
