IBM AS/400 manual Move

Models: AS/400

1 489
Download 489 pages 47.95 Kb
Page 260
Image 260

 

*=================================================================*

 

* NOLOOP:

Show how to avoid

recursion in a *PSSR subroutine.

 

*

 

*=================================================================*

 

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

 

 

 

 

 

*

 

* Array that will be used to

cause an error

 

 

*

 

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

 

 

 

 

 

*

D Arr1

 

S

10A

DIM(5)

 

 

 

 

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

 

 

 

 

 

*

 

* Generate an array out of bounds error to pass control to *P￿SSR. *

 

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

 

 

 

 

 

*

C

 

 

Z-ADD

-1

 

Neg1

5 0

 

C

 

 

MOVE

Arr1(Neg1)

Arr1(Neg1)

 

 

C

 

 

MOVE

*ON

 

*INLR

 

 

 

*=================================================================*

 

* *PSSR: Error Subroutine for the procedure. We use the

 

*

 

*

variable InPssr to detect recursion in the PSSR.

 

*

 

*

If we detect recursion, then we *CANCL the procedure.

*

 

*=================================================================*

C

*PSSR

BEGSR

 

 

 

 

 

C

 

 

IF

InPssr = 1

 

 

 

C

 

 

MOVE

'*CANCL'

 

ReturnPt

6

 

C

 

 

Z-ADD

0

 

InPssr

1 0

 

C

 

 

ELSE

 

 

 

 

 

C

 

 

Z-ADD

1

 

InPssr

 

 

 

*

 

 

 

 

 

 

*

 

*

 

We now generate another error in the PSSR to see

 

*

 

*

 

how the subroutine

cancels the procedure.

 

*

 

*

 

 

 

 

 

 

*

C

 

 

MOVE

Arr1(Neg1)

Arr1(Neg1)

 

 

 

*

 

 

 

 

 

 

*

 

*

 

Note that the next

two operations will not be

 

*

 

*

 

processed if Neg1 is still negative.

 

*

 

*

 

 

 

 

 

 

*

C

 

 

MOVE

'*GETIN'

 

ReturnPt

 

 

C

 

 

Z-ADD

0

 

InPssr

 

 

C

 

 

ENDIF

 

 

 

 

 

C

 

 

ENDSR

ReturnPt

 

 

 

 

 

 

 

 

 

Figure

115.

Avoiding a Loop in an Error Subroutine

 

 

To create the program and start debugging it, using the source in Fig

CRTBNDRPG PGM(MYLIB/NOLOOP) DBGVIEW(*SOURCE)

STRDBG PGM(MYLIB/NOLOOP)

Set a break point on the BEGSR line of the *PSSR subroutine so you can through the *PSSR subroutine.

When you call the program, the following occurs:

 

1. An

exception

occurs

when the

program

tries

to do a MOVE operation

 

array

using

a

negative

index.

Control is passed to the *PSSR.

 

 

2. Since

this

 

is

the

first time through the *PSSR, the variable In_Pss

 

already

set

on.

To

prevent

a

future

loop,

the variable In_Pssr is

 

3. Processing

continues

within

the

*PSSR

with

the

MOVE

after the ELSE.

Aga

 

an

exception

occurs

and

so

processing

of the *PSSR

begins anew.

 

 

4. This

time

through,

the variable In_Pssr

is

already set to 1. Sinc

 

that

the

 

subroutine

is

in

a

loop,

the

procedure

is canceled by

s

 

ReturnPt

field

to

*CANCL.

 

 

 

 

 

 

 

 

 

236

ILE RPG for AS/400 Programmer's

Guide

 

 

 

 

 

 

 

 

 

 

 

 

Page 260
Image 260
IBM AS/400 manual Move