29
Fri, Nov
0 New Articles

Practical SQL: More Change Management

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

ILE presents some challenges for change management, but another DB2 service comes to the rescue.

Not long ago, I wrote an article about using a DB2 service for change management. That article made use of some of the DB2 for i services, including the table function OBJECT_STATISTICS and the view BOUND_MODULE_INFO. Between the two of them, I was able to get the source file library, name, and member used to create the object. I also mentioned that I could probably use that to do another level of change management, and that’s the topic of this article.

A Quick Recap

To recap, in the previous article I presented an SQL statement that used the services mentioned already and a LEFT OUTER JOIN to provide a simple view of the objects and their source:

SELECT OBJLIB, OBJNAME, OBJTYPE, BDMOD,

       O.SOURCE_FILE, SOURCE_LIBRARY, SOURCE_MEMBER, SOURCE_TIMESTAMP,
       SRCLIB, SRCFILE, SRCMBR, SRC_CHGTS                

FROM TABLE(OBJECT_STATISTICS('MYLIB','ALL')) O              

LEFT OUTER JOIN BOUND_MODULE_INFO ON                        

   (PGM_LIB, PGM_NAME, BDMOD) = (OBJLIB, OBJNAME, OBJNAME)

Listing 1: The original SQL combining OBJECT_STATISTICS and BOUND_MODULE_INFO

You can read the previous article for more information, but here’s the short version: The query selects records from OBJECT_STATISTICS, which is the SQL version of DSPOBJD. It includes source information, but there’s a catch: The source information in OBJECT_STATISTICS is only populated for OPM objects. That’s good for files created using DDS (physical, logical, display, and printer) and also for OPM programs but not for ILE programs. Since ILE programs can be created from multiple independently compiled objects, there may be many source members for an ILE program. That’s where the LEFT OUTER JOIN comes in; it brings in ILE module information, including the source for each module.

Expanding Our Architectural Horizon

That original SQL query is a reasonable starting point for ILE objects, but it has a couple of deficiencies. First, it only brings in a single module and only if that module’s name matches the program name. For simpler ILE environments, where you have a single source member for a program and use commands like CRTBNDRPG or CRTBNDCL (or CRTBNDCBL for you crazy COBOL kids), then the program will typically have a single module and it will have the same name as the program. In that case, the query will work fine. However, if you create programs using multiple modules using CRTRPGMOD and CRTPGM, or if you use service programs, then you’ll need something a little more robust. First, I need to expand the query to support multiple bound modules. I simply remove the third argument on the JOIN, which picks only the module whose name matches the program name. It’s easy, I just change the JOIN clause from:

 (PGM_LIB, PGM_NAME, BDMOD) = (OBJLIB, OBJNAME, OBJNAME)

to:

 (PGM_LIB, PGM_NAME) = (OBJLIB, OBJNAME)

In simple terms, this will bring in all modules for an object. For an ILE program compiled using the CRTBNDxxx commands, it will work the same way it always did, bringing in that single module that has the same name as the program. But let’s take a more complex example. I have a service program called SPSYS made up of four modules: SPINZ, SPINZDFT, SPSYSDBG, and SPSYSLOG. If I run the modified query, I get this:

Practical SQL: More Change Management - Figure 1

Figure 1: The first pass at retrieving information for all modules of a complex ILE object

It’s passable, but you can immediately see that there’s a lot of empty space. And for those who noticed, you are correct: This is not STRSQL. I took this screenshot, and subsequent ones, using DBeaver. It’s a free SQL client that I highly recommend. Anyway, those NULL columns are from OBJECT_STATISTICS, because it doesn’t provide any source information for ILE objects. And if I keep with this, then OPM objects will have columns 5-8 populated, while ILE objects will have data in columns 9-12. If only there were some way to sort of coalesce those values into one column. Well, guess what, there is such a way to do it in SQL, and it’s called COALESCE!

Using COALESCE to Reduce Column Complexity

To use COALESCE, you simply list your fields in order of precedence. If the first field in the list is NULL, COALESCE will move to the next field and so on. If all the fields are NULL, then COALESCE returns NULL. If you would rather have a default value, you can provide that as a literal as the last entry to COALESCE. Here is my updated SQL:

SELECT OBJLIB, OBJNAME, OBJTYPE, COALESCE(BDMOD,'*OPM') MODULE,

       COALESCE(SRCLIB, SOURCE_LIBRARY,'*NOSRC') SRCLIB,

       COALESCE(SRCFILE, OS.SOURCE_FILE) SRCFILE,

       COALESCE(SRCMBR, SOURCE_MEMBER) SRCMBR,

       COALESCE(SRC_CHGTS, SOURCE_TIMESTAMP) SRCTS

FROM TABLE(OBJECT_STATISTICS('MYLIB','SRVPGM')) OS

LEFT OUTER JOIN BOUND_MODULE_INFO

  ON (PGM_LIB, PGM_NAME) = (OBJLIB, OBJNAME)

Listing 2: Using COALESCE to present ILE values but use OPM values where no ILE value exists

