Divide by Zero Cobol Floating Point Error

The following routine illustrates how a COBOL program can handle a divide-by-zero condition if one occurs. occur. These actions occur:The program enables the divide-by-zero exception. Exceptions can be enabled or disabled by calling the CEE3SPM (Query and Modify Language Environment Hardware Condition Enablement) callable service. The program registers a user-written condition handler that recognizes the divide-by-zero condition. The program then performs a divide-by-zero, which causes the user-written condition handler to get control. The handler calls CEE3GRN (Get Name of Routine that Incurred Condition), to return the name of the routine that the condition occurred in. The handler inserts the routine name and condition token into a user-defined message string, and calls CEEMOUT (Dispatch a Message) to send the message to the Language Environment message file. (The Language Environment message file is a file that you can specify to store messages from a given routine or application, or from all routines that run under Language Environment.) The program uses CEEHDLR to register the user-written condition handler. CBL LIB,QUOTE,NODYNAM *Module/File Name: IGZTSIGR ************************************************* ** * ** IGZTSIGR - Call the following Language * ** Environment services: * ** * ** : CEEHDLR - register user condition * ** handler * ** : CEE3GRN - get name of routine that * ** incurred the condition. * ** : CEEMOUT - output message associated * ** with the condition, including * ** the name of the routine that * ** incurred the condition. * ** * ** 1. Our example registers user condition * ** handler IGZTSIGH. * ** 2. Our program then divides by zero, which * ** causes a hardware exception condition. * ** 3. IGZTSIGH gets control and prints out a * ** message that includes the name of the * ** routine that incurred the divide-by-zero * ** condition, IGZTSIGR. * ** 4. IGZTSIGH requests that Condition * ** management resume execution after the * ** point at which the condition occurred. * ** 5. IGZTSIGR terminates normally. * ** * ************************************************* IDENTIFICATION DIVISION. PROGRAM-ID. IGZTSIGR. DATA DIVISION. WORKING-STORAGE SECTION. 01 DIVISOR PIC S9(9) BINARY. 01 QUOTIENT PIC S9(9) BINARY. ** ** Declares for condition handling ** 01 PGMPTR USAGE IS PROCEDURE-POINTER. 01 FBCODE. 02 Condition-Token-Value. COPY CEEIGZCT. 03 Case-1-Condition-ID. 04 Severity PIC S9(4) BINARY. 04 Msg-No PIC S9(4) BINARY. 03 Case-2-Condition-ID REDEFINES Case-1-Condition-ID. 04 Class-Code PIC S9(4) BINARY. 04 Cause-Code PIC S9(4) BINARY. 03 Case-Sev-Ctl PIC X. 03 Facility-ID PIC XXX. 02 I-S-Info PIC S9(9) BINARY. 77 TOKEN PIC X(4). PROCEDURE DIVISION. 0001-BEGIN-PROCESSING. DISPLAY "*********************************". DISPLAY "IGZTSIGR COBOL Example is ". DISPLAY " now in motion. ". DISPLAY "*********************************". ** ********************************************** ** Register user condition handler IGZTSIGH ** ** using CEEHDLR ** ** ********************************************** SET PGMPTR TO ENTRY "IGZTSIGH". MOVE 97 TO TOKEN. CALL "CEEHDLR" USING PGMPTR, TOKEN, FBCODE. IF ( NOT CEE000 of FBCODE ) THEN DISPLAY "Error " Msg-No of FBCODE " registering condition handler " " IGZTSIGH" UPON CONSOLE STOP RUN END-IF. ************************************************* ** Divide by zero to cause a hardware exception** ** condition. Condition handler IGZTSIGH gets ** ** control and CALLs CEE3GRN to obtain the ** ** name of the routine in which the condition ** ** was raised. ** ** IGZTSIGH then prints a message using CEEMOUT** ** and passing the name "LEASMSIG." Control ** ** returns and normal termination takes place. ** ** ********************************************** MOVE 0 TO DIVISOR. DIVIDE 5 BY DIVISOR GIVING QUOTIENT. DISPLAY "*********************************". DISPLAY "IGZTSIGR COBOL Example has ended.". DISPLAY "*********************************". GOBACK. End program IGZTSIGR .

CBL LIB,QUOTE,NODYNAM

** **
** IGZTSIGH – Call the following Language **
** Environment services: **
** **
** : CEE3GRN – Get name of routine that **
** incurred a condition. **
** : CEEMOUT – output a user message **
** **
** This is the user condition handler **
** registered by IGZTSIGR. It calls CEE3GRN **
** to retrieve the name of the routine that **
** incurred the divide-by-zero condition. It **
** then calls CEEMOUT to output the message. **
**

IDENTIFICATION DIVISION.
PROGRAM-ID. IGZTSIGH.
DATA DIVISION.
WORKING-STORAGE SECTION.
01 msgstr.
02 VarStr-length PIC S9(4) BINARY.
02 VarStr-text.
03 VarStr-char PIC X,
OCCURS 0 TO 256 TIMES
DEPENDING ON VarStr-length
OF msgstr. 01 Feedback.
02 Condition-Token-Value.
COPY CEEIGZCT.
03 Case-1-Condition-ID.
04 Severity PIC S9(4) BINARY.
04 Msg-No PIC S9(4) BINARY.
03 Case-2-Condition-ID
REDEFINES Case-1-Condition-ID.
04 Class-Code PIC S9(4) BINARY.
04 Cause-Code PIC S9(4) BINARY.
03 Case-Sev-Ctl PIC X.
03 Facility-ID PIC XXX.
02 I-S-Info PIC S9(9) BINARY.
77 rtn-name PIC X(80).
77 msgdest PIC S9(9) BINARY.
77 string-pointer PIC S9(4) BINARY.
*
LINKAGE SECTION.
01 Current-condition.
02 Condition-Token-Value.
COPY CEEIGZCT.
03 Case-1-Condition-ID.
04 Severity PIC S9(4) BINARY.
04 Msg-No PIC S9(4) BINARY.
03 Case-2-Condition-ID
REDEFINES Case-1-Condition-ID.
04 Class-Code PIC S9(4) BINARY.
04 Cause-Code PIC S9(4) BINARY.
03 Case-Sev-Ctl PIC X.
03 Facility-ID PIC XXX.
02 I-S-Info PIC S9(9) BINARY.
**
01 Token PIC X(4).
**
01 Result-code PIC S9(9) BINARY.
88 resume VALUE +10.
88 percolate VALUE +20.
88 perc-sf VALUE +21.
88 promote VALUE +30.
88 promote-sf VALUE +31.
01 New-condition.
02 Condition-Token-Value.
COPY CEEIGZCT.
03 Case-1-Condition-ID.
04 Severity PIC S9(4) BINARY.
04 Msg-No PIC S9(4) BINARY.
03 Case-2-Condition-ID
REDEFINES Case-1-Condition-ID.
04 Class-Code PIC S9(4) BINARY.
04 Cause-Code PIC S9(4) BINARY.
03 Case-Sev-Ctl PIC X.
03 Facility-ID PIC XXX.
02 I-S-Info PIC S9(9) BINARY.
PROCEDURE DIVISION USING current-condition,
token, result-code,
new-condition.
*
* Check to see whether this routine was *
* entered due to a divide-by-zero exception, *
* or due to some other condition. *

IF CEE349 OF current-condition THEN

* (A divide-by-zero condition has occurred)*

SET resume TO TRUE

** Call CEE3GRN to retrieve the name of the **
** program that incurred the divide-by-zero **
** exception. Build user message and include **
** the name of the program. **

CALL “CEE3GRN” USING rtn-name, feedback
IF ( NOT CEE000 OF feedback ) THEN
DISPLAY “Error ” Msg-No OF feedback
” in obtaining program name.”
UPON CONSOLE
MOVE feedback TO new-condition
SET promote TO TRUE
ELSE
MOVE 1 TO string-pointer
MOVE 255 TO VarStr-length OF msgstr
STRING “The example program “
rtn-name
” incurred a divide-by-zero”
” exception.”
DELIMITED BY ” “
INTO VarStr-text OF msgstr
POINTER string-pointer
SUBTRACT 1 FROM string-pointer,
GIVING VarStr-length OF msgstr
MOVE 2 TO msgdest

