Notes

Close *ALL the files on-exit

I have previously mentioned the ON-EXIT operation code, and now it’s the turn of something I should have known about years ago. Back in the old days, handling files was simple. All of the files you declared would be opened when the program starts and closed again when the program Read more…

By Paul, ago
Notes

Querying data queues with QMHQRDQD

Someone recently asked me if I knew of an API that could be used to retrieve the number of entries in a data queue without pulling the entries from the data queue. I didn’t, but a quick search turned up QMHQRDQD.: The Retrieve Data Queue Description (QMHQRDQD) API retrieves the Read more…

By Paul, ago
Notes

Returning data structures from Procedures

This post stems from recent conversation on the subject of prototyped parameters. I always pass parameters as read only (using the const keyword) in order to ensure that no unexpected changes in the called procedure can impact the calling procedure. With this approach, the only value you need to worry Read more…

By Paul, ago
Notes

Guaranteed exit code with ON-EXIT

Here’s handy: The ON-EXIT operation code begins the ON-EXIT section. The ON-EXIT section contains code that runs every time that the procedure ends, whether it ends normally or abnormally. The ON-EXIT section runs under the following conditions: The procedure reaches the end of the main part of the procedure. The Read more…

By Paul, ago
Notes

Converting to CHAR with leading zeros

This is as much a reminder to myself as anything else because the %CHAR built in function has the unfortunate behaviour of stripping leading zeroes when converting a number to a character value. Sometimes I need to keep those leading zeroes, for example when handling elderly date fields. Fortunately, there’s Read more…

By Paul, ago
Notes

Using %TLOOKUP: An example

Firstly, a disclaimer. The CTDATA definition keyword indicates that an array or table should be loaded at compile time. This is a terrible idea for a whole host of reasons, not least of which is that the data is locked away in the program and that you need a programmer Read more…

By Paul, ago
Notes

Writing messages to the joblog with QMHSNDPM

I have previously mentioned using Qp0zLprintf (Print Formatted Job Log Data) to write messages to the joblog. Here’s an alternative approach using QMHSNDPM (Send Program Message). In this case, I am executing an SQL statement and checking the SQL state afterwards. If the state is not 00000 (completed normally), I Read more…

By Paul, ago
Notes

Fun with varying length fields

So here’s a really simple little program that puts the first five characters of a ten character field into a five character field. So why doesn’t it work? **Free // Fun with variable length fields ctl-opt dftactgrp(*no) actgrp(*new) main(Main); dcl-proc Main; dcl-pi *n end-pi; dcl-s LongString varchar(10) inz('123'); dcl-s ShortString Read more…

By Paul, ago