Wednesday, August 5, 2026

QCMDEXC scalar function can write to job log

The QCMDEXC SQL scalar function is one of my favorite SQL features. I have used it many times in my work, and here in articles on this website. As part of the latest Technology Refresh, IBM i 7.6 TR2 and 7.5 TR8, it is further enhanced by now being able to write the command performed to the job log.

QCMDEXC scalar function now has two parameters:

  1. COMMAND:  The CL command to perform
  2. PRINT:  Whether the CL command should be written to the job log. This can contain the following:
    • ERROR:  Only write to the job log if the command fails
    • NONE:  No command is written to the job log. This is the default
    • VERBOSE:  The command is always written to the job log

Before I start describing in details what this change does, I need to have something I can do using the QCMDEXC scalar function. In this scenario I have a DDL table, TESTTABLE, that contains a list of files that I want to delete using a Delete File command, DTLF, in this scalar function.

I can show the contents of this table with the following:

01  SELECT * FROM TESTTABLE

Tuesday, August 4, 2026

Handling pipe separated data into a Db2 file

It started with a question:

If my file.txt is pipe filed separated, how can I make the records fall into the physical file to the corresponding fields.

A good question. Most of the time my incoming files are comma separated. The same methods I would use for those will work for pipe separated files too.

First I need a file with pipe separators. I made a copy of some of the columns from my PERSON DDL table to an output file in QTEMP:

01  CREATE TABLE QTEMP.OUTFILE AS 
02  (SELECT PID,LNAME,FNAME FROM PERSON)
03  WITH DATA