20
Wed, Nov
1 New Articles

TechTip: Get to the Time Machine, Marty!

SQL
Typography
  • Smaller Small Medium Big Bigger
  • Default Helvetica Segoe Georgia Times

 

Let's make a quick trip back to six years ago.

Written by Scott Forstie

In 2007, with the tireless editorial help from Skip Marchesani, I wrote an all-inclusive article entitled "Procedures, and Functions, and Catalogs! Oh My!". The fine folks at MC Press published the article in February 2008.

This article has served its intended purpose, providing customers and IBMers alike a resource to bridge the gap between the SQL Reference and the successful deployment and maintenance of SQL routines with DB2 for i. Even though I lack a DeLorean time machine, I feel compelled to return to this article and provide a few updates.

The fuel driving this need to return to an article of the past is the DB2 for i product improvement delivered with IBM i 7.1 Technology Refresh 5 (TR5). In DB2 PTF Group SF99701 Level 18, DB2 for i added implicit routine catalog management when procedures and function executable objects were operated upon using any of these IBM i CL commands (or their API counterparts) or any service that relies upon these services:

  • Rename Object (RNMOBJ)
  • Move Object (RNMOBJ)
  • Create Duplicate Object (CRTDUPOBJ)

Effect of System CommandsUpdated

When the original article was published, two companion documents were included, breaking down the effect system commands have upon SQL catalogs when routine executes were the objects affected by the system command. I've updated the tables to reflect the changed behavior, with the updated cells highlighted in yellow.

Refer to this table for details on how system commands impact SQL procedures and functions.    

Refer to this table for details on how system commands impact external procedures and functions.

A Glimpse of the Improved Behavior

When copying, moving and renaming executables associated with SQL or external routines, DB2 for i attempts to keep the database catalogs in sync with the executable. These updates are immediately made to the catalogs, but don't stop there. The signature marking information contained within the executable is also updated. This extra step is necessary to accommodate for Save/Restore operations.

Any SQL statements contained the procedure or function are unaffected by the system command processing. For example, consider this SQL statement:

/* Insert new employee into table */

INSERT INTO EMPLOYEE ( EMPNO, FIRSTNME, MIDINIT, LASTNAME, WORKDEPT, HIREDATE, EDLEVEL )

VALUES ( P_EMPNO, P_FIRSTNME, P_MIDINIT, P_LASTNAME, V_DEPTNO, DATE ( V_CREATE_TS ), P_EDLEVEL ) ;

As a static SQL statement containing a table reference that is not schema-qualified, the EMPLOYEE table will be schema-qualified when the procedure is built, using the Default RDB Collection (DFTRDBCOL) setting.

When the executable is moved, renamed, or duplicated, the SQL application statements within the procedure executable are left unchanged. That means that the INSERT statement above will expect to find EMPLOYEE within the same schema (library).

If your goal is to clone an existing library that has both routines and database tables, my suggestion is to use the Generate SQL feature within System i Navigator. The generate option can be launched at the schema level, and you can un-check the "Schema qualify names for objects" and check the "OR REPLACE" clause. The generated script would be devoid of table qualification within statements like the INSERT statement example above. When the generated script is executed, it will use the current schema as the new default RDB collection. Read more about this concept here: Qualified name option added to Generate SQL.

SQL7909 Warning

As the original article explained, the SQL7909 warning is returned when a routine is created and DB2 for i is unable to update the internals of the executable with the routine signature detail.

Over time, the SQL7909 warning has been extended to keep pace with the automatic catalog management of routines. The change can be most easily understood by reviewing the changes, which are highlighted below.

SQL7909 reason codes:

     Reason code is &4.     Reason codes and their meanings are:                

     1 -- The external program did not exist when the CREATE, ALTER, COMMENT,

   LABEL, or DROP statement was issued.                                           

     2 -- The external program library is QSYS.                                    

     3 -- The external program was not an ILE *PGM or *SRVPGM.                     

     4 -- The program object for the corresponding routine or variable was in  

   use by another job.                                                            

     5 -- The SQL associated space in the program was in use by another job.       

     6 -- The SQL associated space in the program could not be expanded.           

     7 -- The external program was compiled in a release prior to V4R4M0.         

     8 -- The SQL associated space in the external program already contains the

   maximum number of routine definitions.                                         

     9 -- The external program is not in the same Independent ASP (IASP) as the routine

Reason 9 is self-explanatory, and Reason 1 indicates that this warning might be returned on any of the following SQL statements:

  • CREATE PROCEDURE

  • CREATE FUNCTION

  • ALTER PROCEDURE

  • COMMENT ON PROCEDURE/FUNCTION/ROUTINE

  • LABEL ON PROCEDURE/FUNCTION/ROUTINE

  • DROP PROCEDURE/FUNCTION/ROUTINE

Memo to Users (MTU)

Whenever existing behavior is changed, we carefully consider the potential impact to IBM i clients.     When we enhanced the catalog management, we anticipated that we could potentially disrupt operations for some customers who had a dependency upon the catalog not changing when executable objects were moved or renamed.

We constructed an optional switch as a remediation mechanism and documented the details in the Memo to Users document. The control is provided via the QIBM_SQL_NO_CATALOG_UPDATE environment variable. Follow the link to the MTU to see the full details.

A Helpful Hand

With Technology Refresh 6 and DB2 PTF Group SF99701 Level 21, DB2 for i supplied a utility procedure to make it easy for customers to assess SQL routine catalog entries between two machines. When a High Availability (HA) or Disaster Recovery (DR) solution is being used, the production and backup machines are generally meant to be identical. When SQL routines are being used, it's critical to also have identical QSYS2/SYSROUTINE, SYSRTNDEP, and SYSPARMS catalog detail.

The original article explained how this tool could be established. With IBM i 7.1 and TR6, the tool exists within the SYSTOOLS schema, where DB2 for i ships tools and examples.

SYSTOOLS/CHECK_SYSROUTINE() is explained in detail in the IBM i Technology Updates wiki: CHECK_SYSROUTINE() procedure added to SYSTOOLS and within this TechTip: "Keep DB2 Routines in Synch Across Systems."

"Back in Time

I'm nearly out of time spent revisiting this article. I'll proceed to rev up the flux capacitor and return to the present time. Thanks for reading this brief update, and if by chance you've never seen Back to the Future, you need to add it to your queue.

Scott Forstie is a Senior Technical Staff Member at IBM. He is the DB2 for i Business Architect, working on all things related to the database on IBM i.  He also is the content manager of the IBM i Technology Updates wiki (www.ibm.com/developerworks/ibmi/techupdates) where IBM i operating system enhancements are described. He can be reached at This email address is being protected from spambots. You need JavaScript enabled to view it. or followed on Twitter @ @Forstie_IBMi.

 

 

 

 

BLOG COMMENTS POWERED BY DISQUS

LATEST COMMENTS

Support MC Press Online

$

Book Reviews

Resource Center

  • SB Profound WC 5536 Have you been wondering about Node.js? Our free Node.js Webinar Series takes you from total beginner to creating a fully-functional IBM i Node.js business application. You can find Part 1 here. In Part 2 of our free Node.js Webinar Series, Brian May teaches you the different tooling options available for writing code, debugging, and using Git for version control. Brian will briefly discuss the different tools available, and demonstrate his preferred setup for Node development on IBM i or any platform. Attend this webinar to learn:

  • SB Profound WP 5539More than ever, there is a demand for IT to deliver innovation. Your IBM i has been an essential part of your business operations for years. However, your organization may struggle to maintain the current system and implement new projects. The thousands of customers we've worked with and surveyed state that expectations regarding the digital footprint and vision of the company are not aligned with the current IT environment.

  • SB HelpSystems ROBOT Generic IBM announced the E1080 servers using the latest Power10 processor in September 2021. The most powerful processor from IBM to date, Power10 is designed to handle the demands of doing business in today’s high-tech atmosphere, including running cloud applications, supporting big data, and managing AI workloads. But what does Power10 mean for your data center? In this recorded webinar, IBMers Dan Sundt and Dylan Boday join IBM Power Champion Tom Huntington for a discussion on why Power10 technology is the right strategic investment if you run IBM i, AIX, or Linux. In this action-packed hour, Tom will share trends from the IBM i and AIX user communities while Dan and Dylan dive into the tech specs for key hardware, including:

  • Magic MarkTRY the one package that solves all your document design and printing challenges on all your platforms. Produce bar code labels, electronic forms, ad hoc reports, and RFID tags – without programming! MarkMagic is the only document design and print solution that combines report writing, WYSIWYG label and forms design, and conditional printing in one integrated product. Make sure your data survives when catastrophe hits. Request your trial now!  Request Now.

  • SB HelpSystems ROBOT GenericForms of ransomware has been around for over 30 years, and with more and more organizations suffering attacks each year, it continues to endure. What has made ransomware such a durable threat and what is the best way to combat it? In order to prevent ransomware, organizations must first understand how it works.

  • SB HelpSystems ROBOT GenericIT security is a top priority for businesses around the world, but most IBM i pros don’t know where to begin—and most cybersecurity experts don’t know IBM i. In this session, Robin Tatam explores the business impact of lax IBM i security, the top vulnerabilities putting IBM i at risk, and the steps you can take to protect your organization. If you’re looking to avoid unexpected downtime or corrupted data, you don’t want to miss this session.

  • SB HelpSystems ROBOT GenericCan you trust all of your users all of the time? A typical end user receives 16 malicious emails each month, but only 17 percent of these phishing campaigns are reported to IT. Once an attack is underway, most organizations won’t discover the breach until six months later. A staggering amount of damage can occur in that time. Despite these risks, 93 percent of organizations are leaving their IBM i systems vulnerable to cybercrime. In this on-demand webinar, IBM i security experts Robin Tatam and Sandi Moore will reveal:

  • FORTRA Disaster protection is vital to every business. Yet, it often consists of patched together procedures that are prone to error. From automatic backups to data encryption to media management, Robot automates the routine (yet often complex) tasks of iSeries backup and recovery, saving you time and money and making the process safer and more reliable. Automate your backups with the Robot Backup and Recovery Solution. Key features include:

  • FORTRAManaging messages on your IBM i can be more than a full-time job if you have to do it manually. Messages need a response and resources must be monitored—often over multiple systems and across platforms. How can you be sure you won’t miss important system events? Automate your message center with the Robot Message Management Solution. Key features include:

  • FORTRAThe thought of printing, distributing, and storing iSeries reports manually may reduce you to tears. Paper and labor costs associated with report generation can spiral out of control. Mountains of paper threaten to swamp your files. Robot automates report bursting, distribution, bundling, and archiving, and offers secure, selective online report viewing. Manage your reports with the Robot Report Management Solution. Key features include:

  • FORTRAFor over 30 years, Robot has been a leader in systems management for IBM i. With batch job creation and scheduling at its core, the Robot Job Scheduling Solution reduces the opportunity for human error and helps you maintain service levels, automating even the biggest, most complex runbooks. Manage your job schedule with the Robot Job Scheduling Solution. Key features include:

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

  • LANSAWhen it comes to creating your business applications, there are hundreds of coding platforms and programming languages to choose from. These options range from very complex traditional programming languages to Low-Code platforms where sometimes no traditional coding experience is needed. Download our whitepaper, The Power of Writing Code in a Low-Code Solution, and:

  • LANSASupply Chain is becoming increasingly complex and unpredictable. From raw materials for manufacturing to food supply chains, the journey from source to production to delivery to consumers is marred with inefficiencies, manual processes, shortages, recalls, counterfeits, and scandals. In this webinar, we discuss how:

  • 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

  • Profound Logic Have you been wondering about Node.js? Our free Node.js Webinar Series takes you from total beginner to creating a fully-functional IBM i Node.js business application.

  • 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: