TechTip: Trapping a Canceled RUNQRY Command

System Administration
Typography
  • Smaller Small Medium Big Bigger
  • Default Helvetica Segoe Georgia Times
Awhile back, I was asked if it were possible to determine when the RUNQRY command had been canceled with F3 or F12. I had no answer, but Tom Liotta of PowerTech Group (www.400security.com) did, and he shared it with me. Tom uses the QUSRJOBI API to test for these keys. Pressing F3 or F12 places a character 1 in byte 103 or 104, respectively.

Following is Tom's code, which I have modified slightly. First, I shortened the lines that were too long for the purposes of this tip. Second, I added the return commands to the do groups. Third, I added the outtype(*PRINTER) parameter to the RUNQRY command. That's not necessary, but trapping a cancel request probably makes more sense when output is to be sent to a printer, since outtype(*DISPLAY) causes RUNQRY to be prompted over and over until it is canceled.

Tom had separate tests for F3 and F12. If you don't care which key the operator pressed, you might want to combine the two do groups into one. Tom adds, "This code can be used in many cases for functions that do not send messages when cancelled. I believe this is standard for UIM [User Interface Manager]-based functions." Thanks for sharing this useful technique with your fellow readers, Tom!

   dcl   &a_len   *char    4 /* Bin Data/Entry length  */
   dcl   &a_rcv   *char 1000 /* Receiver Variable, the */
                             /* length is variable. It */
                             /* must be in &A_LEN.     */

   dcl   &msgdta  *char  256

   dcl   &Action  *char   20  +
            value( 'RUNQRY RCDSLT(*YES)' )

   Qsys/runqry  Range1  outtype(*PRINTER)  rcdslt(*YES)

 /* ---------------------------------------------------*/
 /*   Test for cancel                                  */
 /* ---------------------------------------------------*/

    chgvar     %bin( &a_len 1 4 )    307

    Qsys/call  QUSRJOBI      ( +
                               &a_rcv              +
                               &a_len              +
                               'JOBI0600'          +
                               '*'                 +
                               '                '  +
                             )

 /*   Test job status for *CANCEL (F12)    */

     if ( %sst( &a_rcv 104 1 ) *eq '1' )   do

       chgvar     &msgdta            ( +
                                       'Action'  *bcat +
                                       &Action   *bcat +
                                       'cancelled.'    +
                                     )
       Qsys/sndpgmmsg  msgid( CPF9897 ) +
                    msgf( QSYS/QCPFMSG ) +
                    msgdta( &msgdta ) +
                    msgtype( *INFO )
       return
    enddo

 /*   Test job status for *EXIT (F3)    */

     if ( %sst( &a_rcv 103 1 ) *eq '1' )   do

       chgvar     &msgdta            ( +
                                       'Action'  *bcat +
                                       &Action   *bcat +
                                       'cancelled.'    +
                                     )
       Qsys/sndpgmmsg  msgid( CPF9897 ) msgf( QSYS/QCPFMSG ) +
                    msgdta( &msgdta ) +
                    msgtype( *INFO )
       return
    enddo

 /* ---------------------------------------------------*/
 /*   RUNQRY was not canceled                          */
 /* ---------------------------------------------------*/




Ted Holt is an IT consultant living in northeast Mississippi. He welcomes your comments at This email address is being protected from spambots. You need JavaScript enabled to view it..

Do you have a tip to share?

The useful techniques you discovered or created to help you do your job are exactly the techniques others are looking for! Share with your peers! Send your tips to This email address is being protected from spambots. You need JavaScript enabled to view it..

BLOG COMMENTS POWERED BY DISQUS

LATEST COMMENTS

Support MC Press Online

$0.00 Raised:
$