IBM i Global

IBM i 

A space for professionals working with IBM’s integrated OS for Power systems to exchange ideas, ask questions, and share expertise on topics like RPG and COBOL development, application modernization, open source integration, system administration, and business continuity.


#Power


#IBMi
#Power
 View Only
  • 1.  Varying on printer devices & starting writers after role swap

    Posted Fri March 27, 2026 01:47 PM

    Greetings,

    One pain point I've always dealt with is that whenever we do a MIMIX role swap the process never varies on our printer devices and start the printer writers.  I've always had to go thru them one by one and vary them on manually.  Is there a better way to do this?  I realize this doesn't apply to this specific situation, but I can see in our start-up program this code for starting the writers and the QSPL subsystem. 

    /*******************************************************************/   
    /* START PRINTERS IF NECESSARY                                     */   
    /*******************************************************************/   
                 DLYJOB     DLY(180)                                        
                 IF         COND(&MXSYSROLE *EQ 'P') THEN(DO)               
                 QSYS/STRSBS SBSD(QSPL)                                     
                 MONMSG     MSGID(CPF0000)                                  
                 QSYS/RTVSYSVAL SYSVAL(QSTRPRTWTR) RTNVAR(&STRWTRS)         
                 IF         COND(&STRWTRS = '0') THEN(GOTO CMDLBL(NOWTRS))  
                 CALL       PGM(QSYS/QWCSWTRS)                              
                 MONMSG     MSGID(CPF0000)                                  
    NOWTRS:                                                                 
                 ENDDO                                                      

    I'm wondering if I could write a CL program that I could call to vary on the devices and start the writers.  

    Thank you,



    ------------------------------
    Michael Soucy
    Sr Midrange Engineer
    Bangor Savings Bank
    Bangor ME
    ------------------------------


  • 2.  RE: Varying on printer devices & starting writers after role swap

    Posted Fri March 27, 2026 03:47 PM

    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






  • 3.  RE: Varying on printer devices & starting writers after role swap

    Posted Fri March 27, 2026 04:58 PM

    Hello

    You may want to try using IBM i Services like the following, through a RUNSQL command:

    To vary on the varied off printer devices:

    select qsys2.qcmdexc('VRYCFG CFGOBJ(' concat OBJECT_NAME concat ') OBJTYPE(*DEVD) STATUS(*ON)')

    from SYSTOOLS.CONFIGURATION_STATUS where OBJECT_TYPE = '*DEVD'  and OBJECT_ATTRIBUTE like ('PRT%') and STATUS_DESCRIPTION = 'VARIED OFF'

    Then to start the printers:

    select qsys2.qcmdexc('STRPRTWTR DEV(' concat OBJECT_NAME concat ')')

    from SYSTOOLS.CONFIGURATION_STATUS where OBJECT_TYPE = '*DEVD'  and OBJECT_ATTRIBUTE like ('PRT%')



    ------------------------------
    Marc Rauzier
    ------------------------------



  • 4.  RE: Varying on printer devices & starting writers after role swap

    Posted Sat March 28, 2026 04:52 AM

    My bad sorry.

    Neither RUNSQL nor RUNSQLSTM can execute an SELECT SQL statement.

    You have to create one QMQRY for each statement, then run them with STRQMQRY, or run your statements from "Run SQL scripts" feature of iACS PASE installation (https://www.ibm.com/support/pages/ibm-i-access-acs-updates-pase).



    ------------------------------
    Marc Rauzier
    ------------------------------



  • 5.  RE: Varying on printer devices & starting writers after role swap

    Posted Mon March 30, 2026 07:38 AM

    Workaround:

    create or replace table qtemp.cfg_status_result as (

    ... use select statement above

    ) with data;



    ------------------------------
    Robert Berendt IBMChampion
    Business Systems Analyst, Lead
    Dekko
    Fort Wayne
    ------------------------------



  • 6.  RE: Varying on printer devices & starting writers after role swap

    Posted Mon March 30, 2026 08:06 AM

    Another example of using stored procedures to replace CL



    ------------------------------
    Robert Berendt IBMChampion
    Business Systems Analyst, Lead
    Dekko
    Fort Wayne
    ------------------------------



  • 7.  RE: Varying on printer devices & starting writers after role swap

    Posted Tue March 31, 2026 10:19 AM

    when we do role swaps using Mimix, we submit the vary on (CL Program) as a separate  batch job early in the process by the time the vary-on job is done - we're able to start the writers without issue. While you can use SQL to do something similar, i find that some things do run slower using SQL Services compared to the "old" way of doing things..and like all things. "it depends".  You're not going to notice something running slow if its a small amount of 'x', but you will notice it on items that have a large quantity of 'x'. 



    ------------------------------
    Rich Malloy
    Principal Systems Engineer - IBMi
    Cox Automotive
    Draper UT
    ------------------------------



  • 8.  RE: Varying on printer devices & starting writers after role swap

    Posted Wed April 22, 2026 12:03 PM

    Thank you everyone for your help with this.  I was able to create a CL program using some code that I "stole" from a webservice program a former coworker of mine created.  The webservice program displays a list of all the printers we have.  This is my CL program. 

     START:         PGM        /* B#UTLCPRT */

                    DCL        VAR(&SQLCMD) TYPE(*CHAR) LEN(1000)

                    DCLF       FILE(B#PRINTERS) OPNID(F1)

                    DSPOBJD    OBJ(*ALL) OBJTYPE(*DEVD) DETAIL(*FULL) OUTPUT(*OUTFILE) +
                                 OUTFILE(QTEMP/PRTDEVD)
                    CLRPFM     FILE(B#PRINTERS)
                    CHGVAR     VAR(&SQLCMD) VALUE('INSERT INTO B#PRINTERS SELECT odobnm AS +
                                 JHAPrinter, odobtx AS Description   FROM QTEMP.prtdevd WHERE +
                                 odobat LIKE ''%PRT%'' AND odobnm NOT LIKE ''%V1%'' AND odobnm NOT +
                                 IN (''PDFPRINTER'', ''VALIDATOR'', ''SPLTOPDF'', ''T64E'') AND +
                                 SUBSTR(qgpl.prtdrmtloc(odobnm), 1, 20) IS NOT null ORDER BY odobnm')

                    RUNSQL     SQL(&SQLCMD) COMMIT(*NONE)

     READ:          RCVF       OPNID(F1)
                    MONMSG     MSGID(CPF0000) EXEC(GOTO END)
                    IF         COND(&F1_JHAPRINTER *NE 'ISTOPS') THEN(DO)
                       VRYCFG     CFGOBJ(&F1_JHAPRINTER) CFGTYPE(*DEV) STATUS(*ON)
                       STRPRTWTR  DEV(&F1_JHAPRINTER)
                    ENDDO
                    GOTO       CMDLBL(READ)

     END:           ENDPGM 

    I ended up creating a table to narrow down the printer devices from the DSPOBJD command.  I tested it, and it works fine. 



    ------------------------------
    Michael Soucy
    Sr Midrange Engineer
    Bangor Savings Bank
    Bangor ME
    ------------------------------



  • 9.  RE: Varying on printer devices & starting writers after role swap

    Posted Wed April 22, 2026 03:16 PM

    Guess you're missing remote outqueues unless you don't have those but you can collect both printers and remote outqueues as follows;

    with printers as (
    SELECT OBJLIB, OBJNAME, OBJTYPE, OBJATTRIBUTE
    FROM TABLE (QSYS2.OBJECT_STATISTICS('*ALL''*DEVD'))
    where OBJATTRIBUTE like '%PRT%'
    union
    select OUTPUT_QUEUE_LIBRARY_NAME, OUTPUT_QUEUE_NAME, '*OUTQ''REMOTE'
    from QSYS2.OUTPUT_QUEUE_INFO
    where WRITER_TYPE = 'REMOTE'
    order by objlib, objname, objtype), 
    cmds as (select printers.*, 
      case 
        when objtype = '*DEVD' then 
          'STRPRTWTR DEV(' || OBJNAME || ')'
        else 
          'STRRMTWTR OUTQ(' || OBJNAME || ')'
      end case  
    from printers)
    select * from cmds;

    If you combine this (sorry, didn't have the time now) with other info in this thread like the SYSTOOLS.CONFIGURATION_STATUS and QSYS2.QCMDEXC functionality you can do it in a single SQL.



    ------------------------------
    Paul Nicolay
    Architect
    Cegeka
    ------------------------------