Specialized IT Services focused on Data Management | Speak with Us 877-634-9222
Adding Column Names to an Unload File
I received an e-mail from a reader asking an interesting question. She wanted to know if any of the DB2 unload utilities are able to include the column names in the same file as the unload output data. This was a requirement because one of the applications her company was planning to use takes the column headings and dynamically creates tables.
My initial reaction was that she could write a program that takes the output file and reads the system catalog to gather the appropriate column names. That would work, but she actually came up with a better solution.
She used a third party Unload utility (but it would also have worked with IBM’s Unload, too) to perform two SELECT statements. The first just creates the column headers and the second for the actual data. The column names and data go to two separate data sets, but they used IDCAMS to concatenate the 2 separate column/data sets into 1 data set.
The SQL is simple, something like as follows:
SELECT 'COLUMN NAME 1', 'COLUMN NAME 2',
'COLUMN NAME 3', 'COLUMN NAME 4'
SELECT COL1, COL2, COL3, COL4
Of course, you’d just plug in the correct column names in the literals of the first SELECT statement — and the correct column names in the second.
This post was originally posted on Craig Mullins’ blog.