-
Notifications
You must be signed in to change notification settings - Fork 20
/
QSHCALLC.CLLE
497 lines (445 loc) · 25.1 KB
/
QSHCALLC.CLLE
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
PGM PARM(&CMDLINE &SETPKGPATH &DSPSTDOUT +
&LOGSTDOUT &PRTSTDOUT &DLTSTDOUT +
&IFSSTDOUT &IFSFILE &IFSOPT &CCSID +
&PRTSPLF &PRTUSRDTA &PRTTXT &PRTHOLD +
&PRTOUTQALL &OUTFILE &MBROPT &PASEJOBNAM +
&RETURN01 &RETURN02 &RETURN03 &RETURN04 +
&RETURN05 &RETURN06 &RETURN07 &RETURN08 +
&RETURN09 &RETURN10)
/*----------------------------------------------------------------------------*/
/* Variables */
/*----------------------------------------------------------------------------*/
DCL VAR(&RETURN01) TYPE(*CHAR) LEN(255)
DCL VAR(&RETURN02) TYPE(*CHAR) LEN(255)
DCL VAR(&RETURN03) TYPE(*CHAR) LEN(255)
DCL VAR(&RETURN04) TYPE(*CHAR) LEN(255)
DCL VAR(&RETURN05) TYPE(*CHAR) LEN(255)
DCL VAR(&RETURN06) TYPE(*CHAR) LEN(255)
DCL VAR(&RETURN07) TYPE(*CHAR) LEN(255)
DCL VAR(&RETURN08) TYPE(*CHAR) LEN(255)
DCL VAR(&RETURN09) TYPE(*CHAR) LEN(255)
DCL VAR(&RETURN10) TYPE(*CHAR) LEN(255)
DCL VAR(&PASEJOBNAM) TYPE(*CHAR) LEN(10)
DCL VAR(&MBROPT) TYPE(*CHAR) LEN(10)
DCL VAR(&OUTFILE) TYPE(*CHAR) LEN(20)
DCL VAR(&OUTFILPATH) TYPE(*CHAR) LEN(255)
DCL VAR(&OFILE) TYPE(*CHAR) LEN(10)
DCL VAR(&OLIB) TYPE(*CHAR) LEN(10)
DCL VAR(&PRTHOLD) TYPE(*CHAR) LEN(4)
DCL VAR(&PRTOUTQALL) TYPE(*CHAR) LEN(20)
DCL VAR(&PRTOUTQ) TYPE(*CHAR) LEN(10)
DCL VAR(&PRTOUTQLIB) TYPE(*CHAR) LEN(10)
DCL VAR(&SETPKGPATH) TYPE(*CHAR) LEN(4)
DCL VAR(&CMDLINE) TYPE(*CHAR) LEN(5000)
DCL VAR(&INPUTFILE) TYPE(*CHAR) LEN(255)
DCL VAR(&USERPW) TYPE(*CHAR) LEN(100)
DCL VAR(&OWNERPW) TYPE(*CHAR) LEN(100)
DCL VAR(&PDFOPTS) TYPE(*CHAR) LEN(8)
DCL VAR(&REPLACE) TYPE(*CHAR) LEN(4)
DCL VAR(&TEMPLATE) TYPE(*CHAR) LEN(255)
DCL VAR(&OUTPUTFILE) TYPE(*CHAR) LEN(255)
DCL VAR(&OUTPUTTYPE) TYPE(*CHAR) LEN(10)
DCL VAR(&PARMS) TYPE(*CHAR) LEN(2048)
DCL VAR(&PARMLIST) TYPE(*CHAR) LEN(1024)
DCL VAR(&PGMPARMS1) TYPE(*CHAR) LEN(256) VALUE(' ')
DCL VAR(&PGMPARMS2) TYPE(*CHAR) LEN(256) VALUE(' ')
DCL VAR(&PGMPARMS3) TYPE(*CHAR) LEN(256) VALUE(' ')
DCL VAR(&PGMPARMS4) TYPE(*CHAR) LEN(256) VALUE(' ')
DCL VAR(&TYPE) TYPE(*CHAR) LEN(1)
DCL VAR(&CURDIR) TYPE(*CHAR) LEN(128)
DCL VAR(&CDLEN) TYPE(*DEC) LEN(7 0)
DCL VAR(&OUTPUTDST) TYPE(*CHAR) LEN(10) VALUE('*NONE')
DCL VAR(&OUTPUTACT) TYPE(*CHAR) LEN(10) VALUE('*N')
DCL VAR(&QSHRTN) TYPE(*DEC) LEN(5 0)
DCL VAR(&QSHRTNC) TYPE(*CHAR) LEN(5)
DCL VAR(&MSGDTA) TYPE(*CHAR) LEN(200)
DCL VAR(&MSGDTA4) TYPE(*CHAR) LEN(4)
DCL VAR(&CPFID) TYPE(*CHAR) LEN(7)
DCL VAR(&CMD) TYPE(*CHAR) LEN(9999)
DCL VAR(&STDOUTIFS) TYPE(*CHAR) LEN(255)
DCL VAR(&STDOUTFILE) TYPE(*CHAR) LEN(255)
DCL VAR(&JOB) TYPE(*CHAR) LEN(10)
DCL VAR(&JOBNBR) TYPE(*CHAR) LEN(6)
DCL VAR(&USER) TYPE(*CHAR) LEN(10)
DCL VAR(&TEMPDIR) TYPE(*CHAR) LEN(255) +
VALUE('/tmp')
DCL VAR(&QSHTEMP) TYPE(*CHAR) LEN(255) +
VALUE('/tmp/qsh')
DCL VAR(&DSPSTDOUT) TYPE(*CHAR) LEN(4)
DCL VAR(&LOGSTDOUT) TYPE(*CHAR) LEN(4)
DCL VAR(&DLTSTDOUT) TYPE(*CHAR) LEN(4)
DCL VAR(&PRTSTDOUT) TYPE(*CHAR) LEN(4)
DCL VAR(&IFSSTDOUT) TYPE(*CHAR) LEN(4)
DCL VAR(&IFSOPT) TYPE(*CHAR) LEN(10)
DCL VAR(&IFSFILE) TYPE(*CHAR) LEN(255)
DCL VAR(&RTNVAL) TYPE(*CHAR) LEN(6)
DCL VAR(&CURJOB) TYPE(*CHAR) LEN(10)
DCL VAR(&CURUSER) TYPE(*CHAR) LEN(10)
DCL VAR(&CURNBR) TYPE(*CHAR) LEN(6)
DCL VAR(&QDATE) TYPE(*CHAR) LEN(6)
DCL VAR(&QTIME) TYPE(*CHAR) LEN(9)
DCL VAR(&PRTSPLF) TYPE(*CHAR) LEN(10)
DCL VAR(&PRTUSRDTA) TYPE(*CHAR) LEN(10)
DCL VAR(&PRTTXT) TYPE(*CHAR) LEN(30)
DCL VAR(&CCSID) TYPE(*CHAR) LEN(10)
/*----------------------------------------------------------------------------*/
/* MONITOR FOR GLOBAL ERROR. ANY ERROR IS A CAUSE TO BLOW OUT OF HERE */
/* AND WE WANT A GRACEFUL EXIT. */
/*----------------------------------------------------------------------------*/
MONMSG MSGID(CPF0000) EXEC(GOTO CMDLBL(ERRORS))
/*----------------------------------------------------------------------------*/
/* MAIN */
/*----------------------------------------------------------------------------*/
/*----------------------------------------------------------------------------*/
/* Init return parm values */
/*----------------------------------------------------------------------------*/
CHGVAR VAR(&RETURN01) VALUE(' ')
CHGVAR VAR(&RETURN02) VALUE(' ')
CHGVAR VAR(&RETURN03) VALUE(' ')
CHGVAR VAR(&RETURN04) VALUE(' ')
CHGVAR VAR(&RETURN05) VALUE(' ')
CHGVAR VAR(&RETURN06) VALUE(' ')
CHGVAR VAR(&RETURN07) VALUE(' ')
CHGVAR VAR(&RETURN08) VALUE(' ')
CHGVAR VAR(&RETURN09) VALUE(' ')
CHGVAR VAR(&RETURN10) VALUE(' ')
/*----------------------------------------------------------------------------*/
/* Create return code data area */
/*----------------------------------------------------------------------------*/
CHKOBJ OBJ(QTEMP/QSHRTNCOD) OBJTYPE(*DTAARA)
MONMSG MSGID(CPF0000) EXEC(DO)
CRTDTAARA DTAARA(QTEMP/QSHRTNCOD) TYPE(*DEC) LEN(5 0) +
TEXT('QShell/Pase Return Code')
ENDDO
CHGDTAARA DTAARA(QTEMP/QSHRTNCOD *ALL) VALUE(0)
/*----------------------------------------------------------------------------*/
/* Create stdout IFS file data area */
/* Only useful if you set DLTSTDOUT(*NO) */
/*----------------------------------------------------------------------------*/
CHKOBJ OBJ(QTEMP/STDOUTIFS) OBJTYPE(*DTAARA)
MONMSG MSGID(CPF0000) EXEC(DO)
CRTDTAARA DTAARA(QTEMP/STDOUTIFS) TYPE(*CHAR) LEN(255) +
TEXT('QShell/Pase IFS File for Temporary +
STDOUT')
ENDDO
CHGDTAARA DTAARA(QTEMP/STDOUTIFS *ALL) VALUE(' ')
/*----------------------------------------------------------------------------*/
/* Extract output queue info. */
/*----------------------------------------------------------------------------*/
CHGVAR VAR(&PRTOUTQ) VALUE(%SST(&PRTOUTQALL 1 10))
CHGVAR VAR(&PRTOUTQLIB) VALUE(%SST(&PRTOUTQALL 11 10))
/*----------------------------------------------------------------------------*/
/* Extract output file info. */
/*----------------------------------------------------------------------------*/
CHGVAR VAR(&OFILE) VALUE(%SST(&OUTFILE 1 10))
CHGVAR VAR(&OLIB) VALUE(%SST(&OUTFILE 11 10))
/*----------------------------------------------------------------------------*/
/* Build soft coded OUTFILE IFS style path in QTEMP - Added V1.0.16 */
/*----------------------------------------------------------------------------*/
CHGVAR VAR(&OUTFILPATH) VALUE('/QSYS.LIB/' |< &OLIB +
|< '.LIB/' |< &OFILE |< '.FILE/' |< +
&OFILE |< '.MBR')
/*----------------------------------------------------------------------------*/
/* If copying results to IFS and IFS file is blank, bail out. */
/*----------------------------------------------------------------------------*/
IF COND(&IFSSTDOUT *EQ *YES) THEN(DO)
IF COND(&IFSFILE *EQ ' ') THEN(SNDPGMMSG +
MSGID(CPF9898) MSGF(QCPFMSG) +
MSGDTA('IFSSTDOUT was set to *YES, but no +
IFS file was specified. QSHCALL +
cancelled') MSGTYPE(*ESCAPE))
ENDDO
/*----------------------------------------------------------------------------*/
/* Set environment path for QOpenSys packages if selected */
/* before running any PASE/QSH commands. */
/*----------------------------------------------------------------------------*/
IF COND(&SETPKGPATH *EQ '*YES') THEN(DO)
QSHPATH PKGPATH(*DEFAULT)
ENDDO
/*----------------------------------------------------------------------------*/
/* Create temp folder in /tmp named /tmp/qsh for stdout logs */
/*----------------------------------------------------------------------------*/
MKDIR DIR(&QSHTEMP) DTAAUT(*RWX) OBJAUT(*ALL)
MONMSG MSGID(CPF0000)
/*----------------------------------------------------------------------------*/
/* RETRIEVE JOB DATE/TIME INFO */
/*----------------------------------------------------------------------------*/
RTVSYSVAL SYSVAL(QDATE) RTNVAR(&QDATE)
RTVSYSVAL SYSVAL(QTIME) RTNVAR(&QTIME)
RTVJOBA JOB(&CURJOB) USER(&CURUSER) NBR(&CURNBR)
/*----------------------------------------------------------------------------*/
/* DOUBLE CHECK TO MAKE SURE OUTFILE LIBRARY EXISTS. IF NOT BAIL OUT. */
/*----------------------------------------------------------------------------*/
CHKOBJ OBJ(QSYS/&OLIB) OBJTYPE(*LIB)
MONMSG MSGID(CPF0000) EXEC(DO)
SNDPGMMSG MSGID(CPF9898) MSGF(QCPFMSG) MSGDTA('Output +
library' |> &OLIB |> 'does not exist. +
QSHCALL command cancelled') TOPGMQ(*PRV) +
MSGTYPE(*ESCAPE)
ENDDO
/*----------------------------------------------------------------------------*/
/* CREATE TEMPORARY OUTPUT FILE TO HOLD STDOUT RESULTS IF NOT FOUND ALREADY */
/*----------------------------------------------------------------------------*/
CHKOBJ OBJ(&OLIB/&OFILE) OBJTYPE(*FILE)
/* If file object not found, attempt to create it */
MONMSG MSGID(CPF9801) EXEC(DO)
CRTPF FILE(&OLIB/&OFILE) RCDLEN(1000) TEXT('QShell +
STDOUT Output') OPTION(*NOLIST *NOSRC) +
MAXMBRS(*NOMAX) SIZE(*NOMAX)
MONMSG MSGID(CPF0000)
ENDDO
/*----------------------------------------------------------------------------*/
/* DOUBLE CHECK TO MAKE SURE OUTFILE EXISTS NOW. IF NOT, BAIL OUT NOW. */
/*----------------------------------------------------------------------------*/
CHKOBJ OBJ(&OLIB/&OFILE) OBJTYPE(*FILE)
MONMSG MSGID(CPF0000) EXEC(DO)
SNDPGMMSG MSGID(CPF9898) MSGF(QCPFMSG) MSGDTA('Output +
file' |> &OLIB |< '/' |< &OFILE |> 'does +
not exist. QSHCALL command cancelled') +
TOPGMQ(*PRV) MSGTYPE(*ESCAPE)
ENDDO
/*----------------------------------------------------------------------------*/
/* CLEAR TEMPORARY QSH OUTPUT FILE IF NOT APPENDING TO IT */
/* BAIL OUT IF WE CANNOT CLEAR OUTPUT FILE */
/*----------------------------------------------------------------------------*/
IF COND(&MBROPT *EQ *REPLACE) THEN(DO)
CLRPFM FILE(&OLIB/&OFILE)
ENDDO
/*----------------------------------------------------------------------------*/
/* BUILD PATH NAME FOR IFS STDOUT FILE */
/*----------------------------------------------------------------------------*/
RTVJOBA JOB(&JOB) USER(&USER) NBR(&JOBNBR)
CHGVAR VAR(&STDOUTIFS) VALUE(&QSHTEMP |< +
'/STDOUTQSH-' |< &JOB |< '-' |< &USER +
|< '-' |< &JOBNBR |< '-' |< &QDATE |< +
&QTIME |< '.TXT')
/* Save STDOUTIFS file name to data area */
CHGDTAARA DTAARA(QTEMP/STDOUTIFS *ALL) VALUE(&STDOUTIFS)
/*----------------------------------------------------------------------------*/
/* ERASE QSHELL CMD OUTPUT IF IT EXISTS */
/*----------------------------------------------------------------------------*/
ERASE OBJLNK(&STDOUTIFS)
MONMSG MSGID(CPF0000)
/*----------------------------------------------------------------------------*/
/* SET THE IFS PATH TO STORE QSHELL OUTPUT FOR */
/* REVIEW IF NEEDED. */
/*----------------------------------------------------------------------------*/
CHGVAR VAR(&STDOUTFILE) VALUE('FILE=' |< &STDOUTIFS)
/*----------------------------------------------------------------------------*/
/* Set the PASE_FORK_JOBNAME env variable to set thread job names. */
/* Has TR requiremnents */
/*----------------------------------------------------------------------------*/
IF COND(&PASEJOBNAM *NE *DEFAULT) THEN(DO)
ADDENVVAR ENVVAR('PASE_FORK_JOBNAME') +
VALUE(&PASEJOBNAM) REPLACE(*YES)
SNDPGMMSG MSGID(CPF9898) MSGF(QCPFMSG) +
MSGDTA('Environment variable +
PASE_FORK_JOBNAME is set to:' |> +
&PASEJOBNAM) TOPGMQ(*SAME) MSGTYPE(*DIAG)
ENDDO
IF COND(&PASEJOBNAM *EQ *DEFAULT) THEN(DO)
RMVENVVAR ENVVAR('PASE_FORK_JOBNAME')
MONMSG MSGID(CPF0000)
SNDPGMMSG MSGID(CPF9898) MSGF(QCPFMSG) +
MSGDTA('Environment variable +
PASE_FORK_JOBNAME removed') TOPGMQ(*SAME) +
MSGTYPE(*DIAG)
ENDDO
/*----------------------------------------------------------------------------*/
/* SET THE QSHELL STDOUT IFS FILE LOCATION */
/* ENVIRONMENT VARIABLE */
/*----------------------------------------------------------------------------*/
ADDENVVAR ENVVAR('QIBM_QSH_CMD_OUTPUT') +
VALUE(&STDOUTFILE) REPLACE(*YES)
ADDENVVAR ENVVAR(QIBM_MULTI_THREADED) VALUE(Y) +
REPLACE(*YES)
/*----------------------------------------------------------------------------*/
/* Make sure iTookit CL commands will work when using the */
/* DB2 connectivity by setting job CCSID to 37 */
/*----------------------------------------------------------------------------*/
IF COND(&CCSID *NE *SAME) THEN(DO)
CHGJOB CCSID(&CCSID)
ENDDO
/*----------------------------------------------------------------------------*/
/* BUILD THE FINAL QSH CALL */
/*----------------------------------------------------------------------------*/
CHGVAR VAR(&CMD) VALUE(&CMDLINE)
/* CALL THE QSH COMMAND LINE */
QSH CMD(&CMDLINE)
/* READ AND PROCESS THE QSHELL RESPONSE */
/* TO DETERMINE QSH PROGRAM EXIT CODE */
NEXTCOMP: RCVMSG PGMQ(*SAME) MSGTYPE(*COMP) RMV(*NO) +
MSGDTA(&MSGDTA) MSGID(&CPFID)
/* IF MSGID IS BLANK, WE DIDN'T GET QSH0005 */
/* LIKE WE WERE SUPPSED TO. */
IF COND(&CPFID *EQ ' ') THEN(DO)
CHGVAR VAR(&QSHRTN) VALUE(9999)
CHGVAR VAR(&QSHRTNC) VALUE(&QSHRTN)
CHGDTAARA DTAARA(QTEMP/QSHRTNCOD *ALL) VALUE(&QSHRTN)
GOTO CMDLBL(DONECOMP) /* DONE WITH MSG LOOP */
ENDDO
/* QSH0005 IS THE RETURN RESPONSE FROM THE QSHELL PGM */
IF COND(&CPFID *EQ 'QSH0005') THEN(DO)
CHGVAR VAR(&MSGDTA4) VALUE(%SST(&MSGDTA 1 4))
CHGVAR VAR(&QSHRTN) VALUE(%BIN(&MSGDTA4))
CHGVAR VAR(&QSHRTNC) VALUE(&QSHRTN)
CHGDTAARA DTAARA(QTEMP/QSHRTNCOD *ALL) VALUE(&QSHRTN)
GOTO CMDLBL(DONECOMP) /* DONE WITH MSG LOOP */
ENDDO
GOTO CMDLBL(NEXTCOMP) /* GET NEXT MSG UNTIL QSH */
DONECOMP:
/* COPY STDOUT TO QTEMP OUTFILE AND APPEND OR REPLACE TO OUTFILE */
CPYFRMSTMF FROMSTMF(&STDOUTIFS) TOMBR(&OUTFILPATH) +
MBROPT(&MBROPT) CVTDTA(*AUTO) +
ENDLINFMT(*LF) STMFCODPAG(*STMF)
MONMSG MSGID(CPF0000) EXEC(DO)
SNDPGMMSG MSGID(CPF9898) MSGF(QCPFMSG) MSGDTA('Errors +
occurred while copying STDOUT log to +
file. Check the joblog') +
MSGTYPE(*ESCAPE)
ENDDO
/* If copying results to IFS, do it now */
/* We copy from STDOUTQSH in QTEMP to IFS log */
/* V1.0.10 - Added AUT(*INDOR) */
IF COND(&IFSSTDOUT *EQ *YES) THEN(DO)
CPYTOSTMF FROMMBR(&OUTFILPATH) TOSTMF(&IFSFILE) +
STMFOPT(&IFSOPT) CVTDTA(*AUTO) +
STMFCCSID(*PCASCII) ENDLINFMT(*LF) +
AUT(*INDIR) STMFCODPAG(*STMF)
/* Prevent endless loop if CPYTOSTMF fails */
MONMSG MSGID(CPF0000) EXEC(DO)
SNDPGMMSG MSGID(CPF9898) MSGF(QCPFMSG) MSGDTA('Error +
copying log to IFS file' |> &IFSFILE |> +
'- QSHCALL cancelled') MSGTYPE(*ESCAPE)
ENDDO
ENDDO
/* IF ENABLED, PRINT STDOUT RESULTS */
IF COND(&PRTSTDOUT *EQ *YES) THEN(DO)
/* PRINT STDOUT LOG NOW */
/* Override without specific outq */
IF COND(&PRTOUTQ *EQ *SAME) THEN(DO)
OVRPRTF FILE(QSYSPRT) TOFILE(QSYSPRT) PAGESIZE(198) +
PRTTXT(&PRTTXT) HOLD(&PRTHOLD) +
USRDTA(&PRTUSRDTA) SPLFNAME(&PRTSPLF)
ENDDO
IF COND(&PRTOUTQ *NE *SAME) THEN(DO)
/* Override with specific outq */
OVRPRTF FILE(QSYSPRT) TOFILE(QSYSPRT) PAGESIZE(198) +
PRTTXT(&PRTTXT) +
OUTQ(&PRTOUTQLIB/&PRTOUTQ) HOLD(&PRTHOLD) +
USRDTA(&PRTUSRDTA) SPLFNAME(&PRTSPLF)
ENDDO
CPYF FROMFILE(&OLIB/&OFILE) TOFILE(QSYSPRT)
DLTOVR FILE(QSYSPRT)
ENDDO
/* IF ENABLED, DISPLAY STDOUT RESULTS */
IF COND(&DSPSTDOUT *EQ *YES) THEN(DO)
EDTF STMF(&STDOUTIFS)
MONMSG MSGID(CPF0000)
ENDDO
/* IF ENABLED, Erase stdout result file */
IF COND(&DLTSTDOUT *EQ *YES) THEN(DO)
ERASE OBJLNK(&STDOUTIFS)
MONMSG MSGID(CPF0000)
ENDDO
/* Write STDOUT results PF to job log */
IF COND(&LOGSTDOUT *EQ *YES) THEN(DO)
OVRDBF FILE(STDOUTQSH) TOFILE(&OLIB/&OFILE)
CALL PGM(QSHSTDOUTR)
DLTOVR FILE(STDOUTQSH)
ENDDO
IF COND(&QSHRTN *NE 0) THEN(DO)
SNDPGMMSG MSGID(CPF9898) MSGF(QCPFMSG) MSGDTA('ERROR: +
QShell error' |> &QSHRTNC |> 'occurred +
while running command. Check +
the joblog') MSGTYPE(*ESCAPE)
ENDDO
/*----------------------------------------------------------------------------*/
/* Extract return parameter values from STDOUTQSH log file */
/*----------------------------------------------------------------------------*/
QSHGETPARM RETURN01(&RETURN01) RETURN02(&RETURN02) +
RETURN03(&RETURN03) RETURN04(&RETURN04) +
RETURN05(&RETURN05) RETURN06(&RETURN06) +
RETURN07(&RETURN07) RETURN08(&RETURN08) +
RETURN09(&RETURN09) RETURN10(&RETURN10)
SNDPGMMSG MSGID(CPF9898) MSGF(QCPFMSG) MSGDTA('QShell +
command completed and logged to outfile' +
|> &OLIB |< '/' |< &OFILE) MSGTYPE(*COMP)
RETURN
ERRORS:
/* COPY STDOUT TO QTEMP OUTFILE */
CPYFRMSTMF FROMSTMF(&STDOUTIFS) TOMBR(&OUTFILPATH) +
MBROPT(&MBROPT) CVTDTA(*AUTO) +
ENDLINFMT(*LF) STMFCODPAG(*STMF)
MONMSG MSGID(CPF0000) EXEC(DO)
SNDPGMMSG MSGID(CPF9898) MSGF(QCPFMSG) MSGDTA('Errors +
occurred while copying STDOUT log to +
file. Check the joblog') +
MSGTYPE(*ESCAPE)
ENDDO
/* If copying results to IFS, do it now */
/* We copy from STDOUTQSH in QTEMP to IFS log */
/* V1.0.10 - Added AUT(*INDOR) */
IF COND(&IFSSTDOUT *EQ *YES) THEN(DO)
CPYTOSTMF FROMMBR(&OUTFILPATH) TOSTMF(&IFSFILE) +
STMFOPT(&IFSOPT) CVTDTA(*AUTO) +
STMFCCSID(*PCASCII) ENDLINFMT(*LF) +
AUT(*INDIR) STMFCODPAG(*STMF)
/* Prevent endless loop if CPYTOSTMF fails */
MONMSG MSGID(CPF0000) EXEC(DO)
SNDPGMMSG MSGID(CPF9898) MSGF(QCPFMSG) MSGDTA('Error +
copying log to IFS file' |> &IFSFILE |> +
'- QSHCALL cancelled') MSGTYPE(*ESCAPE)
ENDDO
ENDDO
/* IF ENABLED, PRINT STDOUT RESULTS */
IF COND(&PRTSTDOUT *EQ *YES) THEN(DO)
/* PRINT STDOUT LOG NOW */
/* Override without specific outq */
IF COND(&PRTOUTQ *EQ *SAME) THEN(DO)
OVRPRTF FILE(QSYSPRT) TOFILE(QSYSPRT) PAGESIZE(198) +
PRTTXT(&PRTTXT) HOLD(&PRTHOLD) +
USRDTA(&PRTUSRDTA) SPLFNAME(&PRTSPLF)
/* Prevent endless loop if OVRPRTF fails */
MONMSG MSGID(CPF0000) EXEC(DO)
SNDPGMMSG MSGID(CPF9898) MSGF(QCPFMSG) MSGDTA('Error +
overriding print file - QSHCALL +
cancelled') MSGTYPE(*ESCAPE)
ENDDO
ENDDO
IF COND(&PRTOUTQ *NE *SAME) THEN(DO)
/* Override with specific outq */
OVRPRTF FILE(QSYSPRT) TOFILE(QSYSPRT) PAGESIZE(198) +
PRTTXT(&PRTTXT) +
OUTQ(&PRTOUTQLIB/&PRTOUTQ) HOLD(&PRTHOLD) +
USRDTA(&PRTUSRDTA) SPLFNAME(&PRTSPLF)
/* Prevent endless loop if OVRPRTF fails */
MONMSG MSGID(CPF0000) EXEC(DO)
SNDPGMMSG MSGID(CPF9898) MSGF(QCPFMSG) MSGDTA('Error +
overriding print file - QSHCALL +
cancelled') MSGTYPE(*ESCAPE)
ENDDO
ENDDO
CPYF FROMFILE(&OLIB/&OFILE) TOFILE(QSYSPRT)
DLTOVR FILE(QSYSPRT)
ENDDO
/* IF ENABLED, DISPLAY STDOUT RESULTS */
IF COND(&DSPSTDOUT *EQ *YES) THEN(DO)
EDTF STMF(&STDOUTIFS)
MONMSG MSGID(CPF0000)
ENDDO
/* IF ENABLED, Erase stdout result file */
IF COND(&DLTSTDOUT *EQ *YES) THEN(DO)
ERASE OBJLNK(&STDOUTIFS)
MONMSG MSGID(CPF0000)
ENDDO
/* Write STDOUT results PF to job log */
IF COND(&LOGSTDOUT *EQ *YES) THEN(DO)
OVRDBF FILE(STDOUTQSH) TOFILE(&OLIB/&OFILE)
CALL PGM(QSHSTDOUTR)
DLTOVR FILE(STDOUTQSH)
ENDDO
SNDPGMMSG MSGID(CPF9898) MSGF(QCPFMSG) MSGDTA('QShell +
command failed') MSGTYPE(*ESCAPE)
ENDPGM:
ENDPGM