** Call CEEMOUT to output the user message.**

CALL “CEEMOUT” USING msgstr,msgdest,
feedback
IF ( NOT CEE000 OF feedback ) THEN
DISPLAY “Error in writing the “
“message string.”
MOVE feedback TO new-condition
SET promote TO TRUE
END-IF
END-IF
ELSE

* (A condition other than **
* divide-by-zero has occurred) **
*
SET percolate TO TRUE
END-IF GOBACK. END PROGRAM IGZTSIGH.

Copy code

Parent topic:
Examples with a registered user-written condition

How to fix a divide or divide by zero error
Updated: 06/30/2020 by Computer Hope
Note

This page also applies to the error messages “Divide by Zero,” “Divide by 0,” or “Divide Overflow” error messages.
Calculator divide by zero error

The divide error messages happen when the computer or software attempts run a process that performs a mathematical division by zero, which is an illegal operation. This error message could also be caused by a computer or software limitation or conflict with computer memory.
Improper calculation

If you or the program you’re using performs a calculation in any program and experience a divide error, ensure that the calculation being performed is possible. Some programs are not capable of verifying the accuracy of a calculation and may perform an illegal instruction.

Programs such as Microsoft Excel, generate a #DIV!0 error to indicate the formula or calculation is invalid. For example, when attempting to divide by zero.Getting #DIV/0! in Microsoft Excel spreadsheet.

Hardware or software incompatibility

This issue can occur if a program is incompatible with hardware or software on your computer. Make sure all computer software installed is up-to-date and compatible with the operating system and hardware inside and connected to the computer.
Driver issue

If you are encountering a divide error while using Windows, make sure you are running the latest drivers and software for all component hardware devices. Verify the video card, sound card, network card, and modem drivers on the computer.

You can find a listing of computer drivers on our drivers page.
Software issue

If the divide error happens in a game or program, and the above recommendations don’t resolve your issue, verify all software patches and upgrades are installed.

Also, verify no other program is running in the background that could be causing your problem by End Tasking all background programs and TSRs.How to remove TSRs and startup programs.

External cache or 2nd level cache

If you are encountering the divide error in an older software program or game, it can be caused by compatibility issues with external cache or 2nd level cache. Temporarily disabling this feature in your BIOS setup may resolve your issue.How to enter the BIOS or CMOS setup.

Operating system issue

If you continue to experience divide errors and tried all of the above recommendations, make sure it’s not a problem with the operating system by reinstalling the operating system.
Hardware issue

Finally, if none of the above recommendations resolve or help to determine what’s cause your issue, the computer may have a hardware issue. When a divide error is encountered because of hardware, it’s most often caused by an issue with the computer processor (CPU).
Error with autoexec.bat or config.sys

Users who are running Microsoft Windows 3.x can temporarily remark or remove any additional lines that may not be required in the autoexec.bat and config.sys.

Users who are running Microsoft Windows 95 or Windows 98, we recommend they temporarily rename the autoexec.bat and config.sys to ensure that these files are not causing the issue. To do this, follow the instructions below:Click Start, Shutdown, and then Restart the computer in an MS-DOS mode. Once at the MS-DOS prompt, type:

cd\
ren autoexec.bat autoexec.ch
ren config.sys config.ch Once the files are renamed, reboot the computer.

Additional help and information with the autoexec.bat and config.sys is on our autoexec.bat and config.sys page.
Note

If you can’t get to an MS-DOS prompt or Windows to rename or edit the files, boot the computer to an MS-DOS mode only.
Additional informationSee our divide definition for further information and related links. Basic computer troubleshooting. Was this page useful?YesNo FeedbackE-mailSharePrint Recently added pages How do I make Windows programs automatically startup? How do I update my Antivirus if my antivirus license is expiring? How to change my printer from portrait to landscape mode? Where is my E-mail attachment saved after it is opened? How do I add pictures to my website? View all recent updates Useful links About Computer Hope Site Map Forum Contact Us How to Help Top 10 pages Follow us Facebook Twitter Pinterest YouTube RSS

© 2021 Computer Hope
Legal Disclaimer – Privacy Statement
Back to Top

Leave a comment

Design a site like this with WordPress.com
Get started