IBM AS/400 manual Checking for the Number, Passing Prototyped Parameters, Passed

Models: AS/400

1 489
Download 489 pages 47.95 Kb
Page 165
Image 165

Passing Prototyped Parameters

Checking for the Number

of

Passed

 

Parameters

 

 

 

 

 

 

 

 

 

 

 

 

 

At

times

it

may

be necessary to check for the number of parameter

passed on a call. Depending

on

 

how the procedure has been

written,

may

allow

you

to

avoid references to parameters that are not passe

suppose that you want to write a procedure which will sometimes be

parameters and

sometimes

four parameters. This might arise when

a

ne

eter is required. You can write the called procedure to process

depending

on

the

value

that

is

 

returned by the built-in

function

%PARMS

may

pass

the

parameter.

Old calls can remain unchanged.

 

 

 

 

 

%PARMS does not take any

 

parameters.

The

value returned

by

%PARMS

also

includes

any

parameters

 

for which *OMIT has been passed. For

the ma

dure,

%PARMS

returns

the

same

value as contained

in

the

*PARMS field

in

PSDS,

although

to

use

the

*PARMS

field,

you must

also

code

the

PSDS.

For

both

*PARMS

and

%PARMS,

 

if the number of passed parameters

is

not

known, the

value -1

is

returned.

(In order to determine the

number

passed,

a

minimal

operational descriptor must be passed. ILE

RPG

alwa

one

on

a

call; however other ILE languages may not.) If the

main

pro

active, *PARMS is unreliable. It is not recommended to reference *PARMS

subprocedure.

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

Using %PARMS

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

In

this

example,

a

procedure

FMTADDR

has

been

changed

several

times

for

a

change

in

the address information for the employees of a

co

FMTADDR

is

called by three different procedures. The procedures di

number of parameters they use to process the employee information.

requirements

for

the

FMTADDR

have

arisen, and to support them,

new

pa

have been added. However, old

procedures calling

FMTADDR are

still

su

and

do not

have

to

be

changed

or

recompiled.

 

 

 

 

 

 

 

The changes to the employee address can be summarized as follows:

¹Initially only the street name and number were required because

lived in the same city. Thus, the city and province could be su

¹At a later point, the company expanded, and so the city informati

variable for some company-wide applications.

¹Further expansion resulted in variable province information.

The procedure processes the information based

on the

number

of

para

passed. The

number

may

vary

from 3

to 5.

The

number

tells the

progr

to provide

default

city

or

province

values

or

both.

Figure 68

on

pag

the source for this procedure. Figure 69 on page 143

shows

the

sour

member containing the

prototype.

 

 

 

 

 

 

The main logic of FMTADDR is as follows:

1. Check

to see how many parameters

were

passed

by using

%PARMS. Thi

built-in

function

returns

the number

of

passed

parameters.

 

¹ If

the number is greater than

4,

then the

default

province

the

actual

province

supplied by

the

fifth

parameter

P_Province.

¹If the number is greater than 3, then the default city is actual city supplied by the fourth parameter P_City.

Chapter 10. Calling Programs and Procedures141

Page 165
Image 165
IBM AS/400 manual Checking for the Number, Passing Prototyped Parameters, Passed