TechTip: Trapping a Canceled RUNQRY Command

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..

TED HOLT

Ted Holt is IT manager of Manufacturing Systems Development for Day-Brite Capri Omega, a manufacturer of lighting fixtures in Tupelo, Mississippi. He has worked in the information processing industry since 1981 and is the author or co-author of seven books. 


MC Press books written by Ted Holt available now on the MC Press Bookstore.

Complete CL: Fifth Edition Complete CL: Fifth Edition
Become a CL guru and fully leverage the abilities of your system.
List Price $79.95

Now On Sale

Complete CL: Sixth Edition Complete CL: Sixth Edition
Now fully updated! Get the master guide to Control Language programming.
List Price $79.95

Now On Sale

IBM i5/iSeries Primer IBM i5/iSeries Primer
Check out the ultimate resource and “must-have” guide for every professional working with the i5/iSeries.
List Price $99.95

Now On Sale

Qshell for iSeries Qshell for iSeries
Check out this Unix-style shell and utilities command interface for OS/400.
List Price $79.95

Now On Sale

BLOG COMMENTS POWERED BY DISQUS

LATEST COMMENTS

Support MC Press Online

$

Book Reviews

Resource Center

  •  

  • LANSA Business users want new applications now. Market and regulatory pressures require faster application updates and delivery into production. Your IBM i developers may be approaching retirement, and you see no sure way to fill their positions with experienced developers. In addition, you may be caught between maintaining your existing applications and the uncertainty of moving to something new.

  • The MC Resource Centers bring you the widest selection of white papers, trial software, and on-demand webcasts for you to choose from. >> Review the list of White Papers, Trial Software or On-Demand Webcast at the MC Press Resource Center. >> Add the items to yru Cart and complet he checkout process and submit

  • SB Profound WC 5536Join us for this hour-long webcast that will explore:

  • Fortra IT managers hoping to find new IBM i talent are discovering that the pool of experienced RPG programmers and operators or administrators with intimate knowledge of the operating system and the applications that run on it is small. This begs the question: How will you manage the platform that supports such a big part of your business? This guide offers strategies and software suggestions to help you plan IT staffing and resources and smooth the transition after your AS/400 talent retires. Read on to learn: