Categories: 01 - Programming (EN)

WHEN QTEMP IS NOT ENOUGH

Anyone who develops IBM i applications knows the QTEMP library very well, the temporary library that the system automatically creates and destroys for each job. But it cannot always be used; for example, the RTVDIRINF (Retrieve Directory Information) command does not accept the QTEMP library; or, in certain particular applications there is a need to create temporary objects which however must be shared with other applications. It can therefore be useful to have alternatives to QTEMP. Let’s see some of them.

The /tmp directory is a directory that can be used to create temporary stream files. If you decide to use /tmp it is important to know that the Unix clrtmp utility cleans the /tmp directory by deleting all the files present. On other systems, the /tmp directory is cleaned up every time the system is started; in IBM i, the /tmp directory is not cleaned at system startup, so you must run the ‘QSH CMD (clrtmp)’ command in the launcher specified by the QSTRUPPGM system value to clean the /tmp directory immediately after IPL, the only time when we are sure that no files are used. Before creating files in the /tmp directory, you need to think of a method to prevent jobs from treading on each other; a good solution is to create the files in a sub directory with the qualified name of the job, for example ‘/tmp/[job-user]/[job-name]/[job-number]’ taking care to delete it at the end of the job with the RMVDIR command (Remove directory) because, unlike the QTEMP library, the /tmp directory is not work related, so know that the files created in /tmp are available to all users with adequate authorization.

Like the /tmp directory, it may be convenient to create a temporary scheme for each job in which to create temporary objects. Also in this case the qualified name of the job helps us to have a good uniqueness, therefore we can create the schema with the SQL statement ‘CREATE SCHEMA xxxxx_[job-user]_[job-name]_[job-number]’ where xxxxx is a prefix dedicated to these schema, to which the system automatically assigns the name library ‘xxxxxnnnnn’ where nnnnn is a progressive from 00001 to 99999 managed by the system. The name of the library can be easily found with the SQL statement ‘GET DIAGNOSTICS CONDITION 1 :[host-variable] = MESSAGE_TEXT’ executed after the creation of the schema, which returns the message ‘Schema xxxxxnnnnn created’. At the end of the work it is a good rule to cancel the scheme with the ‘DROP SCHEMA’ instruction to avoid the risk of exceeding 99999 libraries and in the QSTRUPPGM program enter the command ‘DLTOBJ OBJ (QSYS/xxxxx*) OBJTYPE (*LIB)’ .

Related Posts
DB2 for i SQL – String Manipulation – POSSTR-LOCATE-LOCATE_IN_STRING (EN)

Introduction Often, in our applications, we need to work with text strings, and DB2 SQL can come in very useful Read more

DB2 for i – FAQ & Howtos (EN)

DB2 Database and SQL ... maybe the most important things on IBM i platform: here's a collection of FAQs, tips Read more

IBM i 7.4 Announcement (En)

Comes directly with the Easter egg this IBM announcement for the news of the IBM i 7.4 version, iNext version Read more

Generated Always Columns (EN)

Introduction "Generated Always Column": are columns, table fields, filled by DB2 engine: something like columns with a default value but Read more

Recent Posts

ACS Access Client Solution 1.1.9.5

Early April saw the release of the "Spring Version" of ACS Access Client Solution, version 1.1.9.5 Interesting new features especially…

1 day ago

Tim Rowe and Scott Forstie for CEC 2024 – Milan

If the packed agenda of sessions at Common Europe Congress 2024, June 3-6 Milan, wasn't enough for you, here's another…

1 day ago

Code for IBM i 2.10.0 – Debug IBM i App with Visual Studio Code

Debugging functions with Visual Studio Code have been available for some time but this new version 2.10.0 simplifies the handling…

3 days ago

ObjectConnect over TCP/IP

Two and a half years after my post Transferring objects with ObjectConnect and Enterprise Extender, I finally got around to…

4 days ago

SQL: SELECT with “superpowers”

With a little trick even a simple SELECT statement can execute any system command! Let's see how to do that...

5 months ago

NetServer for everyone – part 5

A mini-serial guide to configuring, managing, using, and troubleshooting the IBM i NetServer

1 year ago