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:

Wednesday, July 6, 2016

Run a SQL statement on another IBM i

strqmqry to get data from another ibm i

I work in an environment with many different IBM i systems. I use the word "systems" as some of these are partitions on the same PowerSystems server, while others reside on different servers. Often there is a need to extract information from one system, and send it to another where it will be used.

I have previously written about using DDM files to get information from other systems. But as I use SQL more I find they are limiting, as I cannot extract information from a DDM file using SQL statements. If only there was a way to extract data from one system by using a SQL Select statement issued from a second system.

After searching the new KnowledgeCenter I discovered a way!

Wednesday, June 29, 2016

Easy way to initialize columns when using SQL insert

use default keyword in sql

Regular readers of this blog know that I like to keep things simple and easy. Partly for my own peace of mind, and partly if it is simple then other programmers can quickly understand what my code does. A colleague calls this the K.I.S.S. methodology, which stands for "Keep It Simple Stupid", although she often changes the last "S" to "Simon" (I am not sure what she is trying to imply by this).

A good example is when using SQL to insert a row/record into a table/file. If not all the columns/fields need to be filled I need to give them a default value. This means that I need to look at the table and determine the data type of each column and whether it can be null or not, which takes time and can leave to errors if I try and accidentally insert a columns/field with the wrong default value.

Wednesday, June 22, 2016

Write to a file in the IFS using RPG

fputs c api to help rpg write to ifs file

After writing about how to read an IFS file in a RPG program I received a message from Domenico asking me how to do the opposite.

Very interesting article, as always, the only suggestion is: since, surfing internet, it is possible to find many examples about using _c_ifs_open but not one (!!) of _c_ifs_write .. it would be very very interesting and useful for our community.

Before I get started explaining how to write to an IFS file using RPG, let me say I am not going to repeat what I said in my earlier post A better way to read a file in the IFS with RPG, so you might want to review that before continuing with this post.

Tuesday, June 21, 2016

Happy 28th birthday!

Today is the 28th anniversary of the launch of the AS400.

You can watch a video of the launch announcement here.

Tonight I will be raising a glass of my favorite beverage to wish the AS400 and its descendents, up to the IBM i, a happy birthday!

You can also learn what your PC would have been like at the time of the launch here.

And the family tree that took the AS400 and evolved to became the IBM i here.