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')
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' */
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)
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')