Skip to content

Add S0C7 ABEND Lab: Handling Data Exception Due to Invalid Numeric Operations #337

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -3590,6 +3590,77 @@ With S0C7, the program is expecting numeric data, however, it found other invali
- Incorrect MOVE CORRESPONDING
- Incorrect assignment statements when MOVE from one field to another

## Lab

**Handling ABEND S0C7 - Data Exception**

**Objective:** Learn how to recognize and debug a common ABEND error, S0C7, caused by performing arithmetic on invalid numeric data in a COBOL program.

### What is S0C7?

S0C7 is a **runtime error** (called an **ABEND**, short for *abnormal end*) that happens when your COBOL program tries to perform arithmetic on invalid numeric data.

You will typically see an error message like:

`CEE3207S The system detected a data exception (System Completion Code=0C7)`

### Why does this error happen?

COBOL uses **PIC 9** or **COMP-3** for numeric fields. If these fields contain **non-numeric data** (like letters or symbols), and you try to perform arithmetic on them, the program crashes with a **S0C7 ABEND**.

### Here's a simple example:

```
01 JUNK-FIELD PIC X(05) VALUE "ABCDE".
01 NUM-FIELD-BAD REDEFINES JUNK-FIELD PIC S9(05) COMP-3.
...
ADD 100 TO NUM-FIELD-BAD.
```

- `"ABCDE"` is not a number.
- But `NUM-FIELD-BAD` is defined as a packed decimal (`COMP-3`).
- This mismatch causes the crash.

### Instructions

1. Open the COBOL file `CBL0014.cobol`. Analyze the code carefully. Notice that it uses `REDEFINES` to treat text as a numeric field.
2. Look at the value assigned to `JUNK-FIELD`. It is initialized with `"ABCDE"`, which is not a valid numeric value.
3. Observe how `NUM-FIELD-BAD`, a numeric `COMP-3` field, reuses the same memory space as `JUNK-FIELD`.
4. Submit the JCL program: `CBL0014J.jcl`.

*You should observe the job fails with a S0C7 ABEND.*

![](Images/image014.png)

### How to Fix It

To avoid getting this ABEND:
1. We need to modify the CBL0014.cobol

For example:

```
IDENTIFICATION DIVISION.
PROGRAM-ID. CBL0014.
DATA DIVISION.
WORKING-STORAGE SECTION.
01 TEXT-FIELD PIC X(05) VALUE "00012".
01 NUM-FIELD PIC 9(05).
01 RESULT PIC 9(06).
PROCEDURE DIVISION.
DISPLAY "Moving text to numeric field...".
MOVE TEXT-FIELD TO NUM-FIELD.
DISPLAY "Performing calculation...".
ADD 100 TO NUM-FIELD GIVING RESULT.
DISPLAY "Result: " RESULT.
STOP RUN.
```

2. Save the `CBL0014.cobol`file and resubmit the `CBL0014J.jcl`. The program should now run successfully and display the result of the arithmetic.

![](Images/image014j.png)

### S0CB - Division by Zero

Just like mathematics, attempting to divide a number with 0 in Enterprise COBOL is an undefined operation.
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
IDENTIFICATION DIVISION.
PROGRAM-ID. CBL0014.
AUTHOR. Athar Ramzan.

DATA DIVISION.
WORKING-STORAGE SECTION.
01 JUNK-FIELD PIC X(05) VALUE "ABCDE".
01 NUM-FIELD-BAD REDEFINES JUNK-FIELD PIC S9(05) COMP-3.
01 RESULT PIC S9(06) COMP-3.

PROCEDURE DIVISION.
DISPLAY "Triggering S0C7...".
ADD 100 TO NUM-FIELD-BAD GIVING RESULT.
DISPLAY "Result: " RESULT.
STOP RUN.
16 changes: 16 additions & 0 deletions COBOL Programming Course #2 - Learning COBOL/Labs/jcl/CBL0014J.jcl
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
//CBL0014J JOB 1,NOTIFY=&SYSUID
//***************************************************/
//COBRUN EXEC IGYWCL
//COBOL.SYSIN DD DSN=&SYSUID..CBL(CBL0014),DISP=SHR
//LKED.SYSLMOD DD DSN=&SYSUID..LOAD(CBL0014),DISP=SHR
//***************************************************/
// IF RC = 0 THEN
//***************************************************/
//RUN EXEC PGM=CBL0014
//STEPLIB DD DSN=&SYSUID..LOAD,DISP=SHR
//SYSOUT DD SYSOUT=*,OUTLIM=15000
//CEEDUMP DD SYSOUT=*
//SYSUDUMP DD SYSOUT=*
//***************************************************/
// ELSE
// ENDIF