29
Fri, Nov
0 New Articles

Enhance i5/OS with IBM's Blessing!

CL
Typography
  • Smaller Small Medium Big Bigger
  • Default Helvetica Segoe Georgia Times

Others will think you work for IBM.

 

A System i developer recently informed me that after several years of programming, he is finally learning to create commands. I am amazed that many developers have worked many years with the System i and its predecessors, yet have never created a command, but it seems to be very common.

 

This developer mentioned two areas that have given him trouble, and I was able to help him. First, he wanted to understand how to qualify an object. Second, he wanted to add help text to his command. I have seen this guy's code, and I know that he is very capable. I have no doubt that the commands he produces will be indistinguishable from those IBM ships with i5/OS. Here's the information I gave him. I hope it will be of benefit to many others.

Faux Pas # 1: Using Separate Parameters Rather Than Qualification

It is easier to use separate parameters for object and name than to qualify an object, but the easy way is not always the best way. A few IBM commands use separate parameters for object name and library name. Two examples are Create Duplicate Object (CRTDUPOBJ) and Save Object (SAVOBJ). However, most IBM commands use qualification to combine object name and library name into one parameter. Your commands will look more "IBM-ish" if you use qualification to combine related values, rather than use separate parameters for each related value.

 

See for yourself. Let's consider a command that requires the name of a file and the library in which that file is located. First, here's the command with two parameters.

 

051408Holtbad-command-prompt.jpg

Figure 1: This is a bad example.  (Click images to enlarge.)

 

Take a look at the same command with a qualified file name.

 

051408Holtgood-command-prompt.jpg

Figure 2: This is a good example.

 

The process of qualifying is not difficult. The three most common qualification scenarios are qualified object, job name, and file name with member. Let's look at each one in turn. I will show you how to code the qualification in command source code and how to process the qualified value in a CL procedure.

 

Scenario 1: Qualified Object (Object/Library)

When you define a command parameter to represent an object that resides in the library file system, you will probably need to include a way for the user to tell which library holds the object. To define a qualified object, you'll need two QUAL commands for object and library. The first QUAL must have a label to name the qualification data type. Here is source for a command I'll call DOIT (Do It).

 

     CMD   PROMPT('Do It')

     PARM  KWD(FILE) TYPE(Q1) PROMPT('Database file')

Q1:  QUAL  TYPE(*NAME) MIN(1) EXPR(*YES)           

     QUAL  TYPE(*NAME) DFT(*LIBL) SPCVAL((*LIBL)) +

              EXPR(*YES) PROMPT('Library')          

 

This command includes a parameter of data type Q1 for a file. But what is type Q1? Since Q1 is not one of the predefined data types, the command compiler looks for a QUAL command labeled Q1. The compiler takes the labeled QUAL and any unlabeled QUAL commands that immediately follow. In this case, two QUAL commands make up the Q1 data type. The first QUAL is for the file name, and the second QUAL command is for the library name.

 

 

Notice the locations of the PROMPT parameters. I've included a PROMPT string on the PARM command to indicate the purpose of the parameter. Of the two QUAL commands, however, only the last QUAL, which defines the library, needs a PROMPT. I use this method because it makes my qualified parameters look just like those of the IBM-defined commands.

 

The user can enter the command parameter in two ways: object name only, and library followed by a slash followed by the object name.

 

DOIT   FILE(SOMEFILE)

DOIT   FILE(SOMELIB/SOMEFILE)

 

The command processing program (CPP) receives one parameter that contains the two values with no separation. In this example, both QUAL commands are defined to be of type *NAME, which i5/OS automatically defines as 10 bytes. Therefore, the CPP receives one 20-byte variable, with the file name in the first 10 bytes and the library name in the last 10 bytes. Here's a fragment of a CL program to process the command source given above.

 

PGM        PARM(&QUALFILE)                             

DCL        VAR(&QUALFILE) TYPE(*CHAR) LEN(20)          

                                                       

CHKOBJ     OBJ(%SST(&QUALFILE 11 10)/%SST(&QUALFILE 1 10)) +

             OBJTYPE(*FILE) AUT(*OBJEXIST)         

MONMSG     MSGID(CPF9800) EXEC(DO)                     

/* the file does not exist; do whatever */             

ENDDO                                                  

 

The CL procedure receives the 20-byte qualified object name as &QUALFILE. Bytes 1 through 10 are the file name. Bytes 11 through 20 are the library name. In this example, I've used the substring function, %SST, to refer to the file and library name in the Check Object (CHKOBJ) command.

 

I almost always prefer to extract the individual parts of a qualified value into variables of their own. The following example is equivalent in function to the previous one. It differs in that the &QUALFILE variable is divided into the &FILE and &LIB variables.

 

PGM        PARM(&QUALFILE)                              

DCL        VAR(&QUALFILE) TYPE(*CHAR) LEN(20)          

DCL        VAR(&FILE) TYPE(*CHAR) LEN(10)              

DCL        VAR(&LIB) TYPE(*CHAR) LEN(10)               

                                                       

CHGVAR     VAR(&FILE) VALUE(%SST(&QUALFILE 1 10))      

CHGVAR     VAR(&LIB) VALUE(%SST(&QUALFILE 11 10))      

                                                       

CHKOBJ     OBJ(&LIB/&FILE) OBJTYPE(*FILE) AUT(*OBJEXIST)

MONMSG     MSGID(CPF9800) EXEC(DO)                      

/* the file does not exist; do whatever */             

ENDDO                                                  

Scenario 2: Qualified Job Name (Number/User/Jobname)

Qualification of a job name is similar to qualification of an object. The difference is that there are three values, rather than two, in a qualified job name. Here is the command source code for defining a job name.

 

      CMD   PROMPT('Do It')

      PARM   KWD(JOB) TYPE(JOB) DFT(*) SNGVAL((*)) + 

                PROMPT('Job name')                    

JOB:  QUAL   TYPE(*NAME) LEN(10) MIN(1)              

      QUAL   TYPE(*NAME) LEN(10) MIN(1) PROMPT('User')

      QUAL   TYPE(*CHAR) LEN(6) RANGE(000000 999999) +

                MIN(1) FULL(*YES) PROMPT('Number')                

 

The three QUAL commands that define the JOB data type define job name, user, and job number, respectively. As with qualified objects, the three parts that make up the parameter must be entered in reverse order. That is, the first value represents the last QUAL.

 

DOIT JOB(106798/JSMITH/MYTUBE)

 

The CPP receives the qualified job name as a string of 26 characters. That is, the three parts of the parameter are concatenated to form the single parameter that the CPP receives.

 

Notice also that I have defined a single value to allow an asterisk in the PARM parameter. A single value is a value that can be used instead of the fully qualified value. The CPP is to interpret an asterisk to mean the current job.

 

DOIT JOB(*)

 

When you include single values in qualified parameters, you must make the CPP determine if a single value was passed or a qualified value was passed.

 

In the following program, I use an IF to check for a single asterisk in &QUALJOB. If that condition is true, I retrieve job name, user, and job number from the job attributes. If &QUALJOB is not a single asterisk, it must be a qualified job name, and I extract the three values from the parameter into the job name, user, and job number variables. Regardless of how the three variables are loaded, they serve to tell the Work Job (WRKJOB) command which job to display information about open files in.

 

PGM        PARM(&QUALJOB)                                 

                                                         

DCL        VAR(&QUALJOB) TYPE(*CHAR) LEN(26)             

DCL        VAR(&JOBNAME) TYPE(*CHAR) LEN(10)             

DCL        VAR(&JOBUSER) TYPE(*CHAR) LEN(10)              

DCL        VAR(&JOBNUMBER) TYPE(*CHAR) LEN(6)            

     

/* single value of * means the current job */                                                   

IF         COND(&QUALJOB *EQ '*') THEN(DO)               

RTVJOBA    JOB(&JOBNAME) USER(&JOBUSER) NBR(&JOBNUMBER)  

ENDDO                                       

/* the job name is qualified */            

ELSE       CMD(DO)                                       

CHGVAR     VAR(&JOBNAME) VALUE(%SST(&QUALJOB 1 10))      

CHGVAR     VAR(&JOBUSER) VALUE(%SST(&QUALJOB 11 10))     

CHGVAR     VAR(&JOBNUMBER) VALUE(%SST(&QUALJOB 21 6))    

ENDDO                                                    

                                                         

WRKJOB     JOB(&JOBNUMBER/&JOBUSER/&JOBNAME) OPTION(*OPNF)

