01 - Programming (EN)

WHEN QTEMP IS NOT ENOUGH

Last Updated on 6 March 2020 by Roberto De Pedrini

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

About author

IBM i software developer

Leave a Reply

Your email address will not be published. Required fields are marked *