IBM AS/400 manual Calling within an Expression, Using a Prototyped Call

Models: AS/400

1 489
Download 489 pages 47.95 Kb
Page 158
Image 158
Using a Prototyped Call

Using a Prototyped Call

To call a prototyped program or procedure follow these general steps:

1.Include the prototype of the program or procedure to be called specifications.

2.Enter the prototype name of the program or procedure in the exte

 

field, followed by the parameters if any, within parentheses. Separ

 

parameters with

a

colon

(:).

Factor

1

must

be

blank.

The

following

example shows

a call to a procedure Switch, which changes

of

the

indicator

that

is

passed to it,

in

this

case *IN10..

 

C

 

 

CALLP

Switch(*in10)

 

 

 

 

A maximum

of

255 parameters

are

allowed

on

a

program call, and a maximum

399

for

a

procedure

call.

 

 

 

 

 

 

You can use CALLP from anywhere within the module. If the keyword EXTPG specified on the prototype, the call will be a dynamic external call; be a bound procedure call.

Note

that

if CALLP is used to call a

procedure

which returns

a

value,

not be available to the caller. If

the value

is required,

call

the

within

an

expression.

 

 

 

 

Calling within an Expression

If a

prototyped

procedure is defined to return a

value

then

you mu

dure within an expression if you want to make use of

the

return

valu

procedure name in

a manner that is consistent with the

data type

of

return

value. For

example, if a procedure is defined

to

return

a

num

call to the procedure within an expression must be where a numeric wo expected.

Figure 61 shows the prototype for a procedure CVTCHR that takes a nume parameter and returns a character string. Figure 62 shows how the proc might be used in an expression.

*Prototype for CVTCHR

*- returns a character representation of the numeric param￿eter

 

* Examples: CVTCHR(5) returns '5

'

 

 

*

CVTCHR(15-124) returns '-109

'

D CVTCHR

PR

31A

 

 

D

NUM

 

30P 0

VALUE

 

 

 

 

 

 

 

Figure

61.

Prototype for CVTCHR

 

 

 

 

 

 

 

 

 

C

 

EVAL

STRING =

'Address: ' +

 

C

 

 

 

%TRIM(CVTCHR(StreetNum))

C

 

 

 

+ ' ' + StreetName

 

 

* If STREETNUM = 427 and STREETNAME =

'Mockingbird Lane', afte￿r the

 

* EVAL operation STRING = 'ADDRESS: 427 Mockingbird Lane'

 

 

 

 

 

Figure

62.

Calling a Prototyped Procedure within an Expression

 

134 ILE RPG for AS/400 Programmer's Guide

Page 158
Image 158
IBM AS/400 manual Calling within an Expression, Using a Prototyped Call