Wednesday, August 24, 2016

Extracting data from journals using SQL

display_journal journal dspjrn

Previously I wrote about how to extract data from a Journal using the Display Journal command, DSPJRN. There is an alternative approach with SQL using a User Defined Table Function, UDTF, called DISPLAY_JOURNAL. When I use a SQL Select statement this will return the same information as the output I was using from the DSPJRN command. Unlike the output from the DSPJRN command that comes in four different formats, the output from DISPLAY_JOURNAL has to be all things to all men, and contains more information than I need. You can see all the available columns in the IBM documentation that I have provide a link to at the bottom of this post.

I am just going to do the same as I did in the previous post, I want to get the changes made to a file on a specific date. As this is really a continuation of the previous post I am not going to repeat a lot of what I talked about there, if you feel I have missed something then check in that post.

The information I want is:

Wednesday, August 17, 2016

Extracting data from journals

extract data from journal using dspjrn

Many of the posts in the blog come from questions asked by its readers, this is another example. I received a message asking if I would explain how to extract data about changes made to a file from a journal.

Journaling on files, simply put, is a record of all changes made to one or more files. This information can be used in commitment control operations, allowing for changes to be rolled back, or for replicating changes to a disaster recovery replica of the production system. As the files the questioner asked about are being journaled we can get a copy of the changes made to a file.

How can you tell if a file is being journaled?

Wednesday, August 10, 2016

Changing column headings in output file

using sql to change names of fields or columns in output file produced by query

I am sure there are some who are going to criticize me for saying this, but I do use Query. While I do not use it for "production" reports, I do use it is a quick and easy way to check data, or even to generate a quick "one off" output file. Yes, I know I could use SQL to do the same, but sometimes it is just, in my opinion, quicker and easier to use Query.

One of the drawbacks of using Query are the Column Headings it produces for outfiles. If for example I join a file to itself and/or "define a result field" the Column Heading produced is unclear or outright confusing. Even if I go into the option to "Specify report column formatting" and change the Column Headings, I still get the original column headings in the outfile.

I could email myself/download the file and change the column headings in Microsoft Excel, but there must be an easy way to do it? Fortunately there is using SQL.

Tuesday, August 9, 2016

Modernize your CL too

modernize your cl code using these techniques

I spent the end of last week assisting my colleagues with a project that involved creating CL programs, and over the weekend I was asked to check someone's CL code. In both cases I was disappointed to find that while these individuals have modernized their RPG skills, their CL skills are still date back to the 20th century.

In my opinion CL is a programming language which is undervalued in IBM i circles. I have met many developers who would rather use a complicated API in their RPG code, rather than use a simple CL command. It is time for everyone to look at all the tools that are available in IBM i, rather than limit themselves to just be a "RPG programmer".

Here are some of the things I think we should all do with our CL code.

Wednesday, August 3, 2016

Retrieving System Values using SQL

retrieve system values using sql

I am sure we have all had to retrieve a System Value. I would use the Retrieve System Value command, RTVSYSVAL, to do so. In one of the Technology Refreshes to IBM i 7.1 a SQL View, SYSTEM_VALUE_INFO, was introduced to allow us to access the same information using a simple SQL Select statement.

For those of you who worry that this might allow people to change System Values using SQL, rest assured that as this is a View it cannot be used to change data.

SYSTEM_VALUE_INFO contains three columns/fields:

Wednesday, July 27, 2016

Use Select to retrieve one record of data

select into is used to retireve one record from a file

The germ for this post came from a question I was asked by a reader of this blog:

In SQLRPG do I have to define cursor, open cursor, fetch, close cursor if I only want one record?

That is a lot of work just to retrieve one record. Fortunately there is a very simple method where I can retrieve a field, multiple fields, the entire record, or join to another record, etc providing I am just returning one record/row.

Saturday, July 23, 2016

Thank you OCEAN

I wanted to take this opportunity to thank all of the organizers of this week’s OCEAN Technical Conference. It was another excellent conference, with great speakers, who I want to thank too.

And it was great to talk to all the other IBM i folks attending the conference to share our individual stories.

Events like this is proof of the value of the user group community.

Wednesday, July 20, 2016

The versatile Clear operation code

use the clear operation code to initialize field, variable, record format. no more z-add

When I wrote about using DEFAULT in SQL statements it made me think if there is an equivalent in RPG. The Clear operation code sprung to mind. CLEAR has been around for many releases, including in RPGIII. It initializes the value of a variable, field, data structure, array, record format, etc. to the data type's default value.

I use CLEAR extensively because…

Wednesday, July 13, 2016

How to monitor for function keys when prompting a command

In an earlier post I wrote about prompting commands in a CL program, and allow you to change some of the command's parameters. But I did not give the logic on how to cope if the F3, Exit, or F12, Cancel, keys were pressed.

How to differentiate between the F3 and F12 keys being pressed was a subject of a discussion in one of the Facebook groups I am a member of. As I should have mention this in my earlier post I thought I would give an example of how I would do this.

The person asking the question was prompting the Display User Profile command, DSPUSRPRF, and need to: