Wednesday, July 31, 2013

Subroutines in CL

IBM has been adding commands to CL that have been operations in other languages for many years. IBM i V5R4 saw the introduction of the Subroutine group of commands. There are five commands in this group, but I only use four:

  • SUBR - marks the start of the subroutine.
  • ENDSUBR - marks the end of the subroutine.
  • RTNSUBR - Return from subroutine.
  • CALLSUBR - calls the subroutine given.

I am not going to describe what a subroutine is, as I am assuming that all the readers of this blog have at least a basic knowledge of programming principals.

Friday, July 26, 2013

Query Engines: CQE versus SQE

I received an interesting message regarding the Passing parms to a Query post that I consider worth sharing.

Before I share the message I need to explain that there are two query engines on the IBM i (AS400): the Classic Query Engine (CQE) and the SQL Query Engine Engine (SQE). What runs through each engine is shown below:

Wednesday, July 24, 2013

Passing parms to a Query

Query/400 has always provides a quick and easy way to generate a report or create an output file. I have found that once they are built they never go away, as a programmer never has time, with all the demands on their time, to replace it with a RPG program.

If a Query joins several large files it can become a resource hog, taking away CPU power from normal daily interactive processing. The solution has always been to run Queries in batch.

Most people find that if they need to change the Query’s run parameters they use the Record Select parameter, RCDSLT(*YES), in the Run Query command, RUNQRY.

  RUNQRY QRY(QUERY_NAME) RCDSLT(*YES)

Of course this cannot be run in batch. Therefore, this Query, with its large joins, runs interactively, and the other users complain that the system is running slow.

But there is another way using the Start Query Management Query, STRQMQRY, command.

Thursday, July 18, 2013

When divine help is needed

Saint Isidore of Seville

We have all had those times when what you thought was a quick fix has turned out not to be, you have managed to corrupt a database, the quick software upgrade is entering its 24th hour, the back up of your file cannot be restored, or some other disaster. In those late dark hours don't you feel that you might be in need of some divine help.

You are in luck! In 1997 Pope John Paul II decided that computers, computer users, computer programmers, students studying computers, and the internet in general needed a patron saint to guide Catholics. He chose Saint Isidore of Seville (circa 560- April 4, 636), known in Spanish as San Isidoro de Sevilla, who served as Archbishop of Seville for 30 years and is regarded by many as the "last scholar of the ancient world".

Tuesday, July 16, 2013

Adding to the System Directory

I find that having my user profile in the IBM i (AS400) system directory is useful so that I can perform the following:

  • Send network files.
  • Use the QDLS file system on the IBM i (AS400)

I will not discuss either of them in this post as each deserves a post in their own right.

To add user profiles to the System Directory you need to have Security Administrator (*SECADM). To see whether you have that level of security use the Display User Profile (DSPUSRPRF) command. On a command line type: DSPUSRPRF your-user-profile and press Enter.

On the second screen is the ‘Special authority’ section, this lists the types of authority you have. This user has *SECADM authority.

                          Display User Profile - Basic

 User profile . . . . . . . . . . . . . . . :   SECUSR 
 User expiration interval . . . . . . . . . :   *NONE 
 User expiration action . . . . . . . . . . :   *NONE 
 Special authority  . . . . . . . . . . . . :   *ALLOBJ 
                                                *AUDIT 
                                                *IOSYSCFG 
                                                *JOBCTL 
                                                *SAVSYS 
                                                *SECADM
                                                *SERVICE 
                                                *SPLCTL 
 Group profile  . . . . . . . . . . . . . . :   QSECOFR

If your profile does not have *SECADM authority you will need to see your IBM i (AS400) System Administrator and have them add you to the System Directory.

Wednesday, July 10, 2013

Useful keywords for your F-specs

Update: The post linked here is updated to use totally free RPG definitions.


I was working within earshot of a colleague who had to recompile several programs he had built, over six months ago, that an user finally wanted to test. The objects had been deleted as part of a software refresh of our development IBM i (AS400), therefore, he would have to compile all of the program objects. He was going through all of the programs’ source code and recreating the work files he needed for the compiles, while grumbling that there must be an easier way to do this. That is when I offered to show him something that would make it easier in the future.

There are several File specification, F-specs, keywords that I use especially with “work” files:

  • EXTFILE
  • EXTDESC
  • EXTMBR
  • RENAME

Thursday, July 4, 2013

SELECT in CL

IBM i (OS400) V5R3 brought what I like to call the Select group of commands, SELECT, WHEN, OTHERWISE, and ENDSELECT. If you are familiar with the Select operation codes in RPG/RPGLE you need little or no introduction to their equivalent in CL. Their introduction has allowed me to write, what I consider to be, better looking and structured code.

Before the Select group of commands I would write some ugly thing like this:

01         IF         COND(&FLAG = 'A') THEN(DO)
02               CHGVAR VAR(&STS) VALUE('ACTIVE')
03               GOTO CMDLBL(ENDTEST)
04         ENDDO
05         IF         COND(&FLAG = 'I') THEN(DO)
06               CHGVAR VAR(&STS) VALUE('INACTIVE')
07               GOTO CMDLBL(ENDTEST)
08         ENDDO
09         CHGVAR     VAR(&STS) VALUE('ERROR')
10         CHGVAR     VAR(&ERROR) VALUE('1')
11  ENDTEST:

Line 1 tests if the field &FLAG is ‘A’, if it is then line 2 is executed, and line 3 goes to the label ENDTEST. I have the GOTO as if &FLAG was equal to ‘A’ it does need to execute any of the code before the ENDTEST label. If I did not have the GOTO it would execute the IF at line 5, and I would have had to put another IF statement between lines 8 and 9 too.

Lines 9 and 10 are only executed if &FLAG is not equal or ‘A’ or ‘I’.

Messy? Yes.

Tuesday, July 2, 2013

FOR replaces DO in RPGLE

In the post CL does DO I said that the DOFOR was similar to the FOR operation code in RPGLE. I use the FOR operation in RPGLE, but having looked at the code created by my colleagues I appear to the only one who does. The FOR operation allows us to "loop", perform the same section of code a specified number of times.

When programming in fixed format RPGLE if I needed to perform a section of code ten times many of us would code:

01 C     1             do        10
02
03 C                   enddo

Why do I do that?   I always code RPGLE in lower case.

In RPG/free it comes more complicated as the DO operation not supported. Therefore, I would need to do something like this:

01       Count = 1 ;
02
03       dou (Count = 10) ;
04
05          Count += 1 ;  // Increment Count by 1
06       enddo ;

IBM introduced the FOR operation, to replace the DO, in IBM i (OS400) V5R3.