Wednesday, November 30, 2016

Discovering how much personal storage space remains

amount of user storage

This post is based upon something I made for myself, and after discussing it with some friends they said it would be worthy of becoming a post as others have the same need.

All of the code shown on this blog is written on servers generously provided by the IBM i hosting provider RZKH. Their hosting package gives me a fixed amount of storage, disk space, which I can use. While I am a careful user, who deletes all objects when I have finished with them and regularly clears my output queue, I want an easy way to see the following:

  1. How much storage space was I allocated when my profile was created?
  2. How much space have I used?
  3. How much space do I have left I can use?
  4. What percentage of my allocated space have I used? If I reach a certain percentage I know I need to start deleting and clearing immediately

Wednesday, November 23, 2016

Modern RPG Redbook updated version now available

A new draft of the IBM Redbook "Who Knew You Could Do That with RPG IV? Modern RPG for the Modern Programmer", completed October 20 2016, has been made available. I recognize many of the authors as people I respect as highly knowledgeable in the use of modern RPG.

The chapters cover many items which should interest anyone using, or wanting to learn, modern RPG:

Tuesday, November 22, 2016

Validation trigger in RPG

validation trigger written in rpg

When I wrote about creating a validation trigger in SQL several people asked me to give an example using RPG. Never being one to turn down a challenge this post is going to show how to do the same as my SQL example, but completely in RPG.

I am not going to go into the reasons why you might want to consider using validation triggers, as I gave my opinion in the previous post.

I started my previous example giving an example of a SQL DDL table, in this example I am going to use a DDS physical file. FILE1 has three fields:

Monday, November 21, 2016

Who remembers these? Print charts

who remembers rpg print charts

I could not resist posting pictures of a find I made in a box at home, a pad of IBM 132/10/8 print charts. The numbers denote that the chart is 132 characters wide, with 10 characters per inch and 8 lines per inch. These were used to assist programmers designing reports, and make it easier to translate the desired layout to Output specifications.

My wife had acquired the pad of charts in a previous job many years ago, and had put it in a "safe place" in case she needed them in the future. The charts had been stuffed into box of other old computer items during one of our moves, only to be rediscovered yesterday during one of those "I wonder what's in that box?" moments.

Wednesday, November 16, 2016

Creating a program to show jobs in message wait

sql rpg with subfile

I do get many requests asking for whole example programs, especially ones with a subfile, rather than just bits and pieces of code that I usually give in these examples. With this in mind this post brings a number of things I have written about before together into one program, which I thought would be an interesting refresher. So here goes...

I was asked to write a program to only show jobs that are in message wait status, and I want to add the ability give the user some options that would allow the user to analyze the error and reply to it.

To summarize what I need to do:

Wednesday, November 9, 2016

Coping with null with derived columns

using case with sql when derived column is null

I was assisting a colleague creating a SQL View when I encountered something I had not thought of before. He wanted to create a view with a derived column based on a column in the "right" table of a LEFT OUTER JOIN. Everything looked fine until the LEFT OUTER JOIN did not find a row in the "right" table. We could easily stop a null appearing for the columns from the "right" table, but what about the derived column?

Null is a concept that many people struggle with. I often have had to explain what null is and why it is different from blank or zero to older RPG programmers, who always have a confused or dismissive look in their faces. Users just don't understand the concept. This is why when I create output I always put some value in the column that comes up null.

Wednesday, November 2, 2016

Validation trigger

creating a trigger to validate the data

Triggers are a versatile database tool. A few weeks ago I wrote about using triggers to write data to an output file. I can also use triggers to validate data before it is written to the file or table. By placing the business rules and validation processes into the database with a trigger guarantees that:

  1. The same business rules are used every time. If the rules change I just need to change the logic in the trigger, rather than find all of the programs that output to the file and change the logic within them.
  2. It is not possible to circumvent the trigger. No matter which programming language or tool I use with the file the trigger will be executed. I will no longer have to worry about a rogue colleague changing data behind the scenes using something like DFU.

Wednesday, October 26, 2016

Using Null indicators with program's variables

nullind allows in null in rpg variables and fields

Null is a concept that RPG programmers are going to have to learn. Generations of RPG programmers have used a blank or zero in a variable to denote that it is not used or its value is not given. Null, in the simplest terms, means nothing, and if there is not a value for variable then null would be the ideal value to give it. If I had used a blank instead how am I to know, later, if blank is a valid value or is it being used to denote there is no value?

While null values can be found DDS files and SQL tables, it was not until IBM i 7.3 that I could code variables within my RPG programs that could be null.

Thursday, October 20, 2016

Creating User Defined Functions using only SQL

creating trigger in sql

In my previous post, Creating User Defined Functions to make my SQL statements easier, I gave example of how to create SQL User Defined Functions, UDF, using RPG. In this post I am going to show how I can create an UDF made up entirely of SQL.

I have created this UDF to concatenate the parts of the employee's name together. My example Employee Master file, EMPMST, has the following fields:

     A          R EMPMSTR
     A            LASTNME       30A
     A            FIRSTNME      20A
     A            MIDINITL       1A

When I look in the file I see:

Wednesday, October 19, 2016

Creating User Defined Functions to make my SQL statements easier

sql create function using rpg

The old ERP application I have to work with holds the "dates" in its files as seven long packed numeric fields, called *CYMD format. When I extract data from these files using SQL I always want to convert these "dates" to real dates, which I can the use for calculations, etc. I am tired of using the following SQL code to convert these fields to dates:

SELECT DATE(TIMESTAMP_FORMAT(CHAR(CYMD_DATE + 19000000),'YYYYMMDD'))
  FROM TESTFILE

And if the value in the numeric field is not compatible with a date the Select statement fails, and I have to fix the data with a best guess, and try again. It would just be so much easier if I could make the equivalent of a subprocedure to do this for me, then all I would have to do is call the "subprocedure" with the value to convert and it would return a valid date.

Wednesday, October 12, 2016

Scan has a new parameter and a new BiF

changes to %scan and new %scanr bif

While it was not part of the fanfare for the release of IBM i 7.3, there were some enhancements made to RPG. Two of the changes were made to the Scan built in function (BiF):

  1. Addition of a fourth parameter to the BiF for the length of the string to scan.
  2. A new BiF Scan reverse, which the name suggests starts the scan at the end of the variable and moves towards the start.

Let me jump straight into my code example so I can explain what differences these additions make. First I need the definitions for my example program:

Tuesday, October 11, 2016

IBM i 7.3 TR 1 and 7.2 TR5 announced

IBM i 7.3 TR1 and IBM i 7.2 TR5 announced

(Updated Tuesday October 11 at 6:00 AM)

Technical Updates for IBM i 7.3, TR1, and 7.2, TR5, have just been announced on IBM’s developerWorks and Software announcement web sites.

There is lots of additions and enhancement to SQL, including a new JSON_TABLE table function that is causing quite a buzz on social media.

Even RPG has a new addition, the operation code ON-EXIT. This will force a section of code to run when something unexpected happen. There is no easy link to find it in the Software announcement pages, you will have to use your browser’s search function and search for "ON-EXIT".

Both of the updates will be available on Friday November 11, 2016.

You can learn more from these links: