TechTip: MS Excel--They Gotta Have It!

  • Smaller Small Medium Big Bigger
  • Default Helvetica Segoe Georgia Times
Never mind that the it referred to in the title may be totally inappropriate. Never mind that it may take longer than other methods. Never mind that the user is not properly trained in the use of it. The fact is that users love their MS Excel spreadsheets and will work with them to the exclusion of all else. No matter what! If you work with these users, and I know you do, you must be prepared to format AS/400 data into a spreadsheet. Your pleas of reason will go unheeded. Your pleas of logic will go unheeded. The fact that you can design a better, faster, more appropriate application for the data is irrelevant. Into the spreadsheet it must go. They gotta have it!

There are at least a dozen methods of accomplishing this goal--file transfer, ODBC, VBA, FTP, and many others. The biggest problem occurs when the goal is automation. That is the ability to create the spreadsheet on the AS/400 and send it to the end user, without the user lifting a finger, and you know that the user only occasionally will lift a finger.

The method I have devised for full automation is a combination of COPY commands and SMTP distribution. I use this because much of the work is done in background, during regular production runs. The users may or may not be available at the time the jobs are run. This design allows the spreadsheet to be distributed during regular daily, weekly, or monthly production runs. The users will receive the spreadsheets the next time they open their email.

The process starts with a DB2/400 physical or logical file. I have not tried this with logicals, but I see no reason why it should not work. I do know that the result of an OPNQRYF will not work. You must use the CPYFRMQRYF command before CPYTOIMPF. In other instances, the CPYTOIMPF command is used first. This command has an interesting quirk, which requires a dry run one step at a time, prior to running all commands from a CLP. Here's the quirk: The CPYTOIMPF command will not perform EBCDIC-to-ASCII translation when creating the target file. This is annoying, but you can work with it. The target file should be somewhere on the IFS. I use a folder in QDLS for reasons that will be apparent later, but this is not an absolute requirement. The CPYTOIMPF command should specify a delimiter of *CRLF so that the spreadsheet program can later use the data. Once the file has been created on the IFS, use the CPY command to create a *PCASCII version of the same file, with a suffix of .csv. All subsequent uses of CPYTOIMPF specifying *REPLACE and the CSV file as the target will perform the EBCDIC-to-ASCII translation without the CPY step.

Once the CSV file has been created, you may then use the SNDDST command, with the TYPE(*DOC) parameter specified, to email the CSV to the intended, I mean user. You can only use TYPE(*DOC) if the file is located within the QDLS directory. Despite the removal of OV/400, this works fine for V5R1 and above. In order to use SNDDST to an Internet address, SMTP must be configured.

When the user opens the CSV file, it should open automatically within MS Excel. When the user saves the file, a native Excel format can be used.

I have found this method to be quick and relatively painless. The technique can be embedded in almost any native AS/400 application, and a great deal of leeway is accorded the programming of distribution lists. The bottom line is that this method is quick and easy, and it works, even when the users don't.

David Abramowitz is an independent consultant. He may be reached at This email address is being protected from spambots. You need JavaScript enabled to view it. in columns and rows.