Wednesday, April 25, 2018

Easy to create shortcut commands

creating your own shortcut commands

After my post about how to create your own commands I received messages from readers giving me examples of how they have created their own shortcut commands, to do the same as the standard IBM i command but shorter. In one example the command SP did the same as WRKSPLF.

I don't think many people know of proxy commands. These allow me to create shortcut commands of the regular IBM i commands without any programming. You can even make proxies of proxy commands, although I cannot think of a reason why I would ever think to do so.

In this example I am going to create a proxy command, SP, for the Work with Spooled Files command, WRKSPLF.

Wednesday, April 18, 2018

Sending your own program created messages to the error subfile

filling the error subfile, errsfl, with program generated message

I have previously written about using the error subfile to display error messages, rather than the message subfile. Personally I like using the error subfile as it is another case of allowing the operating system to do the work for me.

Since publishing that article I have received messages asking how can people create their own error message text, in the RPG program, that is displayed in the error subfile.

Fortunately there is a simple way to do this that will work in either RPG in CL.

No matter which language I use the display file can be the same. Here is the display file I will be using in this example.

Wednesday, April 11, 2018

Built in function to return name of procedure

%proc built in function to return procedure name

Until the last round of Technical Refreshes, IBM i 7.2 TR7 and 7.3 TR3, I could not find a way to retrieve the name of the procedure that I was in. The program data structure enticed me with the *PROC keyword. This was not the procedure's name, but rather either the program's or module's name.

01  DPgmDs           SDS                  qualified
02  D ProcName          *PROC

01  dcl-ds PgmDs psds qualified ;
02    ProcName *proc ;
03  end-ds ;

Fortunately these two Technical Refreshes introduced a new built in function, BiF, to returns the name of the current procedure: %PROC

This example is of what I call a closed subprocedure and how this new BiF works.

Wednesday, April 4, 2018

Handling nulls in CL

in a cl program how to handle a null value from a file

I have written previously about how to handle nulls values in RPG and in SQL, but until this week I had never had a problem with null in a CL program.

The CL program was "reading" a SQL table, where some columns/fields were null.

    ORDNBR      ORDSTS       ORDVALUE
01 PO18087       P            145.67
02 PO18556       C             15.36
03 PO18223       -                  -
04 PO18777       D                  -

The CL program is simple.

Happy patron saint's day!

Today is the saint's day of Saint Isidore of Seville.

In 1997 Pope John Paul II, of the Catholic Church, decided that computers and the internet needed a patron saint. His choice was St Isidore of Seville, "the last of the great scholars of the ancient world".

I hope you all have a good St Isidore Seville day. But if you need divine intervention for your computer problem this is the day could be the right day to ask for divine inspiration.

To learn more about St Isidore of Seville see here.

I need to say "St Isidore of Seville" rather than just "St Isidore" as there is another saint of the same name, "St Isidore the farmer", who is the patron saint of farm workers and the communities they live in.

Wednesday, March 28, 2018

Processing simple XML using XML-INTO

xml using rpg xml-into

I had received notification from a supplier that they were changing the order file they send my employer. Previously they sent a Microsoft Excel spreadsheet, starting the end of this month it would now be a XML file. In the past if I need to convert a XML into data in an IBM i file I would use the EDI application to do the conversion. As the XML is so simple I decided to process its contents in my own RPG program.

The operation code XML-INTO takes information from elements in the XML document and, in my example, places them into data structure subfields. I believe that this operation code has been around since V5R4, I am just a late comer to using it.

The XML document I will be using in these (very) simple examples contains a (very short) list of names and the city and state the person is in. The proposed format of the XML file the supplier sending me is very simple too, no need for anything complicated.

Wednesday, March 21, 2018

Handling divided by zero in SQL

coping with divide by 0 in sql update

One of the messages that annoys me the most is "Attempt to divide by zero". I am sure every programmer, no matter, what language they use, has encountered this at least once. It frustrates me is there is not much we can do to fix the error once it has happened. It annoys me that this can be handled very well within the program to prevent the error.

Before I get started I know there are a couple of different ways the division calculation can be described, I did check. I will be using the following:

   Result = Dividend / Divisor 

It is the Divisor that must be zero for this error to occur, as:

Monday, March 19, 2018

Creating a list of journaled files, improved

finding which files are journaled using sql object-statistics

In my previous post about making a list of files in a library that are journaled I stated that I could not find this information in any Db2 for i view or table function.

Krister Karlsson brought to my attention that the information is available in the OBJECT_STATISTICS table function. Looking at the documentation from IBM it would appear to have been added in the previous round of Technology Refreshes.

Rather than using the Display Object Description command, DSPOBJD, I can get the information I desire from a simple Select statement.

Friday, March 16, 2018

New Technical Refreshes released today

ibm i 7.3 tr4 7.2 tr8 made available

The latest IBM i Technical Refreshes for version 7.2 and 7.3, that were announced in February, were released earlier today.

The information about the PTFs can be found here:

One thing to be aware of is that these probably do not contain the PTFs for the latest changes to RPG, these will be released on Monday March 19. These PTFs are listed here.

Wednesday, March 14, 2018

Creating a list of journaled files

make list of files being journaled

"How do we know what files are journaled in library x?" one of the programmers asked me. A straight forward question, but where to find the information?

I could not find reference to journals in either the Db2 for i Views SYSTABLES or SYSTABLESTAT.

I could find a fields for journal information using the Display File Description command, DSPFD, but only in the types of information that I can display or print, not in those that create an outfile.

I might have used an API, QUSLOBJ with format type OBJD0500 or QUSROBJD format OBJD0400, if I only wanted to know about one file, but I want a "list" of files.