Using SQL QCMDEXC to simplify cleanup

Several months ago I publishing a post about finding the detached journal receivers in a partition. I mentioned if I want to delete those receivers I would create an output table, and then read that in a CL program and use the Delete Journal Receiver command, DLTJRNRCV, to delete the receivers one at a time.

Shortly after I received an email from Sue Romano, who is member of the Db2 for i development team, giving me a simpler alternative. Her examples used the QCMDEXC scalar function.

The QCMDEXC scalar function allows me to execute a CL command every time a row is returned in the results of a SQL statement.

She gave two examples, the first is what I would call a “sanity check”, to make sure that my statement returns the results I desire. And then a statement to delete the journal receivers.

Both of these are Common Table Expressions, CTE, which are a combination of SQL statements to produce one final set of results. The first part of the statement generates the a “virtual table” of results from the SQL view JOURNAL_RECEIVER_NAME, and the second does the action I want to do with those results.

The code I show below is Sue’s. My additions are in lower case.

Below is the “sanity check” statement:

01 WITH OLD_JRNRCV AS(
02 SELECT JOURNAL_RECEIVER_LIBRARY AS LIB,JOURNAL_RECEIVER_NAME AS NAME,DETACH_TIMESTAMP
03 FROM QSYS2.JOURNAL_RECEIVER_INFO
04 WHERE DETACH_TIMESTAMP IS NOT NULL
05 AND DETACH_TIMESTAMP < CURRENT_TIMESTAMP – 1 YEAR)

06 SELECT ‘DLTJRNRCV ‘ CONCAT LIB CONCAT ‘/’ CONCAT NAME
07 FROM OLD_JRNRCV ;

Lines 1 – 5: This is the part of the CTE that generated the “virtual table”, OLD_JRNRCV. Nothing really special here. I just select the journal receiver library, that is renamed to LIB, journal receiver name, renamed to NAME, and the detach timestamp. The detach timestamp is used to determine if the receiver is detached, not null, and is older than a year.

Lines 6 and 7: In the second part I just concatenate the LIB and NAME columns from the “virtual table” to create a prototype delete statement. I do not have to trim the columns are they are both VARCHAR, variable length character, type.

When this statement is run I get the following results:

00001
—————————–
DLTJRNRCV LIBRARY1/JOURNR0116
DLTJRNRCV LIBRARY1/JOURNR0117
DLTJRNRCV LIBRARY1/JOURNR0118
DLTJRNRCV LIBRARY1/JOURNR0119
DLTJRNRCV LIBRARY1/JOURNR0120

The second statement, that actually does the deleting of the journal receivers, looks pretty similar to the one above.

01 WITH OLD_JRNRCV AS(
02 SELECT JOURNAL_RECEIVER_LIBRARY AS LIB,JOURNAL_RECEIVER_NAME AS NAME,DETACH_TIMESTAMP
03 FROM QSYS2.JOURNAL_RECEIVER_INFO
04 WHERE DETACH_TIMESTAMP IS NOT NULL
05 AND DETACH_TIMESTAMP < CURRENT_TIMESTAMP – 1 YEAR)

06 SELECT QSYS2.QCMDEXC(‘DLTJRNRCV ‘ CONCAT LIB CONCAT ‘/’ CONCAT NAME
07 || ‘ dltopt(*igntgtrcv *igninqmsg *ignexitpgm)’)
08 FROM OLD_JRNRCV ;

Lines 1 – 5: Same as above.

Lines 6 – 8: I am using the QCMDEXC scalar function to perform the delete of the journal receivers listed in the “virtual table”. I added line 7 as I have found that adding these to the DLTJRNRCV command prevents warning errors.

Thank you Sue for these examples of how simple it is to use the QCMDEXC scalar function within a CTE. I am now thinking of other processes I have created that I could replace with a CTE like this.

 

This article was written for IBM i 7.5, and should work for some earlier releases too.

Mainframes vs Midrange Servers: What’s the Difference, Anyway?

Mainframe and midrange server are probably among the least understood terms in IT – due in part to the fact that folks don’t necessarily know what differentiates these types of systems from each other.

Unless you work with mainframes or midrange servers specifically, you probably just think of both as weird, old-fashioned types of infrastructure. You know they’re different from commodity, x86-based servers and PCs, but you don’t know what really defines a midrange server or a mainframe, or what makes them different from each other.

If that sounds like you, keep reading. Below, we explain what mainframes and midrange servers are, and offer some examples of each type of system.

What is a mainframe?

A mainframe is a large (though not necessarily as large as you think) server that is designed for processing and storing massive amounts of data. Mainframes originated in the 1950’s and have been an important part of the computing landscape ever since.

Most mainframes today are manufactured by IBM (although that was not always the case). They run either z/OS, the native mainframe operating system, or a version of Linux designed for mainframes.

Despite common misperceptions about the decline of mainframes, mainframes continue to see widespread use across a range of industries.

Read our whitepaper

Getting the Most Out of Your Mainframe

See how to offload, accelerate and lower cost of your mainframe to maximize its value

What is a midrange server?

A midrange server, meanwhile, is a server whose processing power falls somewhere between that of a mainframe and that of a standard commodity server.

Midrange servers were originally intended to meet the needs of small and medium-sized businesses, which did not require the massive computing power of a mainframe but needed more power than commodity servers could supply. (Actually, for the first couple decades of their history, there was no such thing as a commodity server; x86 servers came into widespread use starting only in the later 1980’s.)

Although midrange servers operate using their own class of hardware, it is more helpful to define midrange servers in terms of the operating systems that run on them rather than the hardware that they are built with. IBM created the first midrange server operating, called System/3, in 1969, which gave rise to the concept of midrange servers.

Several new midrange operating systems followed until 1988, when IBM released its AS/400 server line and the OS/400 operating system for it. By the early-2000’s, IBM was callings its midrange servers System i, and the operating system for them IBM i.

You might hear IBM i (or iSeries, a closely related term) used today to refer to midrange server operating systems (you might even still hear people talk about AS/400). Technically, however, since 2008 IBM’s nomenclature for midrange servers has been Power Systems. That’s the more proper term to use today.

No matter what you call them, midrange servers continue to cater to smaller organizations that need significant computing power and availability, but don’t want to move their workloads to commodity servers or the cloud because of cost, performance or security concerns.

Midrange servers vs. mainframes

If you’ve read this far, you know that both midrange servers and mainframes offer higher availability and performance than commodity servers. But what makes them different from each other, apart from the fact that mainframes offer more performance?

Here’s a basic rundown of the differences between mainframes and midrange systems:

Mainframes have been around longer. As noted above, they originated in the late 1950’s, compared to the late 1960’s for midrange servers.
Mainframes and midrange servers use different operating systems. Mainframes run z/OS or Linux; midrange servers run IBM i.
From a hardware perspective, a mainframe is really a distributed network of components, which interact to form a massive computing platform. A midrange server is a single, standalone system.
Mainframes are usually larger in terms of physical size – although as noted above, modern mainframes are not the huge machines of yore; they can be as small as a refrigerator. But midrange servers are typically even smaller than that.

Despite these differences, mainframes and midrange servers both remain an important resource for businesses across the world. While the advent of the cloud and very inexpensive commodity servers has drawn some businesses to redeploy workloads to those environments, mainframes and midrange servers continue to offer unparalleled levels of availability and performance.

Read “Getting the Most Out of Your Mainframe” to learn how to offload, accelerate and lower cost while leaving the primary CPU with more headroom for the organization’s core business applications.

 

The post Mainframes vs Midrange Servers: What’s the Difference, Anyway? appeared first on Precisely.

Verified by MonsterInsights