Scenario 3: Qualified Database File with Member (Object/Library Member)

 

IBM has two ways to qualify file names when a database member is involved. In some commands, such as Copy File (CPYF) and Override with Database File (OVRDBF), the file is qualified as any other object would be, and the member is specified in a separate parameter.

 

OVRDBF FILE(SOMEFILE) +

          TOFILE(MYLIB/MYFILE) +

          MBR(MYMBR)

 

In other commands, like Copy to Import File (CPYTOIMPF), the member is included as a second element in the qualified parameter.

 

CPYTOIMPF FROMFILE(MYLIB/MYFILE MYMBR) +

             TOSTMF('mydata.dat') 

 

Here is a command in which the file member is included in the qualification.

 

CMD        PROMPT('Do It')

PARM       KWD(FILE) TYPE(DBFILE) MIN(1) +               

             PROMPT('Database file')                     

                                                                      

DBFILE:     ELEM       TYPE(QUALFILE) MIN(1) PROMPT('File')           

            ELEM       TYPE(*NAME) LEN(10) DFT(*FIRST) +             

                          SPCVAL((*FIRST)) EXPR(*YES) PROMPT('Member')

                                                                      

QUALFILE:   QUAL       TYPE(*NAME) LEN(10) MIN(1) EXPR(*YES)         

            QUAL       TYPE(*NAME) LEN(10) DFT(*LIBL) +              

                          SPCVAL((*LIBL) (*CURLIB)) EXPR(*YES) +      

                          PROMPT('Library')                           

 

In this case, the file parameter has two elements: the qualified file and the member. Both make up the DBFILE data type. The first of those two elements is further defined by the QUALFILE data type.

 

The CPP receives the FILE parameter as a 32-byte string. The first two positions always contain the number two, to indicate the number of elements, in binary format. You can ignore them. The information you need begins in position three and spans 30 positions: 10 for file name, 10 for library name, and 10 for member name. Use the substring function to extract that information in a CL procedure.

 

PGM        PARM(&QUALFILE)                      

                                                

DCL        VAR(&QUALFILE) TYPE(*CHAR) LEN(32)   

DCL        VAR(&FILE) TYPE(*CHAR) LEN(10)       

DCL        VAR(&LIB) TYPE(*CHAR) LEN(10)        

DCL        VAR(&MBR) TYPE(*CHAR) LEN(10)        

                                                

CHGVAR     VAR(&FILE) VALUE(%SST(&QUALFILE 3 10))

CHGVAR     VAR(&LIB) VALUE(%SST(&QUALFILE 13 10))

CHGVAR     VAR(&MBR) VALUE(%SST(&QUALFILE 23 10))

Faux Pas # 2: No Command Help

I've given you the skeleton source code you need to define qualified parameters as IBM does. This will go a long way toward making your commands look and act like those of IBM's. There is one other thing that you need to do: You need to provide some help text. Absence of help text is a dead giveaway that your command did not come from IBM. Fortunately, defining help text is easy if you are running V5R3 or above.

 

In V5R3, IBM added the Generate Command Documentation (GENCMDDOC) command to i5/OS. This wonderful command relieves the developer of the grunt work in developing HTML and UIM (help text) documentation. It's a little goofy in the way it works, in that it doesn't return error messages to a green-screen session. You have to look at the job log to see if the command succeeds or not. Another quirk is that it may not be finished when the input-inhibited light goes away, because the command kicks off a Java application that runs in its own little world. But the good outweighs the bad.

 

To generate help text for the DOIT command, I ran the GENCMDDOC command from an interactive session.

 

GENCMDDOC CMD(MYLIB/DOIT)                   

   TODIR('/qsys.lib/mylib.lib/qpnlsrc.file')

   TOSTMF(doit.mbr)                  

   GENOPT(*UIM)                         

 

In return, I got a source member called DOIT[THH1]  in file QPLNSRC of library MYLIB. If you prefer, you can generate the source in the IFS. The following command creates the UIM source code in stream file /home/mydir/MYLIB_DOIT.UIM.

 

GENCMDDOC CMD(MYLIB/DOIT)    

          TODIR('/home/mydir')

          TOSTMF(*CMD)       

          GENOPT(*UIM)       

 

Wherever you put the source, you'll need to edit it. Open the source member using your editor of choice and start looking for three periods inside angle brackets, like this:

 

You must have <...>

 

These placeholders indicate where you need to fill in the blanks. Either replace the placeholders or delete the sentences or sections in which they are found. The following example shows how you might replace a placeholder with meaningful text.

 

You must have security administrator authority to run this command.

 

Once you've replaced the placeholders with meaningful text, create the panel group.

 

CRTPNLGRP PNLGRP(MYLIB/DOIT)

   SRCFILE(MYLIB/QPNLSRC)   

   SRCMBR(DOIT)       

   REPLACE(*YES)         

 

Attach the panel group to the command, either by creating the command or changing the command.

 

CRTCMD CMD(MYLIB/DOIT)       

   PGM(*LIBL/DOITPGM)     

   SRCFILE(MYLIB/QCMDSRC)      

   SRCMBR(DOIT)           

   HLPPNLGRP(MYLIB/DOIT)

   HLPID(*CMD)              

   REPLACE(*YES)             

 

CHGCMD CMD(MYLIB/DOIT)

   HLPPNLGRP(MYLIB/DOIT)

   HLPID(*CMD)

 

They'll Think You Work for IBM

One of the highest compliments I've ever been paid occurred on those occasions when someone thought a CL command that I'd written was part of the operating system. It's not that I'm a super programmer, but rather that I follow (as far as is practical) the standards IBM developers have set.

 

Learning to qualify objects and define help text is not difficult. Whether you're an old-timer or a newbie, if you've never learned to define your own commands, now is a great time to start.

TED HOLT

Ted Holt is IT manager of Manufacturing Systems Development for Day-Brite Capri Omega, a manufacturer of lighting fixtures in Tupelo, Mississippi. He has worked in the information processing industry since 1981 and is the author or co-author of seven books. 


MC Press books written by Ted Holt available now on the MC Press Bookstore.

Complete CL: Fifth Edition Complete CL: Fifth Edition
Become a CL guru and fully leverage the abilities of your system.
List Price $79.95

Now On Sale

Complete CL: Sixth Edition Complete CL: Sixth Edition
Now fully updated! Get the master guide to Control Language programming.
List Price $79.95

Now On Sale

IBM i5/iSeries Primer IBM i5/iSeries Primer
Check out the ultimate resource and “must-have” guide for every professional working with the i5/iSeries.
List Price $99.95

Now On Sale

Qshell for iSeries Qshell for iSeries
Check out this Unix-style shell and utilities command interface for OS/400.
List Price $79.95

Now On Sale

BLOG COMMENTS POWERED BY DISQUS

LATEST COMMENTS

Support MC Press Online

$

Book Reviews

