fhg
Volume 7, Number 41 -- November 28, 2007

Admin Alert: Basic Tools for the System i Admin Tool Chest

Published: November 28, 2007

by Joe Hertvik

Like it or not, iSeries, i5, and System i administrators usually have to write small Control Language (CL) programs to help them manage their systems. To make this task easier, I frequently use several common programming and IBM-sponsored techniques to perform different functions. This week, I'll look at three basic programming and administrative tools for CL programming and demonstrate how they can benefit you when creating operational programs.

Tool #1: Sending Status Messages When a User is Running a Program

When you're writing long-running code that has to be run interactively, it helps to flash status messages at the bottom of the screen to let the user know what's happening and to reassure him that the program is indeed running. I frequently use the Send Program Message (SNDPGMMSG) command for this task. SNDPGMMSG displays a text message of your choosing on line 24 of the display session where the program is running.

If I want to send a status message during an interactive program run, for example, I would execute the following SNDPGMMSG command at the appropriate place in my CL code.

SNDPGMMSG  MSGID(CPF9898) MSGF(QCPFMSG) MSGDTA('Message text')

By running SNDPGMMSG, whatever text is listed in the Message Data parameter (MSGDTA) will be printed at the bottom of the screen. For this tip, it's important to code this command so that it always sends a program message with a Message Identifier (MSGID) parameter of CPF9898 from the QCPFMSG message file, as designated in the Message File (MSGF) parameter. CPF9898 is the escape message identifier that i5/OS uses to send messages to a display terminal instead of to a named message queue. The text of the message must always be entered in the Message Data (MSG) parameter. If you don't want to hard-code your message text but prefer instead to display the contents of a character-based CL variable in the program, you would instead code your SNDPGMMSG command like this.

SNDPGMMSG  MSGID(CPF9898) MSGF(QCPFMSG) MSGDTA(&MESSAGE)

In this case, whatever value is present in the variable listed in the MSGDTA parameter will appear as a message on line 24 of your user's display session.

In addition to using message ID CPF9898 to send a message, you can also code your SNDPGMMSG command to use message ID CPF9897, like this.

SNDPGMMSG  MSGID(CPF9897) MSGF(QCPFMSG) MSGDTA('Message text')

This command will run exactly the same way as the CPF9898 version of the command runs, with one trivial exception. When you send message CPF9898, i5/OS appends a period character ('. ') to the end of each displayed message. Sending a message by using CPF9897 displays the message at the bottom of the screen without appending a period to the end of the delivered text.

Step #2: Using IBM APIs Instead of Growing Your Own Code

One of the problems with system administrators is that we sometimes start coding homegrown CL code when IBM has already created a perfectly good alternative in the form of a callable System Application Program Interface (System API) program. IBM offers many System APIs for all kinds of common or obscure scenarios, including APIs for the following categories.

  • Backup and recovery
  • Configuration
  • Date and time
  • Message handling
  • Security

There's a ton of APIs out there, and the biggest problem is figuring out whether there's an API that does what you want it to do. Luckily, IBM has made the job of finding APIs easier by providing an API finder in the i5/OS Information Center. To perform an API search, go to the i5/OS Information Center for the release that you're currently running, and type in "API Finder" in the site's search function. The search results window will display a link that takes you to that version's API finder, where you can search for APIs by category, by descriptive name, by program name, or by entering only part of the name. So you can save some time when coding by checking the API finder to see if IBM already offers an API that runs the functionality that you would otherwise have to program yourself.

Step #3: Using the Local Data Area for Cross-Program Communication

When calling one program from within another program, the called program may sometimes need to send information back to the calling program. This is where the Local Data Area (*LDA) comes in handy. For each running job, the system creates a localized 1,024-character data area that can be used for any one of the following purposes.

  • Passing information to a program or procedure without using a parameter list
  • Passing information to a submitted job without coding it as a parameter
  • Storing temporary information for a program without having to create a permanent data area

Similar to a job's QTEMP library, each job's local data area is unique to that job and it cannot be accessed by another process running inside i5/OS. Inside an individual job, the local data area is always referred to as the *LDA, and it can be written to or referenced from any CL or RPG program. To write to the *LDA in a job step, you could use the Change Data Area (CHGDTAARA) command like this:

CHGDTAARA  DTAARA(*LDA (xxxx yyyy)) VALUE('text') 

In this example, xxxx is a one- to four-digit number between 1 and 1024 representing the starting position that you want to write the information to in the *LDA. yyyy is another one- to four-digit number that represent the length of the substring that you are writing out to the *LDA. So if I wanted to write the literal 'Admin Alert' to positions 1-80 of my job's LDA, I would execute the following CHGDTAARA command.

CHGDTAARA  DTAARA(*LDA (1 80)) VALUE('Admin Alert')

If the literal is shorter than the LDA location that you are writing it to, the CHGDTAARA command will left-justify the literal in that location and then pad out the rest of the location with blanks.

Once the information is written to the job's *LDA, any program or procedure called in that same job can retrieve information from that *LDA into a program variable. In a CL program (which is what most administrators use to write special function code), you can use the Retrieve Data Area (RTVDTAARA) command to retrieve the contents of an *LDA substring and copy those contents to a CL program variable. A sample RTVDTAARA statement to retrieve *LDA information might look like the following.

RTVDTAARA  DTAARA(*LDA (xxxx yyyy)) RTNVAR(&VARIABLE)

Like the CHGDTAARA command, the xxxx and yyyy values are four-digit numbers designating the starting position and the length of the *LDA substring to retrieve. The CL variable for the Returned Value (RTNVAR) parameter designates the program variable that will contain the retrieved substring after the command is run. Following our example, if I want to retrieve positions 1-80 of my *LDA into a CL variable called &LDADTA, I would code that command this way.

RTVDTAARA  DTAARA(*LDA (1 80)) RTNVAR(&LDADTA)

While CHGDTAARA and RTVDTAARA are fairly easy to use to pass data between programs or procedures within a job stream, you can also use the *LDA to pass information from a source job to any batch job that the source job submits by using the Submit Job (SBMJOB) command. This is because, by default, SBMJOB copies the contents of the submitting job's *LDA into its own *LDA as the job is submitted. As a result, you can easily pass *LDA information from a submitting job to a submitted job by performing the following two steps:

  1. Use the Change Data Area (CHGDTAARA) command in the submitting job to place the information into the *LDA.
  2. Use the Retrieve Data Area (RTVDTAARA) command in the submitted job to retrieve that same information from the job's copy of the submitting job's *LDA.

The moral here is that the *LDA is a great way to pass information anywhere within an individual job or between an individual job and any other jobs that it submits.

About Our Testing Environment

Configurations described in this article were tested on an i5 550 box running i5/OS V5R3. Most of the commands shown here are also available in earlier versions of the operating system running on System i, iSeries or AS/400 machines. If a command or function is present in earlier versions of the i5/OS or OS/400 operating systems, you may notice some variations in the pre-V5R3 copies of these commands. These differences may be due to command improvements that have occurred from release to release.


RELATED RESOURCES

i5/OS Information Center, IBM



                     Post this story to del.icio.us
               Post this story to Digg
    Post this story to Slashdot


Sponsored By
GUILD COMPANIES

New Book: The System i RPG & RPG IV
Tutorial and Lab Exercises

 

This affordable self-study package by Brian Kelly was originally as a lab guide. The book comes packaged with a 1-2-3-type tutorial, lab exercises, and PowerPoint presentations with notes on the slides that make for handy reference material immediately available on your workstation.

 

You won't want to put down this comprehensive guide to learning System i RPG/RPG IV.

 

Price: $59.95
Get Your Copy at the IT Jungle bookstore today!


Senior Technical Editor: Ted Holt
Technical Editors: Howard Arner, Joe Hertvik, Shannon O'Donnell, Kevin Vandever
Contributing Technical Editors: Joel Cochran, Wayne O. Evans, Raymond Everhart,
Bruce Guetzkow, Brian Kelly, Marc Logemann, David Morris
Publisher and Advertising Director: Jenny Thomas
Advertising Sales Representative: Kim Reed
Contact the Editors: To contact anyone on the IT Jungle Team
Go to our contacts page and send us a message.

Sponsored Links

