Here is CL code I wrote decades ago to vary on QPADEV* but it is the same concept as what you want to do.
If your printer DEVD follow a naming convention like the QPADEV* devices then DSPOBJD with the generic name works well.
If they don't then you can just run the DSPOBJD command with *ALL and add code to filter the records you want to test after the RCVF command. You would check the ODOBAT attribute field for values like "PRTVRT", "PRTLAN" , etc.
Then I use the QDCRCFGS API to check the configuration status. If the &STATUS field = 0, then the device is varied off and we do a VRYCFG command for it.
The MOVPGMMSG and RSNESCMSG were internal commands that simplify the function of percolating messages up the call stack but you can replace them with normal message handling code.
Feel free to adapt as needed.
Scott A. Schollenberger
Senior Software Developer / IBM POWER Technician
E: sschollenberger@harriscomputer.com
-----------------------------------------------------------------------------------------------------------
VRYQPADEV: PGM
DCLF FILE(QPADEVICES)
DCL VAR(&RECVAR) TYPE(*CHAR) LEN(45)
DCL VAR(&RCVLEN) TYPE(*CHAR) LEN(4)
DCL VAR(&LENGTH) TYPE(*DEC) LEN(9 0) VALUE(45) +
DCL VAR(&CFGS0100) TYPE(*CHAR) LEN(8) +
VALUE('CFGS0100')
DCL VAR(&CFGTYPE) TYPE(*CHAR) LEN(10) +
VALUE('*DEVD')
DCL VAR(&ERRCDE) TYPE(*CHAR) LEN(4) +
VALUE(X'00000000')
DCL VAR(&STSBIN) TYPE(*CHAR) LEN(4)
DCL VAR(&STATUS) TYPE(*DEC) LEN(9 0)
MONMSG MSGID(CPF0000) EXEC(GOTO CMDLBL(ERROR))
DSPOBJD OBJ(QPADEV*) OBJTYPE(*DEVD) OUTPUT(*OUTFILE) +
OUTFILE(QTEMP/QPADEVICES)
#read: RCVF
MONMSG MSGID(CPF0864) EXEC(GOTO CMDLBL(#EOF))
CHGVAR VAR(%BIN(&RCVLEN)) VALUE(&LENGTH)
CALL PGM(QDCRCFGS) PARM(&RECVAR &RCVLEN &CFGS0100 +
&CFGTYPE &ODOBNM &ERRCDE)
CHGVAR VAR(&STSBIN) VALUE(%SST(&RECVAR 9 4))
CHGVAR VAR(&STATUS) VALUE(%BIN(&STSBIN))
IF COND(&STATUS = 0) THEN(DO)
VRYCFG CFGOBJ(&ODOBNM) CFGTYPE(*DEV) STATUS(*ON)
MOVPGMMSG MSGTYPE(*COMP)
ENDDO
GOTO CMDLBL(#READ)
#eof: CLOF OPNID(QPADEVICES)
MONMSG MSGID(CPF0000)
DLTOVR FILE(*ALL)
MONMSG MSGID(CPF0000)
RETURN
ERROR: MOVPGMMSG
RSNESCMSG
RETURN
ENDPGM