Resource Center

  • SB Profound WC 5536 Have you been wondering about Node.js? Our free Node.js Webinar Series takes you from total beginner to creating a fully-functional IBM i Node.js business application. You can find Part 1 here. In Part 2 of our free Node.js Webinar Series, Brian May teaches you the different tooling options available for writing code, debugging, and using Git for version control. Brian will briefly discuss the different tools available, and demonstrate his preferred setup for Node development on IBM i or any platform. Attend this webinar to learn:

  • SB Profound WP 5539More than ever, there is a demand for IT to deliver innovation. Your IBM i has been an essential part of your business operations for years. However, your organization may struggle to maintain the current system and implement new projects. The thousands of customers we've worked with and surveyed state that expectations regarding the digital footprint and vision of the company are not aligned with the current IT environment.

  • SB HelpSystems ROBOT Generic IBM announced the E1080 servers using the latest Power10 processor in September 2021. The most powerful processor from IBM to date, Power10 is designed to handle the demands of doing business in today’s high-tech atmosphere, including running cloud applications, supporting big data, and managing AI workloads. But what does Power10 mean for your data center? In this recorded webinar, IBMers Dan Sundt and Dylan Boday join IBM Power Champion Tom Huntington for a discussion on why Power10 technology is the right strategic investment if you run IBM i, AIX, or Linux. In this action-packed hour, Tom will share trends from the IBM i and AIX user communities while Dan and Dylan dive into the tech specs for key hardware, including:

  • Magic MarkTRY the one package that solves all your document design and printing challenges on all your platforms. Produce bar code labels, electronic forms, ad hoc reports, and RFID tags – without programming! MarkMagic is the only document design and print solution that combines report writing, WYSIWYG label and forms design, and conditional printing in one integrated product. Make sure your data survives when catastrophe hits. Request your trial now!  Request Now.

  • SB HelpSystems ROBOT GenericForms of ransomware has been around for over 30 years, and with more and more organizations suffering attacks each year, it continues to endure. What has made ransomware such a durable threat and what is the best way to combat it? In order to prevent ransomware, organizations must first understand how it works.

  • SB HelpSystems ROBOT GenericIT security is a top priority for businesses around the world, but most IBM i pros don’t know where to begin—and most cybersecurity experts don’t know IBM i. In this session, Robin Tatam explores the business impact of lax IBM i security, the top vulnerabilities putting IBM i at risk, and the steps you can take to protect your organization. If you’re looking to avoid unexpected downtime or corrupted data, you don’t want to miss this session.

  • SB HelpSystems ROBOT GenericCan you trust all of your users all of the time? A typical end user receives 16 malicious emails each month, but only 17 percent of these phishing campaigns are reported to IT. Once an attack is underway, most organizations won’t discover the breach until six months later. A staggering amount of damage can occur in that time. Despite these risks, 93 percent of organizations are leaving their IBM i systems vulnerable to cybercrime. In this on-demand webinar, IBM i security experts Robin Tatam and Sandi Moore will reveal:

  • FORTRA Disaster protection is vital to every business. Yet, it often consists of patched together procedures that are prone to error. From automatic backups to data encryption to media management, Robot automates the routine (yet often complex) tasks of iSeries backup and recovery, saving you time and money and making the process safer and more reliable. Automate your backups with the Robot Backup and Recovery Solution. Key features include:

  • FORTRAManaging messages on your IBM i can be more than a full-time job if you have to do it manually. Messages need a response and resources must be monitored—often over multiple systems and across platforms. How can you be sure you won’t miss important system events? Automate your message center with the Robot Message Management Solution. Key features include:

  • FORTRAThe thought of printing, distributing, and storing iSeries reports manually may reduce you to tears. Paper and labor costs associated with report generation can spiral out of control. Mountains of paper threaten to swamp your files. Robot automates report bursting, distribution, bundling, and archiving, and offers secure, selective online report viewing. Manage your reports with the Robot Report Management Solution. Key features include:

  • FORTRAFor over 30 years, Robot has been a leader in systems management for IBM i. With batch job creation and scheduling at its core, the Robot Job Scheduling Solution reduces the opportunity for human error and helps you maintain service levels, automating even the biggest, most complex runbooks. Manage your job schedule with the Robot Job Scheduling Solution. Key features include:

  • LANSA Business users want new applications now. Market and regulatory pressures require faster application updates and delivery into production. Your IBM i developers may be approaching retirement, and you see no sure way to fill their positions with experienced developers. In addition, you may be caught between maintaining your existing applications and the uncertainty of moving to something new.

  • LANSAWhen it comes to creating your business applications, there are hundreds of coding platforms and programming languages to choose from. These options range from very complex traditional programming languages to Low-Code platforms where sometimes no traditional coding experience is needed. Download our whitepaper, The Power of Writing Code in a Low-Code Solution, and:

  • LANSASupply Chain is becoming increasingly complex and unpredictable. From raw materials for manufacturing to food supply chains, the journey from source to production to delivery to consumers is marred with inefficiencies, manual processes, shortages, recalls, counterfeits, and scandals. In this webinar, we discuss how:

  • The MC Resource Centers bring you the widest selection of white papers, trial software, and on-demand webcasts for you to choose from. >> Review the list of White Papers, Trial Software or On-Demand Webcast at the MC Press Resource Center. >> Add the items to yru Cart and complet he checkout process and submit

  • Profound Logic Have you been wondering about Node.js? Our free Node.js Webinar Series takes you from total beginner to creating a fully-functional IBM i Node.js business application.

  • SB Profound WC 5536Join us for this hour-long webcast that will explore:

  • Fortra IT managers hoping to find new IBM i talent are discovering that the pool of experienced RPG programmers and operators or administrators with intimate knowledge of the operating system and the applications that run on it is small. This begs the question: How will you manage the platform that supports such a big part of your business? This guide offers strategies and software suggestions to help you plan IT staffing and resources and smooth the transition after your AS/400 talent retires. Read on to learn: