× The internal search function is temporarily non-functional. The current search engine is no longer viable and we are researching alternatives.
As a stop gap measure, we are using Google's custom search engine service.
If you know of an easy to use, open source, search engine ... please contact support@midrange.com.



If a zero value is expected (perhaps a stock quantity) then test before the divide.

If it is not expected (but could happen) use MONITOR.

MONITOR has a very low overhead - less than a test - so it makes sense to use it if it is not going to occur often. Also I personally think that MONITOR makes the intent of the code more obvious - i.e. the expected logic path and the exception are clearly identified as to which is which.


On 2013-06-21, at 9:15 AM, Gary Thompson <gthompson@xxxxxxxxxxx> wrote:

Me too: what Michael said.

-----Original Message-----
From: rpg400-l-bounces@xxxxxxxxxxxx [mailto:rpg400-l-bounces@xxxxxxxxxxxx] On Behalf Of Clay Carley
Sent: Thursday, June 20, 2013 9:24 PM
To: rpg400-l@xxxxxxxxxxxx
Subject: Preventing a divide by zero error

This sounds like an easy an easy thing to check for, but here's what is going on:

I'm studying (on my own) RPG IV using Stanley Myers' book, "RPG IV Programming on the AS/400". I'm doing the programming assignments at the end of Chapter 5, and assignment 5-2 wants "Include the control that prevents a divide-by-zero error". As far as I can tell, this hasn't been discussed in the book yet; so I don't want to jump ahead with a solution that isn't what they are really looking for.

This is what the line in question could be something like:

C EVAL GRPFT = NETPRICE / GROSSPRFT

Is there some EVAL option I'm missing for this? Setting indicators is discussed, but for the life of me I don't see anything related to divide by zero.

I did some searching, but I found what I would logically do to check for a zero in the variable before doing the math. That hasn't been covered in this book yet, so I'm guessing there is something else to it.

Thanks,
Clay Carley
Sonic.net/ Sonic Telecom
--
This is the RPG programming on the IBM i (AS/400 and iSeries) (RPG400-L) mailing list To post a message email: RPG400-L@xxxxxxxxxxxx To subscribe, unsubscribe, or change list options,
visit: http://lists.midrange.com/mailman/listinfo/rpg400-l
or email: RPG400-L-request@xxxxxxxxxxxx
Before posting, please take a moment to review the archives at http://archive.midrange.com/rpg400-l.



--
This is the RPG programming on the IBM i (AS/400 and iSeries) (RPG400-L) mailing list
To post a message email: RPG400-L@xxxxxxxxxxxx
To subscribe, unsubscribe, or change list options,
visit: http://lists.midrange.com/mailman/listinfo/rpg400-l
or email: RPG400-L-request@xxxxxxxxxxxx
Before posting, please take a moment to review the archives
at http://archive.midrange.com/rpg400-l.


Jon Paris

www.partner400.com
www.SystemiDeveloper.com





As an Amazon Associate we earn from qualifying purchases.

This thread ...

Replies:

Follow On AppleNews
Return to Archive home page | Return to MIDRANGE.COM home page

This mailing list archive is Copyright 1997-2024 by midrange.com and David Gibbs as a compilation work. Use of the archive is restricted to research of a business or technical nature. Any other uses are prohibited. Full details are available on our policy page. If you have questions about this, please contact [javascript protected email address].

Operating expenses for this site are earned using the Amazon Associate program and Google Adsense.