IBM AS/400 manual Avoiding

Models: AS/400

1 489
Download 489 pages 47.95 Kb
Page 259
Image 259
Avoiding

 

*-----------------------------------------------------------------

 

*

 

* Start of subprocedure definition

 

 

*-----------------------------------------------------------------

 

*

P SubProc

B

 

 

D SubProc

PI

5P 0

 

 

...

 

 

 

 

*-----------------------------------------------------------------

 

*

 

* Body of code goes here including division operation.

 

*-----------------------------------------------------------------

 

*

C

X

DIV

Divisor

Result

C

 

Return

Result

 

 

*-----------------------------------------------------------------

 

*

 

* An error occurs when division by zero takes place.

 

* Control is passed to the *PSSR subroutine.

 

*-----------------------------------------------------------------

 

*

C

*PSSR

BEGSR

 

 

 

*-----------------------------------------------------------------

 

*

 

* If this is a divide-by-zero error, return 0 from the subproc￿edure

 

*-----------------------------------------------------------------

 

*

C

 

IF

Err = 102

 

C

 

RETURN

0

 

C

 

ENDIF

 

 

 

*-----------------------------------------------------------------

 

*

 

* If control reaches ENDSR, the procedure will fail

 

*-----------------------------------------------------------------

 

*

C

 

ENDSR

 

 

P

 

E

 

 

Figure 114. Example of Subprocedure *PSSR Subroutine with RETURN

Avoiding

a

Loop

in

an

Error

Subroutine

 

 

 

 

 

 

 

 

 

 

 

 

 

In the previous example, it is unlikely that

an

error

would

occur

in

thereby

cause

a

loop.

However,

depending

on

how the *PSSR is written

occur

if

an

exception

occurs

while

processing the

*PSSR.

 

 

 

 

One

way

to

avoid

such

a

loop

is

to

set

a

first-time

switch

in

the

not

the first

time

 

through the subroutine,

you

can

specify

an

appro

point, such as *CANCL, for

the

Factor

2

entry

of

the ENDSR

operation.

Figure 115

on

page 236

shows

a

program

NOLOOP

which is designed to ge

exceptions in

order

to

show how to avoid looping

within

a

*PSSR

subrou

program

generates an

exception

twice:

 

 

 

 

 

 

 

 

 

 

1. In the main body of the code, to pass control to the *PSSR

2. Inside the *PSSR to potentially cause a loop.

Chapter 12. Handling Exceptions235

Page 259
Image 259
IBM AS/400 manual Avoiding