Here is an example to show how to handle division by zero error in RPG program
dMyPsds sds - Define a variable of type *STATUS to capture return status of the progam
dStatus *status
derror_lineno 21 28 - To capture line on which error has occured
dnstatus s 4s 0 inz(0)
dArgum1 s 4s 0 inz(12)
dArgum2 s 4s 0 inz(0)
dResult s 4s 0 inz(0)
dRestrPoint s 6a
dATemp s 4s 0 inz(0)
c '-+-+-+-+' Dsply
c 'Begin...' Dsply
c '-+-+-+-+' Dsply
c Opr1 Tag
c Eval Result = Argum1 / Argum2 - this will result in error and Arg2 is Zero
c Result Dsply
c 'Hurry ' Dsply
c Eval *inlr = *on
c Return
c*
c*defining Pssr subroutine to handle exception condition
c *pssr BEGSR
c Move status nstatus
c Move error_lineno ATemp
c* is the error divide by zero ? ie 102 ?
c If nstatus = 102
c Eval Argum2=2 The value of Argum2 is changed to 2
c Else
c* error is not a divide by zero End program.
c Eval RestrPoint = '*CANCL'
c Endif
c If RestrPoint <> '*CANCL'
c goto Opr1
c Endif
c Endsr RestrPoint
OUTPUT :
DSPLY -+-+-+-+
DSPLY Start..
DSPLY -+-+-+-+
DSPLY 6
Thursday, January 8, 2009
Subscribe to:
Posts (Atom)
