Wednesday, September 25, 2013

Alternative to SELECT is IF-ELSEIF

The RPG operation code SELECT as been with us for many years. It is also found in many other languages, including CL (see the post SELECT in CL).

An alternative was introduced in one of the IBM i V5 releases, the IF-ELSEIF operation codes. If the first IF is not true then the first of the ELSEIF is executed, just like the WHEN in the SELECT group.

Friday, September 20, 2013

Validating dates in RPGLE

I received an email asking me the following question:

What about date validation?

Dates on a screen are usually displayed as MMDDYY. I don't need to add days or months to it, I need to ensure that the date itself is valid.

I can think of two approaches of displaying and validating dates on a display file.

  • Use a date field.
  • Use a 6,0 numberic field.

Wednesday, September 18, 2013

More SQL and dates part II

This post is a continuation of a previous posting More SQL and dates part I, and is based on an email I received from Scott Damery.

"We can all become SQL black belts with knowledge and practice," he reassured me.

In this post I am going to compare SQL to RPGLE/RPG IV.

Thursday, September 12, 2013

More SQL and dates part I

After my post on calculating the last day of the month using SQL, Calculating end of month part II, I received an email from Scott Damery.

"Take advantage of the many date functions in SQL instead of programming code to provide the information needed," he said in his email.

I am a great believer in: if there is a function to do a process use it, rather than code your own.

Below are the SQL functions he mentioned with a couple of others I found:

Tuesday, September 10, 2013

Renaming one field in a file in RPG

I was asked to quickly modify a program. The program currently uses a file, I'll call it FILE1, and the modification was to add a second file, FILE2 to it. If the user selects to search for a certain type of information the the program would uses FILE1, if they want to search for a different type of information the program would need to use FILE2.

All of the fields in FILE1 and FILE2 have the same names and attributes, except for the Part number field. The Part number field, PART, in FILE1 is 20 long, in FILE2 it is 15.

I cannot change FILE2 to make PART be the same length as it is in the other file. I must make the minimum amount of changes to the program to negate the need for it to be audited by the SOX auditors. What can I do?

The changes I would need to make would be:

  • Create a 'which file' field to be used to determine which file the search is for.
  • Add USROPN to the File specifications, F-spec, for FILE1 and FILE2. This means that the file will only be opened if I use the OPEN operation code to open it.
  • Use the value in the 'which file' field to condition which file is opened.
  • Decide which file to read by using the 'which file' field.
  • Close the file opened.

But that still leaves the problem of what to do with the two PART fields.

But how do I cope with the difference between the two PART fields with the minimum of code changes?

Using the PREFIX keyword in the F-spec would not do, as that would rename all the fields in FILE2.

Then it struck me, I could use a way I had used before in RPG III.

Thursday, September 5, 2013

Externally described Data Structures

I have been racking my brain to try to remember when I first came across Externally Described Data Structures in RPG. I think it must have been when I transitioned from being a RPG II programmer on the IBM System/36 to a RPG III programmer on an AS400 (yes, I am that old). The others I was working with at the time were all former IBM System/38 programmers and were "fluent" in RPG III. They did not use Externally Described Data Structures. and I was the "newbie" learning RPG III from them, so neither did I.

It was while I was working on a project programming in Synon/2E, and later modifing Synon generated RPG code, did I find them used everywhere. Synon uses Externally Described DS for passing parameters, saving the values of fields in files, and for the Program Status DS (PSDS).

What do I use Externally described Data Structures for?

Tuesday, September 3, 2013

Equivalent of SETLL using SQL

I received several messages and comments in response to my post Validation: CHAIN versus SETLL informing me that I can do the same in SQL.

Alas, no-one sent me any examples of how they would do it. Therefore, after some Googling I found a way.

Sunday, September 1, 2013

CHAIN versus SETLL the results

Having started the debate on which is faster in my post Validation: CHAIN versus SETLL I decided to put the theory to the test.

I created a DDS file with a single key:

  A                                      UNIQUE
  A          R TESTFILER
  A            KEY            7P 0
  A            F1             3
  A            F2             5P 0
  A            F3            30
  A            F4             3P 2
  A            F5            50
  A          K KEY

And filled the file with a million records, the field KEY contained the values of 1 to 1 million.

I created two almost identical programs. Each one would perform their operation 1 million times, and write a record to an output file with the Start time, End time, and the number of milliseconds it took to perform the 1 million operations. Those programs are listed below: