Wednesday, January 27, 2016

Read an IFS file using RPG

read ifs rpg

I had a situation where I had a text file in an IFS folder and I needed to read its contents. I could have copied the file from the IFS into an IBM i library and then read it there, but I decided to investigate how I could read the file directly from the IFS using RPG. Fortunately there are three APIs which will allow me to do this.

First I need to give credit to a friend of mine, who wishes to remain anonymous, for providing a program that my example is based upon.

I created a text file using Windows' Notepad. At the end of each line I pressed Enter to create variable length records, see below, and copied the file to my folder in the IFS.

Monday, January 25, 2016

More proof IBM i 7.3 is coming

IBM i 7.3 7.2 TR4

On December 17 I found a reference to IBM i release 7.3 on an IBM website, you can see it here. This weekend I found further proof that a new release is coming.

In the IBM developerWorks website there are now sections for IBM i 7.3 and 7.2 TR4 enhancements, which were created on January 13.

Wednesday, January 20, 2016

Using SQL for object's statistics

object statistics dspobjd

I have mentioned in a previous post how you could find out pretty much anything you wanted to know about a file or SQL table by using the SQL View SYSTABLES. But what about other object types?

I have found the OBJECT_STATISTICS table function useful for most of the information I want to know about objects in a library. Table functions return columns in way that resembles getting columns from a View or Table.

OBJECT_STATISTICS has three parameters:

Wednesday, January 13, 2016

Retrieving the program's name in a CL program

sndpgmmsg rcvmsg

I have always had a standard that whatever output I produce from the IBM i I always put the program's name on it. This is very useful when a user brings me a screen print or report I can quickly go to the program they have a question about. Many years ago I found that some of my colleagues would copy my display and printer file code without bothering to change the name of the program "hard coded" on the file. To overcome this I code the program name as a field in the file, and I always retrieve the name of the program from within the program itself. In RPG the program name is a subfield in the Program Data Structure so it can be easily retrieved, for an example see the post Externally described Data Structures.

Wednesday, January 6, 2016

Finding record locks using SQL

sql record lock info

One of the new SQL Views introduced as part of IBM i 7.2 TR3 and 7.1 TR11 was one that allows us to check for record locks. Now I can execute a SQL query and return all of the jobs locking the file I inquired about. No longer do I need to use APIs or the CL command Display Member Record Locks, DSPRCDLCK.

The new View, RECORD_LOCK_INFO, is found in the library QSYS2. It returns one row of every lock in your IBM i. This is why I should be careful how I use this View. I am sure there are many thousands of record locks in any medium to large size applications at any one time, most of them are harmless as the record or row is locked, updated and released. Every once in a while something goes "bump" and a tries to lock a record/row that is already locked by another. An error message occurs and I have to work out what the lock is and how to release it, in a timely manner, before I get more record locks to the same record/row.

Friday, January 1, 2016

Happy New Year

At the start of a new year I am always filled with a feeling of excitement for what the new year will bring us, and a feeling of gratitude for all the good stuff that happened last year.

Last year's most popular posts covered a good variety of subjects:

  1. Change date from one format to another using SQL
  2. Char built in function added to CL
  3. IBM i 7.1 TR10 and 7.2 TR2 announced at Common
  4. Trim in CL and its Second Parameter
  5. Getting the number of rows affected by SQL statement

We also have the following IBM i anniversaries to look forward to in 2016: