• The Four Hundred
  • Subscribe
  • Media Kit
  • Contributors
  • About Us
  • Contact
Menu
  • The Four Hundred
  • Subscribe
  • Media Kit
  • Contributors
  • About Us
  • Contact
  • Emulate sp_Help In DB2 For i

    April 30, 2014 Michael Sansoterra

    Note: The code accompanying this article is available for download here.

    Every once in a while I get an email from an SQL developer asking something like “What tool do you use to develop SQL routines on IBM i?” Astonished is the perfect verb to describe the reaction when I reply that I normally use STRSQL or Run SQL Scripts (in System i Navigator).

    Equally apt descriptions are dumbfounded, perplexed, baffled, and flummoxed. If you’ve ever used SQL developer tools on other platforms, such as Microsoft’s SQL Server Management Studio, then the astonishment is quite understandable.

    Run SQL Scripts has many good features, but it’s still comparatively cumbersome to develop with. If I were to list the many productivity aids I have in SQL Server Management Studio that I don’t have on the IBM i, we’d be here for quite some time. However, instead of bellyaching about lacking features, I found it’s generally pretty easy to create some productivity utilities to aid in the development process. While they’re not full blown GUI features, they can nevertheless be helpful.

    One productivity tool available with SQL Server is a system stored procedure called sp_HELP. When you execute sp_HELP [table name] in SQL Server management studio, SQL Server spits back several result sets detailing information about the table, including column names, the indexes built on the table, constraints, etc.

    Just typing this simple command often beats navigating through the GUI object tree to find the same information, especially with large databases. So I built a DB2 for i stored procedure called sp_HELP that does much the same thing as its SQL Server counterpart. However, while sp_HELP in SQL Server returns information about most database objects, the version I’ve created only works with tables, views, and aliases.

    The code for the DB2 for i sp_HELP procedure can be downloadedhere. There are also two helper functions included in the source that are required to collect the dependency and key column information. Make sure all three objects are created! Note that the script assumes the functions and procedure will be built in QGPL, but you can modify it to be installed into any library you’d like.

    While the code was built on IBM i 7.1 with the latest database group PTF installed, the code for sp_HELP can be ported to an earlier version of IBM i as long as you’re willing to remove some features or make a few code tweaks. For example, the SYSTRIGGERS table has some new columns in IBM i 7.1 that are unavailable in prior versions of the OS. I tried to note where these require “6.1” or “7.1” in specific places in the source code wherever I encountered them so that changes can be made where appropriate.

    The DB2 for i sp_HELP procedure accepts two parameters: a schema name; and an object name, where the object can be an alias, view, table, physical file, logical file, or materialized query table. The schema and object names can be specified as either long or short (system) names.

    The procedure is used as follows:

    CALL QGPL.sp_Help ('ADVENTUREWORKS','SALESHEADER')
    

    Incidentally, the CALL keyword, the parenthesis and the quotes are required in DB2 for i, so it’s more typing than you’d do with SQL Server.

    The procedure returns up to six result sets with information about:

    1. The object itself (object type, label, etc.) with info supplied from the SYSTABLES catalog view.
    2. The object’s columns based on info drawn from the SYSCOLUMNS2 catalog view.
    3. Other objects that depend on the selected object. This only includes database references that can be found in the system catalogs. Code dependencies are not listed here. This result set is based primarily on the QADBFDEP system cross reference file and the SYSINDEXES catalog view. Key column information is also shown.
    4. Check, unique, and primary key constraints on the object based on the SYSCST and SYSCHKCST catalog views.
    5. Foreign key constraints defined on the object based on the SYSCST and SYSREFCST catalog views. Only the child-parent or “outgoing” relationships from the requested table are shown. “Incoming” relationships from other tables to the requested table are not shown.
    6. The triggers defined on the object based on the SYSTRIGGERS catalog view.

    Take a look at this PDF that shows sample output for all six result sets.

    The constraint and dependency result sets are only shown when a table–or alias based on a table–is requested. When a view is requested, sp_HELP returns just three result sets: object information, columns, and triggers. The result sets returned show pretty much the same information you’d find with the System i Navigator GUI or by browsing through the DB2 catalog views. However, you can enhance sp_HELP to show you whatever is most important for your environment.

    sp_HELP only works with GUI-based tools such as Run SQL Scripts because the green screen tool STRSQL doesn’t support showing result sets. When the RunSQL Scripts utility returns multiple result sets, each result set gets placed in its own tab, which has advantages and disadvantages. The disadvantage is when sp_HELP returns six result sets, it’s difficult to know which tab has the trigger info result set, which tab has the column information, etc. IBM should remedy this by making each tab have an ordinal label (or something) so that a user has an idea of how to identify the desired result set without fumbling around. In contrast, in SQL Server management studio all of the results are shown in the same window so it’s easy to see all of the information.

    The sp_HELP procedure for DB2 for i is a handy utility for quickly viewing information about a database data object without having to maneuver through a GUI tree to find the required information. While it doesn’t have all of the features of the SQL Server version, it can be a real help for developers who need to keep on coding with access to relevant database object information at their fingertips.

    Michael Sansoterra is a DBA for Broadway Systems in Grand Rapids, Michigan. Send your questions or comments for Mike via the IT Jungle Contact page.



                         Post this story to del.icio.us
                   Post this story to Digg
        Post this story to Slashdot

    Share this:

    • Reddit
    • Facebook
    • LinkedIn
    • Twitter
    • Email

    Tags:

    Sponsored by
    VISUAL LANSA 16 WEBINAR

    Trying to balance stability and agility in your IBM i environment?

    Join this webinar and explore Visual LANSA 16 – our enhanced professional low-code platform designed to help organizations running on IBM i evolve seamlessly for what’s next.

    🎙️VISUAL LANSA 16 WEBINAR

    Break Monolithic IBM i Applications and Unlock New Value

    Explore modernization without rewriting. Decouple monolithic applications and extend their value through integration with modern services, web frameworks, and cloud technologies.

    🗓️ July 10, 2025

    ⏰ 9 AM – 10 AM CDT (4 PM to 5 PM CEST)

    See the webinar schedule in your time zone

    Register to join the webinar now

    What to Expect

    • Get to know Visual LANSA 16, its core features, latest enhancements, and use cases
    • Understand how you can transition to a MACH-aligned architecture to enable faster innovation
    • Discover native REST APIs, WebView2 support, cloud-ready Azure licensing, and more to help transform and scale your IBM i applications

    Read more about V16 here.

    Share this:

    • Reddit
    • Facebook
    • LinkedIn
    • Twitter
    • Email

    Sponsored Links

    Valence Framework for IBM i:  Download Valence 4.0 FREE! Web and mobile apps for IBM i.
    LANSA:  Webinar: Mobile and the IBM i: Why Should You Care? May 21, 9 am PT/11 am CT/Noon ET
    COMMON:  Join us at the COMMON 2014 Annual Meeting & Exposition, May 4 - 7 in Orlando, Florida

    More IT Jungle Resources:

    System i PTF Guide: Weekly PTF Updates
    IBM i Events Calendar: National Conferences, Local Events, and Webinars
    Breaking News: News Hot Off The Press
    TPM @ EnterpriseTech: High Performance Computing Industry News From ITJ EIC Timothy Prickett Morgan

    Unions Criticize IBM’s Earning Per Share Focus IBM i 7.2 Available May 2

    Leave a Reply Cancel reply

Volume 14, Number 10 -- April 30, 2014
THIS ISSUE SPONSORED BY:

SEQUEL Software
WorksRight Software
Bug Busters Software Engineering

Table of Contents

  • Emulate sp_Help In DB2 For i
  • PDF = Pretty Darn Fine!
  • Where Do I Find These IBM i Licensed Products?

Content archive

  • The Four Hundred
  • Four Hundred Stuff
  • Four Hundred Guru

Recent Posts

  • Liam Allan Shares What’s Coming Next With Code For IBM i
  • From Stable To Scalable: Visual LANSA 16 Powers IBM i Growth – Launching July 8
  • VS Code Will Be The Heart Of The Modern IBM i Platform
  • The AS/400: A 37-Year-Old Dog That Loves To Learn New Tricks
  • IBM i PTF Guide, Volume 27, Number 25
  • Meet The Next Gen Of IBMers Helping To Build IBM i
  • Looks Like IBM Is Building A Linux-Like PASE For IBM i After All
  • Will Independent IBM i Clouds Survive PowerVS?
  • Now, IBM Is Jacking Up Hardware Maintenance Prices
  • IBM i PTF Guide, Volume 27, Number 24

Subscribe

To get news from IT Jungle sent to your inbox every week, subscribe to our newsletter.

Pages

  • About Us
  • Contact
  • Contributors
  • Four Hundred Monitor
  • IBM i PTF Guide
  • Media Kit
  • Subscribe

Search

Copyright © 2025 IT Jungle