RJS Software Systems:  Make your office paperless with WebDocs
COMMON:  Join us at the annual 2008 conference, March 30 - April 3, in Nashville, Tennessee
LANSA:  Hear how System i shops achieved modernization with RAMP


 

IT Jungle Store Top Book Picks

The System i RPG & RPG IV Tutorial and Lab Exercises: List Price, $59.95
The System i Pocket RPG & RPG IV Guide: List Price, $69.95
The iSeries Pocket Database Guide: List Price, $59.00
The iSeries Pocket Developers' Guide: List Price, $59.00
The iSeries Pocket SQL Guide: List Price, $59.00
The iSeries Pocket Query Guide: List Price, $49.00
The iSeries Pocket WebFacing Primer: List Price, $39.00
Migrating to WebSphere Express for iSeries: List Price, $49.00
iSeries Express Web Implementer's Guide: List Price, $59.00
Getting Started with WebSphere Development Studio for iSeries: List Price, $79.95
Getting Started With WebSphere Development Studio Client for iSeries: List Price, $89.00
Getting Started with WebSphere Express for iSeries: List Price, $49.00
WebFacing Application Design and Development Guide: List Price, $55.00
Can the AS/400 Survive IBM?: List Price, $49.00
The All-Everything Machine: List Price, $29.95
Chip Wars: List Price, $29.95


 
The Four Hundred
Redefining Security the New Goal of Former i5/OS Security Architect

The System i Fourth Quarter Sales Strategy

Power Systems Division Eyes Cognos Deal; Business Systems Shrugs

As I See It: The Sick Guys in Your Wallet

The Linux Beacon
Blade Servers Make It to the Top HPC Sites

Red Hat and Platform Computing Partner for Supercomputing

HP Closes Out Fiscal 2007 with a Strong Finish

Be My Guest

Four Hundred Stuff
NetManage Fixes Printing, Performance Issues in Web-Based Emulation

Verastream Streamlines Host Access for Hospital Billing Specialist

Help/Systems Extends Robot to Linux Servers

VAI Gives Retailers a Windows Option for Backup

Big Iron
IBM Previews z/VSE V4.2, Releases DB2 Server V7.5

Top Mainframe Stories From Around the Web

Chats, Webinars, Seminars, Shows, and Other Happenings

System i PTF Guide
November 24, 2007: Volume 9, Number 46

November 17, 2007: Volume 9, Number 45

November 10, 2007: Volume 9, Number 45

November 3, 2007: Volume 9, Number 44

October 27, 2007: Volume 9, Number 43

October 20, 2007: Volume 9, Number 42

The Windows Observer
Windows Server 2008 Pricing and Packaging Set by Microsoft

'Viridian' Hypervisor Gains Formal Name: Hyper-V

Intel Announces First "Penryn" Xeon Processors

Microsoft Makes Gains in HPC Market

The Unix Guardian
Solaris Conversion Rate: Sun Sheds Some Light

Blade Servers Make It to the Top HPC Sites

Intel Announces First "Penryn" Xeon Processors

The Blue Cloud Is IBM's Commercial Cloud Computing

Four Hundred Monitor
Four Hundred Monitor's
Full iSeries Events Calendar

THIS ISSUE SPONSORED BY:

ProData Computer Services
Help/Systems
Guild Companies


Printer Friendly Version


TABLE OF CONTENTS
System i Developers and .NET 2.0, Part 2: Web Development Using ASP.NET AJAX

ON vs. ON

Admin Alert: Basic Tools for the System i Admin Tool Chest

Four Hundred Guru

BACK ISSUES

From the IT Jungle Forums
Choose Logical File Format with SQL

IBM 6400 on LPT1 prints junk

Reallocate disk space from one LPAR to another

How to retrieve a workstation ID

Finding *OUTFILE Template Files





 
Subscription Information:
You can unsubscribe, change your email address, or sign up for any of IT Jungle's free e-newsletters through our Web site at http://www.itjungle.com/sub/subscribe.html.

Copyright © 1996-2008 Guild Companies, Inc. All Rights Reserved.
Guild Companies, Inc., 50 Park Terrace East, Suite 8F, New York, NY 10034

Privacy Statement