Q: I'm looking for a way to retrieve the default output queue name for another job. How can I do that?
A: You may already know that you can retrieve the default output queue and printer device for the current job with the RTVJOBA CL command. An example follows:
PGM
DCL VAR(&OUTQ) TYPE(*CHAR) LEN(10)
DCL VAR(&OUTQLIB) TYPE(*CHAR) LEN(10)
DCL VAR(&PRTDEV) TYPE(*CHAR) LEN(10)
RTVJOBA OUTQ(&OUTQ) OUTQLIB(&OUTQLIB) PRTDEV(&PRTDEV)
ENDPGM
You can do the same thing, more or less, for another job using the Retrieve Job Information (QUSRJOBI) API.
The reason that I retrieve the print device as well as the output queue name is that sometimes the output queue name will be *DEV. In that case, you'll want to have the print device name handy.
The following CL program uses the QUSRJOBI API to retrieve these attributes for any job:
PGM PARM(&QUALJOB)
DCL VAR(&QUALJOB) TYPE(*CHAR) LEN(26)
DCL VAR(&OUTQ) TYPE(*CHAR) LEN(10)
DCL VAR(&OUTQLIB) TYPE(*CHAR) LEN(10)
DCL VAR(&PRTDEV) TYPE(*CHAR) LEN(10)
DCL VAR(&RCVVAR) TYPE(*CHAR) LEN(187)
DCL VAR(&RCVVARLEN) TYPE(*CHAR) LEN(4)
DCL VAR(&ERRCODE) TYPE(*CHAR) LEN(8)
CHGVAR VAR(%BIN(&RCVVARLEN)) VALUE(187)
CHGVAR VAR(%BIN(&ERRCODE 1 4)) VALUE(0)
CALL PGM(QUSRJOBI) PARM( &RCVVAR +
&RCVVARLEN +
'JOBI0300' +
&QUALJOB +
' ' +
&ERRCODE )
CHGVAR VAR(&OUTQ) VALUE(%SST(&RCVVAR 85 10))
CHGVAR VAR(&OUTQLIB) VALUE(%SST(&RCVVAR 95 10))
CHGVAR VAR(&PRTDEV) VALUE(%SST(&RCVVAR 107 10))
/* &OUTQ CONTAINS THE OUTPUT QUEUE NAME +
* &OUTQLIB CONTAINS THE LIBRARY OF THE OUTPUT QUEUE +
* &PRTDEV CONTAINS THE NAME OF THE PRINT DEVICE +
*/
ENDPGM
When you call this program, you'll need to pass a job identifier as a parameter. The job identifier is a 26-character string that contains the job name in positions 1-10, the user profile name in positions 11-20, and the job number in positions 21-26.
For example, to retrieve the output queue for the 123456/QSECOFR/QPADEV0001 job, I'd call the program as follows:
CALL PGM(GETOUTQ) PARM('QPADEV0001QSECOFR 123456')
You can also pass an asterisk if you want to get the output queue of the current job. An example of this follows:
CALL PGM(GETOUTQ) PARM('*')
One of the great things about using an API instead of a CL command is that you can use it from any language. For example, the following RPG progam is equivalent to the CL program:
H DFTACTGRP(*NO)
D GetOutQ PR ExtPgm('GETOUTQ')
D QualJob 26A const
D GetOutQ PI
D QualJob 26A const
D QUSRJOBI PR ExtPgm('QUSRJOBI')
D RcvVar 32767A options(*varsize)
D RcvVarLen 10I 0 const
D Format 8A const
D QualJob 26A const
D IntJobID 16A const
D ErrorCode 32767A options(*varsize: *nopass)
D ResetPfrStat 1A const options(*nopass)
D Results ds
D 84A
D OutQ 10A
D OutQLib 10A
D 2A
D PrtDev 10A
D 73A
D ErrorCode ds
D BytesProv 10I 0 inz(0)
D BytesAvail 10I 0 inz(0)
D MsgID 7A
D 1A
D MsgDta 1024A
/free
QUSRJOBI( Results
: %size(Results)
: 'JOBI0300'
: QualJob
: *blanks
: ErrorCode );
// OUTQ now contains the output queue name
// OUTQLIB now contains the output queue library name
// PRTDEV now contains the print device name
*inlr = *on;
/end-free