WorksRight



HOME    SUBSCRIBE

  Midrange Guru - OS/400 Edition

 

Editors: Ted Holt      Managing Editor: Mari Barrett
Howard Arner Technical Editor: David Morris

    Tramenco

    Topics Covered in Volume 1, Number 25:

    Grepping It Up

    Hey, Ted:

    I thought the tip showing how to use the grep function to find a string was cool, so I showed it to one of the guys I work with. We are starting to use XML for an insurance system and store those files as OS/400 IFS files. The grep command will come in handy when we need to look for something and don't want to map a drive. There is one problem; with a mapped drive you can search sub-directories. It looks like you can search for all kinds of patterns with grep, but I don't see how you search through sub-directories. Am I missing something?

    -- Dan

    No, you are not missing anything. The grep utility on iSeries and AS/400 systems does not directly support traversal of sub-directories, although grep on some other systems does. There is a way though. Many of the Unix utilities, including grep, allow the output of one command to be the input to another command.

    In this case, a combination of the grep and find utilities is the answer. Alone, both grep and find are useful, combined they are omnipotent. For those of you who missed the grep discussion, read the article, "Looking for Strings in the IFS," available on the Midrange Guru OS/400 edition Web site at http://www.itjungle.com/guruo/guruo010902.html.

    The find command allows you to read a directory and all of its sub-directories. One thing the find utility provides is the ability to run other commands using the -exec option. You terminate the -exec option with a backslash (\) and semicolon (;) combined, like this: \;. If you specify a grep expression for a find's -exec, the 'found' files replace any braces ({}) in the supplied expression:

    find   /home/mydir   -exec grep -il 'jar' {} \;

    Entering this in Qshell results in a list of files that contain the string 'jar' in any case (remember the -i option means ignore case and -l means list file names rather than lines containing the find string). The search begins in the directory /home/mydir and includes all subdirectories under mydir.

    Like grep, find supports quite a few options. One of the most useful is the -name option. When you specify -name, find only selects files that match the name pattern you specify. Adding -name '*.xml' to the previous example tells find to only return files that have a .xml extension. Here is an example:

    find  -name '*.xml' -exec grep -il 'jar' {} \;

    Another find option that you might find useful is -user, which selects files owned by a particular user profile. To search all files that you own, you might specify something like the following example:

    find -user 'dmmorris' -exec grep -il 'jar' {} \;

    For more information on the find command and find's options, go to the IBM iSeries Information Center. Find is listed with all of the other Unix utilities supported on the iSeries at http://as400bks.rochester.ibm.com/pubs/html/as400/v5r1/ic2924/index.htm. In the directory pane on the left side of the screen, choose Programming, Shells and Utilities, Qshell Interpreter, and Utilities.

    -- Ted

     

    SPONSORED BY WORKSRIGHT SOFTWARE, INC.

    ******** Indiana and Arkansas have new area codes! ********

    On January 15, 2002, parts of area code 219 in Indiana will be split into new area codes: 260 and 574. On January 19, 2002, parts of area code 501 in Arkansas will become new area code 479.

    How are you going to update your customer files?

    We have the answer. Our ZIP/CITY System for the AS/400 can automatically update your customer files for this area code split and future ones as well.

    We provide bimonthly updates that contain all the latest area code and ZIP CODE information. The ZIP/CITY System also provides city, state and county names, county codes, time zones, and lat/lon information. The ZIP/CITY System also includes a distance calculation feature and a nearest dealer locator system.

    Software, data, bimonthly updates, and unlimited support are included for the low price of $395 per year.

    Visit our Web site http://www.worksright.com to learn more about ZIP/CITY. We offer a free, no-hassle, 30-day trial. Phone, fax, e-mail us, or order your free trial directly from our Web site.




    Reader Feedback and Insights

    Hey, Howard and Ted:

    I just wanted to thank you guys for the SQL tip in the Midrange Guru OS/400 Edition, September 28, 2001, (see A Character from a Character Field). I've been trying to remember how to do that for some time now.

    Keep 'em coming! Thanks.

    -- Randy

    You're welcome, Randy. We're glad to be of assistance, and keep that feedback coming.

    -- Howard and Ted

    SQL Package Problems Cause ODBC Troubles

    Hey, Howard:

    Our company had a problem when all of our ODBC connections failed to retrieve data from the AS/400. To fix the problem, one of our techs deleted the SQL packages from the production AS/400, and then restored the SQL packages from our Development machine.

    What are SQL packages? Any light shed on this issue would be greatly appreciated.

    -- R. Moore

    Ah, packages the wonderful performance-enhancing technology from IBM. Packages relate to DB2/400 query execution plans and are a great way to optimize the performance of your client applications. The best way to understand packages is with a little background information.

    When DB2/400 gets a query from a client application, such as a PC running ODBC, JDBC, or OLE DB, the query optimizer decides how to perform the query. First, the optimizer compiles a list of the physical files that your query is accessing. Then it retrieves a list of the logical files built over the physical files. Next, it evaluates your query's ordering, join, and where criteria against the physical implementation of your database and chooses the best way to retrieve your data. The way that the query optimizer decides to access the data is sometimes called an access plan or implementation plan. Once it has a plan, the DB2/400 uses the plan to implement your query each time the query runs.

    Here is the problem: Many iSeries and AS/400 shops have numerous logical files built over their physical files, so formulating an access plan can be a very expensive operation. (What? You thought it was magic?) The system must look at the access paths and determine if any of them can speed up data retrieval, and that means lots of I/O. Since formulating the plan is an I/O-intensive operation, you should avoid that process in production environments as if it was the black plague. A package file can come in handy for helping to avoid unnecessary and repetitive optimizations.

    If you enable package support on your OLE DB, ODBC, or JDBC applications, the DB2/400 will optimize the SQL statements and store the execution plans in SQL package files on the AS/400. Thus, any program attempting to run the same SQL statement does not need to perform query optimization; the database engine looks up the SQL statement in the SQL package file and if it is found, executes the stored access plan. This will reduce both I/O and CPU because the optimization step of implementing the query is avoided.

    How to Use Packages:

    Use the Windows Control Panel to control whether or not ODBC applications use SQL packages, and to control how packages are used. Note that the following information is version-specific. IBM changes the order and layout of information in the ODBC configuration from time to time, but the names of the fields should be consistent.

    First, from the Control Panel, select ODBC Data Sources, then select a Client Access ODBC data source that you want to modify. Go to the Packages tab, where you should see a check box called Enable Extended Dynamic Support. In some versions of CA, I believe that this was available via the Performance tab. If this box is checked, your ODBC applications that use this data source will use packages on the AS/400.

    Now, to make things a little more confusing, let's talk about some of the other settings that you can alter when an application uses packages (all of these settings are on or available from the Packages tab). The Default Package Library specifies where the client program should look for its package files. If no package file exists for the application, it will create the package file in this library.

    The Application Name drop-down list allows you to select a particular Windows application and associate it with a specific library, file, and setting just for that application. This function can be useful if you are running multiple applications that use the same data source to connect to the AS/400. For example, on my machine, package settings for VB6 are different from package settings for application crw32 (Crystal Reports). Note that the application name isn't really the name of the application as you and I would think of it, but the name of the executable (EXE) file that you use to start the application. Therefore, if you wanted to set up specific package setting for Microsoft Excel, the Application Name would be EXCEL.

    For each application you define, you can set the name of the package file, choose the library where you want the package file to reside, and determine how the package is used. For the Package usage option, you can set the package to Disable, Use, or Use/Add. If you specify Disable, that application will ignore an available package file. If you specify Use, the package file will be used but no new execution plans will be added to it. If you specify Use/Add, the package will be used, and if the AS/400 encounters a query that is not in the package file, it will store that query and execution plan in the package file.

    Now, here is a setting that addresses your question. The Unusable Package setting controls how the client application should respond if there is a problem with the SQL package file. In your case, the setting is probably set to Error, which causes the client application to receive an error message when it attempts to execute a query and the package file is corrupt or unusable. Setting this option to Warning would cause the client application to receive a warning message when a package is not usable. However, some poorly coded client applications incorrectly interpret SQL warnings as errors--or worse yet; show the messages to users who then call the help desk--so you might want to set the option to Ignore. If set to Ignore and the application encounters an error in dealing with a package, the DB2/400 and client application will merrily continue and not use the SQL package file.

    Another setting you can control is the 'Clear Package if Package Size Is' setting. By checking this box and setting a size limit, you cause the package file to be cleared when it reaches the size you specify. In addition, the Cache Package Locally option allows the application to maintain a copy of the package file in local memory (on the client) and can improve performance. Thus, the client memory and processor are used to search for the SQL access path first, before giving the query to the AS/400.

    Now, IBM changed the interface a little bit in version 8 of the ODBC driver and you now have a pop-up window to configure each application separately. Also, note that in ODBC driver version 7, if you do not specify an application name, you are specifying settings for all applications that use the source by default as application use the data source, the package information will be stored in the Windows registry and associated with that application. Therefore, when you first enable extended dynamic support, the drop-down list of applications will be blank. Run a few applications that use that data source, and then go back into the Data Source administrator program and the applications will appear in the drop-down list.

    In JDBC, OLE DB, and ODBC, you can also control the use of packages based on the arguments that you supply in the connection string to the AS/400. Any connection string arguments will override the package settings in the ODBC data source. I have an article, available at www.sqlthing.com under the AS/400 tab, that overviews connection string arguments that can affect packages and package use.

    Managing Packages

    Ok, so now that we have an idea of what packages are and how they are used, let's briefly talk about how you want to manage packages on your AS/400 and with your client applications. First, do not bother to use Enable extended dynamic package support if your client application is all dynamic SQL and the fields in the Where, Group by, or Order by clauses change from one run of the query to the next. You will end up with a really big package file of queries that are not reused (and shame on you for only using so much dynamic SQL).

    During the development phase of a project, I typically disable extended dynamic support because I am executing so many queries and the queries rapidly change; I do not want the AS/400 to store the execution plans in this fluid environment. In fact, most of the time I am not executing queries in applications, but doing query development, benchmarking, and performance testing in SQLThing. I'm also usually running the queries in Debug mode so I can see all of the implementation messages from the AS/400 query optimizer.

    Once I get close to the testing, performance, and quality assurance phase of my project, I turn on extended dynamic support and allow the AS/400 to store copies of my queries in a package, using the Use/Add option. I ensure that I go through all of the queries in the application so that all queries are optimized and stored in the package. (In fact, most times I save all queries to a file and then use SQLThing to run the script so I know that each query is stored in the package file.) When I deploy my application, I ensure that the data source is set to use the package file that I created and the application is set to Use, as I do not want any new access paths saved in the package, especially if my client application has some dynamic SQL. In addition, I typically set the Unusable Package setting to Ignore so that if the package file is corrupted or unusable, my client application does not see an error.

    Finally, let me relate two performance stories about extended dynamic use in JDBC and ODBC. In the first case, the client was using JavaServer Pages (JSPs) to display information from a 10,000,000-record table. Performance was intermittent when the application went to production, sometimes taking up to 60 seconds to display the resulting page. All of the processing time was spent on query optimization (60 logical files had to be evaluated when attempting to formulate an access plan). By writing ten versions of the query--one for each different combination of how the user might request the display--using the prepared statement object in JDBC, passing parameters to the query, and ensuring that the statements were packaged by the settings in the connection string, I took the average data response down to one-half second per request.

    Example number two is from an insurance company running Active Server Pages (ASP) against their AS/400 database. Again, all pages were executing using dynamic SQL and no extended dynamic support. Some pages took between 20 seconds and two minutes to display, again most of the time was wasted on query optimization. By having the ASP pages use the ADO Command object, pass parameters to the queries, and ensure that all queries are packaged, the average data response is now always less than one-quarter second.

    -- Howard

     

    SPONSORED BY TRAMENCO

    Introducing a New Source for Training and Mentoring

    Follow this link to a vital new source for how-to technical information: www.tramenco.com.

    Unlike companies that offer training as an afterthought, The Training and Mentoring Company (Tramenco) is dedicated to just one thing: Advancing your career by giving you the skills you need to solve real-world business problems.

    You get the best information from the world's leading experts--Howard Arner, Kelly Conklin, Don Denoncourt, Susan Gantner, Skip Marchesani, Glen Marchesani, Shannon O'Donnell, Craig Pelke, and Richard Shaler.

    Choose from a menu of training options to fit your needs: onsite seminars, public seminars, mentoring, consulting, books, CBTs, and Web-based training.

    And make plans to attend the 2002 iSeries Connection Conference, the multi-day, multi-track conference that was the only sold-out iSeries training event this year, co-sponsored by the Education Connection and Tramenco.

    For more information about Tramenco's career enhancing opportunities, call (800) 421-8031 or go to www.tramenco.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 see our advertising opportunities and pricing at

    http://www.itjungle.com/advertising.html

    Or contact Timothy Prickett Morgan at

    Phone: 212 942 5818

    Email: tpm@itjungle.com

    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

    WorksRight

    Copyright (C) 2002 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.