I’ve done a couple of things. In my first use of COALESCE, I present the module name for ILE objects. If the module name (BDMOD) is NULL, however, I default to the literal *OPM. The next COALESCE first looks at the ILE source library from the BOUND_MODULE_INFO (SRCLIB), and if that is NULL, it then attempts to use the OPM source library from OBEJCT_STATISTICS (SOURCE_LIBRARY). If both are null, then the literal *NOSRC is used. The next three COALESCE calls do the same thing, attempting to first get an ILE value, and failing that, to use the OPM value. Unlike the previous call, though, there is no default value, since that’s already been done in the source library column. Running that on just my service program, I see this:

Practical SQL: More Change Management - Figure 2

Figure 2: Using COALESCE provides a complete view of all the modules for a service program

Running the expanded query over a library with a mix of OPM and simple ILE objects gives this:

Practical SQL: More Change Management - Figure 3

Figure 3: Running the COALESCE version over an entire library gives a more complete picture.

You can see that this library contains a mix of both OPM and ILE programs. And yes, this is an absolutely ancient library; it’s one of the original test libraries for VisualAge for Java. There are also some files, including one that has no source at all, which makes sense because that file, APPSOURCE, is itself actually a source file. It was created using the CRTSRCPF command and so has no source.

Back to the Source

I hinted at the beginning of this article that we would do a little more advanced change management. And while I’ve expanded the query to better handle complex ILE objects, I really haven’t done much to advance our change-management goals. To do that, I’m going to provide a way to compare the source timestamp in my object to the timestamp from the source file member itself. I do this by introducing the SYSPARTITIONSTAT view, which provides information on file members. In this case, I will be retrieving the member information for the source member I identified in my original query. Using COALESCE to use either ILE or OPM values as necessary makes that relatively easy. Here is the final query for today:

WITH T1 AS (

SELECT OBJLIB, OBJNAME, OBJTYPE, COALESCE(BDMOD,'*OPM') MODULE,

       COALESCE(SRCLIB, SOURCE_LIBRARY,'*NOSRC') SRCLIB,

       COALESCE(SRCFILE, OS.SOURCE_FILE) SRCFILE,

       COALESCE(SRCMBR, SOURCE_MEMBER) SRCMBR,

       COALESCE(SRC_CHGTS, SOURCE_TIMESTAMP) SRCTS

FROM TABLE(OBJECT_STATISTICS('ADTSLAB','PGM,FILE')) OS

LEFT OUTER JOIN BOUND_MODULE_INFO

ON (PGM_LIB, PGM_NAME) = (OBJLIB, OBJNAME)

) SELECT T1.*, LASTSRCUPD

FROM T1 LEFT OUTER JOIN SYSPARTITIONSTAT

   ON (SRCLIB, SRCFILE, SRCMBR) = (SYS_DNAME, SYS_TNAME, SYS_MNAME)

Listing 3: Define the original query as a CTE and JOIN it to SYSPARTITIONSTAT

What I’ve done is include the original query as a common table expression (CTE) named T1. I join that CTE to the SYSPARTITIONSTAT view and select all of the columns from the CTE followed by the source change timestamp (LASTSRCUPD) from SYSPARTITIONSTAT. This is the result:

Practical SQL: More Change Management - Figure 4

Figure 4: The final version includes both source timestamps, one from the object and one from the source file

While the query results reflect only the incremental difference of the additional timestamp, the next step would be to include only records where the two source timestamps don’t match. That’s when you can start really reviewing your change management requirements. As a simple example, you can see that the object RTVUSRCLAS has no source timestamp because in this case the library LEUNGA is not on the machine. So what we have is an object that was compiled from source that does not exist. And that’s something we need to identify!

I hope you enjoy how we managed to go from a simple object list to a reasonably sophisticated source/object analysis. Look for more on this subject in a subsequent article.

Joe Pluta

Joe Pluta is the founder and chief architect of Pluta Brothers Design, Inc. He has been extending the IBM midrange since the days of the IBM System/3. Joe uses WebSphere extensively, especially as the base for PSC/400, the only product that can move your legacy systems to the Web using simple green-screen commands. He has written several books, including Developing Web 2.0 Applications with EGL for IBM i, E-Deployment: The Fastest Path to the Web, Eclipse: Step by Step, and WDSC: Step by Step. Joe performs onsite mentoring and speaks at user groups around the country. You can reach him at This email address is being protected from spambots. You need JavaScript enabled to view it..


MC Press books written by Joe Pluta available now on the MC Press Bookstore.

Developing Web 2.0 Applications with EGL for IBM i Developing Web 2.0 Applications with EGL for IBM i
Joe Pluta introduces you to EGL Rich UI and IBM’s Rational Developer for the IBM i platform.
List Price $39.95

Now On Sale

WDSC: Step by Step WDSC: Step by Step
Discover incredibly powerful WDSC with this easy-to-understand yet thorough introduction.
List Price $74.95

Now On Sale

Eclipse: Step by Step Eclipse: Step by Step
Quickly get up to speed and productivity using Eclipse.
List Price $59.00

Now On Sale

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: