Wednesday, February 11, 2015

Reading a SQL table in SQL

sql fetch update insert to red update write to sql table

In a previous post I explained how to handle a SQL table using RPG operation codes to perform the file access. The post was just to illustrate that it was possible. I received messages expressing surprise that I had chosen to use RPG and not SQL. I think those who sent me those messages missed the point of the post. Anyway in this post I am going to show the same example, but using SQL for accessing the SQL table.

If I was doing this myself I would probably replace the entire DO loop in the RPG program with the following SQL statement:

Wednesday, February 4, 2015

Finding triggers using SYSTRIGGER

trigger information from systriggers

Triggers allow business logic to be placed at the file/table level, independent of the software. When you access the file/table with a program, SQL, DFU, or DBU the trigger will execute. Before making changes to objects or creating test data it is important to find what triggers are present on which files and tables to stop them from executing in unexpected manners.

Fortunately there is a SQL view, SYSTRIGGER in QSYS2, that contains all the information we need to know about all the triggers on the IBM i. I am not going to list all the columns in SYSTRIGGER as IBM's documentation job does a good job of doing it here.

Wednesday, January 28, 2015

Reading a SQL table in RPG

reading sql table in rpg

This idea for this post comes from a Comment posted on Creating a SQL table on the fly. Anonymous posed the question "Now how do you use that table in your RPG program?".

The post I describe how it is possible to use the SQL CREATE TABLE to build a SQL table extracting data from another file. I have mainly used this in processes that extract data and then send the extracted data to the requester via email. But there is no reason why I cannot read the table created in a RPG program.

Wednesday, January 21, 2015

How to replace Key Lists

replace klist with %kds key data structure or key field list

As we now have all free RPG we need to find ways to move from familiar fixed format definitions to free format equivalents. Key lists, KLIST, are a good example. I still see new programs written in RPGLE with free form calculations, but with fixed format Key lists.

  C     KeyTestfile   klist
  C                   kfld                    wkFld1
  C                   kfld                    wkFld2
  C                   kfld                    wkFld3

The solutions was provided back in V5R2:

Wednesday, January 14, 2015

Trim in CL and its Second Parameter

trim (%TRIM, %TRIMR,%TRIML) is now in CL. And did you know that there is a second parameter to state which characters you want trimmed?

I am sure I am not the only person who has been using the Trim built in functions (BIFs) in their RPG code to remove leading and trailing blanks from strings. Trim BIFs were introduced into CL with IBM i release 7.1, and function in the same way as their RPG brethren.

Were you aware that the Trim BIFs have a second parameter that can be used for removing characters other than blanks? I have Miguel Cordova to thank for bringing this to my attention. Using the second parameter I can remove any character using the Trim. Below I will show examples in RPG and in CL, and discuss what I found in using them in both languages.

Wednesday, January 7, 2015

Which Control options/H-specs do you use?

rpg control specification

In my many years of experience working for various companies I have found that just a few programmers define Control specifications in their RPG programs. The Control specification is commonly known as the Header specification, or H-spec, as in fixed format RPG the specification character, in the sixth position of the line, is 'H'. In all free RPG the Control specification was replaced by the Control options, 'CTL-OPT'.

In my opinion this was the most cryptic of the specifications in RPG III as you had to know what each column stood for, as it would only reveal its meaning when F4 was pressed to prompt the line.

Thursday, January 1, 2015

Happy 2015

I have always found New Years exciting, a new year is ahead of me that will be full of exciting new things and adventures. It is also the chance to bid farewell to the old year, and revisit its highlights.

2014 was an exciting year in the IBM i world with the following:

Wednesday, December 31, 2014

Display release of IBM i

display ibm i release

One of the first things I do when I first signon to an IBM i is to check what release of operating system it is running. Armed with that information I then know what version programming tools and language features I will need to use.

Fortunately there is a quick way and a not so quick way, that takes just a few more key strokes.

Monday, December 29, 2014

Operating systems release history

Server name Operating
system
Release Available
date
End of
Support date
AS400
(Application System/400,
1988-2000)
OS400
(1988-2006)
Rel 1 August 26, 1988 ?
R01M00 ? ?
R01M01 ? ?
R01M02 November 25, 1988 ?
R01M03 ? ?
V2R1 May 24, 1991 June 30, 1994

Tuesday, December 23, 2014

Getting field definitions using SYSCOLUMNS

Use SYSCOLUMNS to get list of fields in file

In several previous posts where I have used the DSPFFD command, see here and here, or the QUSLFLD API, see here, to retrieve the Column Heading of fields in a file someone has commented that I should retrieve the column headings using the SYSCOLUMNS file. In the scenarios described in those post using SYSCOLUMNS would not have worked as it only contains data for files not in QTEMP.

SYSCOLUMNS resides in the library QSYS2, and is a SQL view built over the physical file QABDIFLD. It contains the field/column information for all the files and tables in every library on your IBM i, except those in QTEMP. I am not going to list all the columns in SYSCOLUMNS as the IBM documentation does a good job doing it here.

I am going to show two scenarios how I could use SYSCOLUMNS:

  1. List all of the fields in a file.
  2. List all the occurrences of a field name in all the files in a library.

Wednesday, December 17, 2014

Using aliases can be simple

using alias in rpg

The discussion of whether to use the alias names for files’ fields has become a lengthy here amongst the programming staff. The major argument against has been that there does not appear to be an easy way to perform input or output to record formats in display and printer files. I needed to find a simpler way to define the alias and its uses.

Fortunately IBM came to my aid with PTFs to make the using of alias simple in IBM i 7.1 and 7.2. In my opinion this is the way alias handling should have been from the start.

Tuesday, December 16, 2014

Node.js now available

node.js released for ibm i

Node.js was promised as part of Technical Refresh 9 for IBM i 7.1 and TR1 for 7.2. It was released yesterday, December 15 2014, as a new License Program Option.

Node.js is an open source runtime environment for server side and network applications. Its applications are written in JavaScript using Google's V8 JavaScript engine to execute code. Its runtime can execute on OS X, Microsoft, Free BSD, Linux (which can be hosted on a PowerSystems server along with IBM i) and now IBM i.