Notes

LTRIM, RTRIM and Trim Expressions

I have to admit that, when trimming strings with SQL, I tend to just use the TRIM function to strip off all leading and trailing spaces. But the LTRIM and RTRIM functions really do deserve more attention because they have been recently enhanced to support trim expressions. That is, all Read more…

By Paul, ago
Notes

Handling divide by zero in SQL

Division by zero is something that, sooner or later, we all have to capture. For the rest of this post, I am using a small temporary table that I have imaginatively named DIV0. It has two columns, COLUMN1 and COLUMN2 and it looks like this: COLUMN1 COLUMN2 5 0 6 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

Combining Counts for multiple tables

It’s surprising how many times you need to know whether a record exists in any one of two or more tables. Traditionally, you would have to check each table individually until you either find a match or have checked every table to confirm that no match exists. Finding myself faced Read more…

By Paul, ago
Notes

On holding jobs rather than job queues

Several months ago, I talked about Debugging RPG Programs in Batch and said that, before you submit your job, you should first hold the job queue. While this isn’t bad advice, exactly, it’s not what I actually do. When I am debugging a job in batch, I will submit it Read more…

By Paul, ago
Notes

Service Programs, signatures and RTVBNDSRC

I have talked about service programs in the past and, at the time, I mentioned that you need a binding source without really saying why. So, to revisit the subject, using the binding language allows you to change your service program without needing to recompile all of the programs that 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