Wednesday, May 28, 2025

Increment a number held in a character field

The title is simplistic for what this post is really about. The question that was asked was:

I have a character field in a DDS physical file that is 20 characters long. There can be various numbers in that field of any length. I want to retrieve the value from the field, increment it by one, and update the field in the file.

If all the "numbers" in the field in the file were 20 characters long it would be easy, but as the "numbers" can be of different lengths it makes the problem more interesting.

First I need a file for this 20 character field. I decided to call it TESTFILE and the DDS code for it is:

01 A                                      UNIQUE
02 A          R TESTFILER
03 A            KEY            5A
04 A            FIELD1        20A
05 A          K KEY

Wednesday, May 21, 2025

SQL scalar function to break apart IFS path name

As part of the new new release, IBM i 7.6, and the latest Technology Refresh for IBM i 7.5, TR6, I can break apart an IFS path name into its parts:

  • File extension
  • File name
  • File prefix (file name without the file extension)
  • Path prefix (path without the file name)

This new SQL scalar function is called IFS_PATH, and it is found in the library SYSTOOLS.

Before I start with my examples I need to check if there are objects in the IFS I can use. This is a simple task using IFS_OBJECT_STATISTICS:

Wednesday, May 14, 2025

Selecting updated and deleted values when using SQL

Have you ever wanted to confirm that a SQL Update or Delete statement ran the way you expected?

In the new release, IBM i 7.6, I can do this using what IBM describes as:

  1. Selecting updated values
  2. Selecting deleted values

This was not added to the latest Technology Refresh for IBM i 7.5, TR6.

Tuesday, May 13, 2025

SELF default changes

While playing with the new release, IBM i 7.6, I noticed that the default for the SELF, SQL Error Logging Facility, SELFCODES global variable has changed.

When it first came out, IBM i 7.5 TR1 and 7.4 TR7, the default for the SELFCODES was null.

With IBM i 7.6 and 7.5 TR6 the default is '*NONE'.

Why the difference?

Both null and '*NONE' are acceptable as the default. The difference is that '*NONE' will stop SELF monitoring immediately. Null does not, only when new SQL 'jobs' start.

 CREATE OR REPLACE VARIABLE SYSIBMADM.SELFCODES VARCHAR(256) DEFAULT '*NONE' ;

This is another good enhancement to SELF.

Wednesday, May 7, 2025

Where on the subfile is the cursor

I was asked how is it possible to determine where the cursor is on a subfile when the F4 key is pressed.

I have written about the parts needed to achieve this in separate posts, and I thought it would be a good idea to put it all together into one new post.

What I would need is:

  1. A subfile program
  2. Determine when the F4 is pressed
  3. Retrieve the record format name
  4. Retrieve subfile relative record number, RRN, of the record the cursor is on
  5. Retrieve the name of the field the cursor is on in the subfile

First off, I need a subfile display file, a simple one. The code for a minimalist subfile could be:

Monday, May 5, 2025

IBM Performance documents updated for Spring 2025

Steve Will, IBM i Chief Technology Officer and Chief Architect, announced this week that new versions of the following documents had been updated by the IBM performance experts:

  • IBM i on Power - Performance FAQ – see here
  • IBM Power10 performance optimization for IBM i – see here

IMHO I think they both are worth checking out.

Wednesday, April 30, 2025

Report of the success of the nightly saves

My manager asked me if I could provide him with a report of all the libraries that were backed up as part of the night process job, NBACKUP. "You know what I mean: one line for each library" was his final statement to me.

I did want to browse a different job log for each day. I wanted to design something that was simple. I decided to use the HISTORY_LOG_INFO table function. I could select results using:

  • Starting timestamp of 1 day (24 hours) ago
  • I know the job name

I started with this SQL statement:

Wednesday, April 23, 2025

Quickest way to determine which day of the week today is

In a program I wrote recently I needed to return which day of the week today is. My first thought was to use SQL, as it would only be one line of code. But is that the fastest way to return today's day name?

I thought about writing my own RPG routine to calculate the day name, but decided to use Google to see if there was a better example. I found an article by Rafael Victoria-Pereira for MC Press from 2015 that gave what I think is an efficient way to do this, you can read his article here.

Using his example I refactored the RPG code up to 2025 standards and created this procedure:

Monday, April 21, 2025

Useful manuals

I have few more recent IBM manuals that I wanted to share with you, including the one I have been waiting for since the IBM i 7.6 announcement:

I hope you find these links interesting and useful.

Friday, April 18, 2025

IBM i 7.6 available today

The new release of the IBM i operating system, IBM i 7.6, is available today. While 7.6 will steal the headlines today, there is a Technology Refresh for IBM i 7.5, TR6, that is also available.

If you have missed all the news, you can find out what is in the new release and the new TR, here.

Wednesday, April 16, 2025

LISTAGG scalar function can return distinct results

I did not realize it had been so long since I first wrote about the LISTAGG scalar function. I mentioned very briefly in that article something that became very useful to me just a short while ago.

The LISTAGG scalar function aggregates the results from a one or more rows into a single new column, separated by a character of my choice.

In my scenario I have a table, TESTTABLE, that contains a column of colors, COLOR:

01  SELECT COLOR,COUNT(*) "Count" 
02    FROM TESTTABLE
03   GROUP BY COLOR

Tuesday, April 15, 2025

Award for this website

I was notified yesterday that this website, RPGPGM.COM, had won an award.

Anuj Agarwal, founder of FeedSpot, informed me of this:

I would like to personally congratulate you as your blog Rpgpgm.Com has been selected by our panelist as one of the Top 45 IBM Blogs on the web.

https://bloggers.feedspot.com/ibm_blogs/

This is the most comprehensive list of Top 45 IBM Blogs on the internet and I'm honored to have you as part of this!

RPGPGM.COM is ranked in fifth place.

Thank you Anuj, and the panel at FeedSpot, for this honor.