Old School Batch Programming and Code Generation

Recently I had the opportunity to do some old school Windows batch file programming at work. At first I was not too interested in using a language (is that even the correct word for it?) as old as DOS, but after I got into the project it was actually rather fun.

First, a little back story about the project. The company I work for uses many mainframe systems today that it has used for decades. But, like most big companies, it has many modern server systems as well. To use these systems together we often have to move files containing large amounts of data between servers and mainframes. To accomplish this task, a piece of software called Connect:Direct is used.

Because of the way we used this software, the setup and maintenance was really a pain. First, to setup a file to be moved to/from a mainframe and server, a Connect:Direct “process” has to be setup which consists of a file containing some propriety code to instruct Connect:Direct on what the process should do and how it should run. The file was just text containing some code with a CDP extension. In addition to the CDP file, we had two more simple files per process. One simple batch file so the users of the process can run it simply by double clicking on an icon and a simple text file to be used by the batch file which contains some instructions on which CDP file to use and some variables to use. What that meant was three files per process and a maintenance nightmare. Why a maintenance nightmare you ask? Because a server was recently done away with so every single of our 300 files had to have some details changed.

Since my coworkers and I knew we would have to change many files we decided to streamline the process a bit. Initially we decided to just combine the batch files into one and have a simple menu so the users could choose the process they wanted from there. Since I was the one writing the batch file I got to work.

After a bit of work though, I realized that more could be done than merely combining the batch files – we could actually do some code generation. That’s right, code generation with a batch program. Now obviously it couldn’t be too complex seeing how this would be done in a batch program, but a rudimentary form of code generation is possible.

What I ended up doing was generating the text and CDP files on the fly, executing the Connect:Direct process with them, and then deleting the files afterwards. All the configuring is done in the batch file by setting few variables containing the changing data. What this resulted in was the elimination of 300 files and and extremely easy way to modify processes as well as an easy way to add new processes in the future.

Before this project I had done a very limited amount of batch file work before. Perhaps what we did could have been done in some other “better” way, but I doubt in the time it took to get this up and running. Batch files might not be very sophisticated, but don’t underestimate there power. Under the right circumstances, they can really prove to be invaluable.