Look at the two programs in Figures 7 and 8. At first glance, you would think that PGM2 would have the following two parameter values: &X (containing the value 'FIRST' followed by trailing blanks) and &Y (containing the value 'SECOND' followed by trailing blanks). Wrong?&X and &Y will contain a mess!
Usually, when a program calls another program directly, the system passes character parameters by address. This allows the called program to access the same data passed by the calling program. However, when a program submits another one to batch, the system makes a copy of the parameters. Unfortunately, this copy contains only the used part of the parameters or the first 33 bytes, whichever is less. Past that point, the results are very unpredictable. This area usually contains hexadecimal garbage.
To avoid this problem, I usually declare the parameter variables in the calling program one character longer than in the called program and put a nonblank character in the last position. For example, in PGM1, this is what I would code:
DCL VAR(&A) TYPE(*CHAR) LEN(501) CHGVAR VAR(%SST(&A 501 1)) + VALUE('.') As a result, the system is forced to make a copy of the whole variable. There is no problem if a character parameter is defined longer in the calling program than in the called program. This solves the problem by ensuring that the correct data is passed between the two programs.
? Sorin Caraiani
TechTalk: Passing Parameters to a Batch Job
Figure 7: Program PGM1
PGM DCL VAR(&A) TYPE(*CHAR) LEN(500) DCL VAR(&B) TYPE(*CHAR) LEN(500) CHGVAR VAR(&A) VALUE('FIRST') CHGVAR VAR(&B) VALUE('SECOND') SBMJOB CMD(CALL PGM(PGM1) PARM(&A &B)) ENDPGM
TechTalk: Passing Parameters to a Batch Job
Figure 8: Program PGM2
PGM PARM(&X &Y) DCL VAR(&X) TYPE(*CHAR) LEN(500) DCL VAR(&Y) TYPE(*CHAR) LEN(500) . . . ENDPGM
Business users want new applications now. Market and regulatory pressures require faster application updates and delivery into production. Your IBM i developers may be approaching retirement, and you see no sure way to fill their positions with experienced developers. In addition, you may be caught between maintaining your existing applications and the uncertainty of moving to something new.
IT managers hoping to find new IBM i talent are discovering that the pool of experienced RPG programmers and operators or administrators with intimate knowledge of the operating system and the applications that run on it is small. This begs the question: How will you manage the platform that supports such a big part of your business? This guide offers strategies and software suggestions to help you plan IT staffing and resources and smooth the transition after your AS/400 talent retires. Read on to learn:
LATEST COMMENTS
MC Press Online