Sunteți pe pagina 1din 14

Passing Parameters

Part 13

Presentation Copyright 2008, Bryan Meyers, www.bmeyers.net


What Are Parameters?

A calling program can share data with a called


program
CALL, CALLPRC, TFRCTL commands
Specify parameter variables or literals
(constants) in PARM parameter
CALL, TFRCTL can pass up to 255 parameters
CALLPRC can pass up to 300 parameters
PGMA: PGM
DCL &name *CHAR 10 VALUE('BOB')
CALL PGMB PARM(&name)
RETURN
ENDPGM
Defining Parameters
in a Called Program/Procedure
Use PGM statement to accept parameters
Parameters must be accepted into variables
Can accept up to 255 parameters
Number of parameters and order must match
CALL
PGMA: PGM
DCL &name *CHAR 10 VALUE('BOB')
CALL PGMB PARM(&name)
RETURN PGMB: PGM PARM(&name)
ENDPGM DCL &name *CHAR 10
SNDPGMMSG (My name is *CAT &name)
RETURN
ENDPGM
Defining Parameters
in a Called Program/Procedure
Declare each parameter variable
DCL type and length must match declaration in
calling program/procedure
Declared order and names not significant
Cannot assign initial VALUE
PGMA: PGM
DCL &name *CHAR 10 VALUE('BOB')
CALL PGMB PARM(&name)
RETURN PGMB: PGM PARM(&name)
ENDPGM DCL &name *CHAR 10
SNDPGMMSG (My name is *CAT &name)
RETURN
ENDPGM
Passing Character Constants

CALL, CALLPRC can pass a character constant


instead of a variable
Called program/procedure will receive
parameter into a variable
PGMA: PGM
CALL PGMB PARM('Monday' 'Tuesday' 'Wednesday')
RETURN
PGMB: PGM PARM(&day1 &day2 &day3)
ENDPGM
DCL &day1 *CHAR 9
DCL &day2 *CHAR 9
DCL &day3 *CHAR 9

ENDPGM
Passing Character Constants

Called program/procedure must declare


parameter as *CHAR
Should be long enough to hold longest value
Constant is left-adjusted
Padded or truncated if necessary
PGMA: PGM
CALL PGMB PARM('Monday' 'Tuesday' 'Wednesday')
RETURN
PGMB: PGM PARM(&day1 &day2 &day3)
ENDPGM
DCL &day1 *CHAR 9
DCL &day2 *CHAR 9
DCL &day3 *CHAR 9

ENDPGM
Passing Character Constants

Character constants are passed with a


minimum length of 32 characters
Or actual length, if longer than 32 characters
CALL MYPGM PARM('Mary' 'Heather' +
'Character constant longer than 32')

MYPGM: PGM PARM(&parm1 &parm2 &parm3)


DCL &parm1 *CHAR 10 /* 'Mary ' (Padded) */
DCL &parm2 *CHAR 5 /* 'Heath' (Truncated) */
DCL &parm3 *CHAR 33 /* 'Character constant longer than 32' */

ENDPGM
Passing Character Constants

Never declare character parameter longer


than 32 unless you will always pass the correct
number of characters
CALL MYPGM PARM('Here is a potential problem' +
'Character constant longer than 32')

MYPGM: PGM PARM(&parm1 &parm2)


DCL &parm1 *CHAR 40 /* 'Here is a potential problem Characte' */
DCL &parm2 *CHAR 33 /* 'Character constant longer than 32' */

ENDPGM
Passing Logical Constants

Logical constants use same rules as character


constants
Passed as 32 characters, padded
PGMA: PGM
CALL PGMB PARM('1' '0')
RETURN
ENDPGM

PGMB: PGM PARM(&parm1 &parm2)


DCL &parm1 *LGL
DCL &parm2 *LGL

ENDPGM
Passing Numeric Constants

Must declare receiving variable with data type


*DEC (15 5)
Decimal point is aligned in receiving variable
PGMA: PGM
CALL PGMB PARM(5 3.1416 129.95)
RETURN
ENDPGM

PGMB: PGM PARM(&parm1 &parm2 &parm3)


DCL &parm1 *DEC (15 5) /* 0000000005.00000 */
DCL &parm2 *DEC (15 5) /* 0000000003.14160 */
DCL &parm3 *DEC (15 5) /* 0000000129.95000 */

ENDPGM
Passing Variables

By default, parameters are passed by reference


Both programs/procedures share same storage
Changes made to parameter variables in called
program/procedure are reflected in caller
Changes made to parameters passed as constants
are not recognized
PGMA: PGM
DCL &name *CHAR 10 VALUE('BOB') PGMB: PGM PARM(&who)
CALL PGMB PARM(&name) DCL &who *CHAR 10
/* &name = 'Jim ' */ /* &who = 'BOB ' */
RETURN CHGVAR &who 'Jim'
ENDPGM RETURN
ENDPGM
Passing Parameters
with TFRCTL
If TFRCTL passes parameters, they must be
variables
Constants are not allowed
Parameter variables must have been received
initially as parameters by the program
executing TFRCTL
PGMA: PGM PARM(&name)
DCL &name *CHAR 10
TFRCTL PGMB PARM(&name)
RETURN
ENDPGM
Passing Parameters
with SBMJOB
SBMJOB translates parameter variables to
constants in submitted program
Must consider rules for passing constants
PGM
DCL &name *CHAR 10 VALUE('BOB')
DCL &number *DEC (5 2) VALUE(129.95)

SBMJOB CMD(CALL PGMA PARM(&name &number))
RETURN
ENDPGM
PGMA: PGM PARM(&name &number)
DCL &name *CHAR 10
DCL &number *DEC (15 5)

ENDPGM
Using Hexadecimal Notation

Hexadecimal values use typed literals


Preceded by X
Hexadecimal value in quoted string
Commonly used to emulate packed decimal
Avoids *DEC (15 5) requirement for constant
parameter values
Value can contain only 0-9 and trailing sign
Sign must be F for positive value, D for negative
CALL MYPGM PARM(X'31416F')
CALL MYPGM PARM(X'0012995F')
CALL MYPGM PARM(X'12995D')

S-ar putea să vă placă și