BCD Websmat



HOME    SUBSCRIBE

  Midrange Guru - OS/400 Edition

Editors: Ted Holt and Howard Arner     Managing Editor: Mari Barrett

This issue of the OS/400 Edition of Midrange Guru is sponsored by:

Symtrax
Business Computer Design, Int'l, Inc.

Topics Covered In Volume 1, Number 2:

Trapping A Canceled RUNQRY Command

Hey Ted :

Is there a way to determine in a CL program when a user has pressed F3 or F12 to cancel the Run Query (RUNQRY) command?

There sure is. In fact, here are two methods, courtesy of Tom Liotta of PowerTech Group (http://www.400security.com) and Carsten Flensburg.

Pressing F3 or F12 places a character 1 in byte 103 or 104 respectively. To test for the use of these keys, Tom uses the QUSRJOBI (Retrieve Job Information) API. Tom provided his code, which I have modified slightly. First, I shortened the lines that were too long for the format of this newsletter. 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 repeatedly until the operator cancels it. In other words, the test will always prove true with OUTTYPE(*DISPLAY), so why bother to test it?

Tom had separate tests for F3 and F12. If you don't care which key the operator pressed, you can combine the two conditions under one IF statement and have only one do group.

Tom adds, "This code can be used in many cases for functions that do not send messages when canceled. I believe this is standard for UIM-based functions."

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 */
/* ---------------------------------------------------*/

The second method comes from Carsten Flensburg. He uses the QWCRTVCA (Retrieve Current Attributes) API to query the two attributes holding the flags for F3 and F12, then resets the two job attributes using the QWCCCJOB (Change Current Job) API.

Load the following code into an RPGLE source member named GETXIT. Compile it using the Create Bound RPG Program (CRTBNDRPG) command. (You can recompile it as a module and, if you wish, add it to a service program.)

**-- Parameter: --------------------------------------------
D Fkey s 3
**-- QWCRTVCA API: ----------------------------------------
D CurAtr Ds
D AtNbrAtrRtn 10i 0
D AtAtrLen1 10i 0
D AtAtrKey1 10i 0
D AtAtrDtaTyp1 1a
D 3a
D AtAtrDtaLen1 10i 0
D F12 1n
D 3a
D AtAtrLen2 10i 0
D AtAtrKey2 10i 0
D AtAtrDtaTyp2 1a
D 3a
D AtAtrDtaLen2 10i 0
D F3 1n
D 3a
**
D CurAtrLen s 10i 0 Inz( %Len( CurAtr ))
D FmtNam s 8a Inz( 'RTVC0100' )
D KeyFldNbr s 10i 0 Inz( 2 )
D KeyFlds Ds
D 10i 0 Inz( 301 )
D 10i 0 Inz( 503 )
**-- QWCCCJOB API: ----------------------------------------
D ChgAtr Ds D CaAtrFldNbr 10i 0 Inz( 2 )
D CaAtrKey1 10i 0 Inz( 1 )
D CaAtrLen1 10i 0 Inz( 1 )
D CaAtrVal1 1a Inz( '0' )
D CaAtrKey2 10i 0 Inz( 2 )
D CaAtrLen2 10i 0 Inz( 1 )
D CaAtrVal2 1a Inz( '0' )
**
D ApiError Ds
D AeBytAvl 10i 0 Inz( 8 )
D AeBytRtn 10i 0 Inz( 0 )
**
C *Entry Plist
C Parm Fkey
**
C Call 'QWCRTVCA'
C Parm CurAtr
C Parm CurAtrLen
C Parm FmtNam
C Parm KeyFldNbr
C Parm KeyFlds

C Parm ApiError

**
C Call 'QWCCCJOB'
C Parm ChgAtr
C Parm ApiError
** C Select
C When F3
C Eval Fkey = 'F3'
C When F12
C Eval Fkey = 'F12'
C Other
C Eval Fkey = *Blanks
C EndSl
**
C Return

To test this routine, create a CL program called QRY001CL from the following source code:

Dcl &Fkey *Char 3

Runqry Q1 RcdSlt( *YES ) OutType( *PRINTER )

Call GETXIT &Fkey

If ( &Fkey *GT ' ' ) GoTo EndPgm

/* ...continue processing */

Endpgm:
EndPgm

QRY001CL executes the RUNQRY command specifying that the record select panel should be presented before execution. Then it calls the GETXIT RPG/IV program to have it check if the Exit or Cancel key was pressed.

Thanks to Carsten and Tom for sharing these useful techniques with Midrange Guru and your fellow readers.

-- Ted  

 

 

NEW SYMTRAX capabilities save more time and money!

Download FREE evaluation copies of COMPLEO and the "NEW" SYMTRAX REFORM at

http://www.symtrax.com/fhn

Award-winning COMPLEO reformats to XLS, HTML, PDF, and more, eliminating labor-intensive rekeying.

SYMTRAX REFORM painlessly adds custom electronic forms. Automate the complete process!

Call (800) 627-6013 or email us at sales@symtrax.com



 

Subscription And Advertising Information

Subscription Information

To unsubscribe, change your email address, or sign up for any of Guild Companies, Inc's free email newsletters, visit http://www.itjungle.com. Hit the SUBSCRIBE button on the homepage and it will lead you to our online subscription system.

When you sign up for one of our e-newsletters, you can be assured that your e-mail address will NEVER be sold to an outside company.

Advertising Information

Please contact Timothy Prickett Morgan at

Phone: 212 942 5818

Email: tpm@itjungle.com

DSN-Less Connections Using ActiveX Data Object

Hey Howard:

I have read that DSN-less connections are faster for Active Server Pages than using ODBC DSN connections. How can I connect to my AS/400 without a DSN, and why would I want to?

I think I can help.

A DSN, or Data Source Name, is defined via the ODBC Driver manager in the Windows Control Panel. This causes an entry to be made into the system registry that records all of the connection information you enter into the Control Panel. The problem with using a DSN is that every time you connect to the AS/400, the target computer must look up the connection information in the Windows registry. This is not a factor if you are casually connecting from applications like Excel, Access, or SQLThing, but if you are using Active Server Pages, these registry lookups do add a small amount of time to the connection process. Using a DSN-less connection will give you finer control of connection attributes; in fact, you can control your connection attributes on a page-by-page basis. In addition, by not requiring a DSN, your application or Web pages are easier to distribute to target computers (i.e., you do not have to go to the target computer and use the control panel to create a DSN).

There are many connectivity options that you can use when connecting to the AS/400. These options can cause your connection string to become quite complex. Instead of typing in all of the options, you can let Windows create a connection string for you by creating a Universal Data Link (UDL) file. A UDL file is a file-persisted set of information that tells a database program where and how its data files are stored on a computer or network and how to connect to a data source. In this case, you will use the UDL file as a quick way to build an ODBC or OLEDB connection string. First, open a Command Prompt window, switch to a directory you want to use, type COPY CON A.UDL, and press the Enter key. Next, press the F6 key to send a ^Z command to the console. You should see the text, "1 file copied" and then be returned to a command prompt. You have just created a zero length file called A.UDL in your target directory.

Next, pull up Windows Explorer, right click on the A.UDL file, and select the Properties menu. This will open an interactive window where you can set the provider and all connection options for that provider. Once you have your settings correct, press Apply, then OK to save the UDL information. Next, open the UDL file with a text editor (e.g., Notepad), and voila, you have a pre-formed, almost-perfect connection string. But there is one problem with the string: it still points to an ODBC DSN. To make the string perfect, remove the DSN information from the extended properties and replace the single quotes (')with double quotes (") so the string will not be confused in your ASP page. Finally, after the string "Provider=MSDASQL.1;" place the following information: Driver=Client Access ODBC Driver (32-bit). This string lets the MSDASQL OLEDB provider know that it should use the Client Access ODBC driver when it attempts to connect. Here is a code snippet that shows a proper connection string with lots of options:

ConStr = "Provider=MSDASQL.1;Driver="
ConStr = ConStr & "Client Access ODBC Driver (32-bit);Password=SECRET;"
ConStr = ConStr & "Persist Security Info=True;User ID=HFA;Extended"
ConStr=ConStr&"Properties=""SYSTEM=172.16.2.200;CMT=0;"
ConStr = ConStr&"DBQ=WEBOE,HD1100PD,HD1100PO;NAM=0;"
ConStr=ConStr&"DFT=5;DSP=1;TFT=0;TSP=0;DEC=0;XDYNAMIC=1;"
ConStr=ConStr&"RECBLOCK=2;BLOCKSIZE=32;SCROLLABLE=0;"
ConStr=ConStr&"TRANSLATE=1;LAZYCLOSE=1;LIBVIEW=0;
ConStr=ConStr&"REMARKS=1;CONNTYPE=0;SORTTYPE=0;
ConStr=ConStr&"PREFETCH=0;DFTPKGLIB=QGPL;LANGUAGEID=ENU;"
ConStr=ConStr&"SORTWEIGHT=0;SSL=2;MAXFIELDLEN=32;"
ConStr = ConStr&"COMPRESSION=1;ALLOWUNSCHAR=0;"
ConStr = ConStr&"SEARCHPATTERN=0;MGDSN=0;"""
Set Con1 = Server.CreateObject("ADODB.Connection"
Con1.Open ConStr

For more information, check my company's Web site at http://www.sqlthing.com in the coming weeks for a more complete look at how the settings for connections can effect performance.

-- Howard

 

 

Save time and money by doing fast, easy automated or end-user driven iSeries400 Report Distribution, e-mailing, Data Extraction... with the #1 Voted industry tools. Streamline the workflow process!

Whether you want to view reports online with a point & click download feature, or automate the entire process of downloading, converting & distributing reports, you need the right tools:

CATAPULT--Voted the #1 Automated Email Report Distribution tool for 2001. Automatically distribute via email, download and archive reports. Splits reports. Distributes them in the desired format. Converts to HTML, PDF, RTF, TIF. Uses AFP files.

Award winning Spool-Explorer/400 -- End users point and click to view / download reports. Converts to PDF, HTML, RTF... New version 3! Generate bookmarks and hyperlinks based on report contents... more.

Interfaces to EZ-Pickin's or Monarch for powerful data extraction and report mining, update Excel / Access spreadsheets... and so much more.

Also try WebSmart, voted best eBusiness / eCommerce Development and Deployment tool for 2001.

See the difference for yourself. Download and try CATAPULT, Spool-Explorer, EZ-Pickin’s -or- WebSmart now for FREE or get a FREE CD and you'll be more productive the very first day.

Call 630-986-0800 for more information, or visit our Web site at http://www.BCDsoftware.com



 


Reader Feedback And Insights

One of the great things about the OS/400 community is that it is indeed a community. We may be all working from our cubicles, but we are all connected and trying to figure out how to best employ the computer technology at our disposal. There are more than a few ways to skin any cat, and if you have a clever and unique answer to a problem that one of our Midrange Gurus has solved, we'd love to hear from you. This newsletter is an open dialog, and we value your input as well as your readership.

It goes without saying--but we'll say it anyway--that your hard technical questions pertaining to real world problems are equally valuable as a foundation for this newsletter as are your programming insights. We hope you find all the editions of Midrange Guru valuable, and we are going to work hard to make sure that they are.

Contact the Editors

If you have a tough problem, our gurus can probably help. Their mailboxes are always open.

* Email Ted Holt at tholt@itjungle.com

* Email Howard Arner at harner@itjungle.com

BCD Websmat

Copyright © 1996-2008 Guild Companies, Inc. All Rights Reserved. This document may be redistributed freely and enthusiastically by email, but only in its unedited form. Thanks for your cooperation. Midrange Guru is a registered trademark of Guild Companies, Inc. IBM, AS/400, iSeries, OS/400, and eServer registered trademarks of International Business Machines Corp. All other product names are trademarked or copyrighted by their respective holders.