************ Club Tech iSeries Programming Tips Newsletter ***********
An iSeries Network Publication http://www.iseriesnetwork.com
Home of iSeries NEWS Magazine Editor: Scott Klement
Issue 197 February 24, 2005
Thanks to this issue's sponsors -- SEQUEL and BCD
SPONSORED IN PART BY SEQUEL
TOP TEN REASONS
Why You Should RETIRE QUERY/400
SEQUEL is the BETTER way! Check out the Top Ten list and a video
Demo that shows how SEQUEL automatically converts QUERY objects
into SEQUEL views and reports. Ask for a FREE TRIAL today!
http://www.asc-iseries.com/isn41118.htm
THIS WEEK:
APIs by Example: Retrieve System Information
STRDBG Can Be GUI!
Pro and Pro VIP Edition Items:
Hibernate -- Easing Table Access in Java
Right Justifying a Character Field
1. APIs BY EXAMPLE: RETRIEVE SYSTEM INFORMATION
In this installment of APIs by Example, I will demonstrate some of the APIs
that are available to access different types of system information.
Regular APIs, as well as various MI built-in functions, offer a lot of
information in this area. In the API manual, many of the APIs related to
system information are found in the 'Work Management
APIs' category. You can view the APIs in this category at the following link:
http://as400bks.rochester.ibm.com/iseries/v5r2/ic2924/info/apis/wm1.htm
In the following API example, I have also included a couple of Software
Product APIs, which have their own category. You can read about those APIs
by clicking this link:
http://as400bks.rochester.ibm.com/iseries/v5r2/ic2924/info/apis/sw1.htm
Finally, the MI built-in functions also provide a wealth of system information.
Many of the 'Materialize' built-ins in general, and the Materialize Machine
Attributes in particular, are a source of system information otherwise not
programmatically available. All built-ins as of release V5R1 are documented here:
http://publib.boulder.ibm.com/iseries/v5r1/ic2924/tstudio/tech_ref/mi/in...
The so-called built-ins are, in reality, interfaces to corresponding MI functions.
They make MI functions available to all ILE languages. The ILE C/C++ languages
also have their own version of these MI function interfaces, documented in the
'ILE C/C++ MI Library Reference', which is available here:
http://as400bks.rochester.ibm.com/iseries/v5r2/ic2924/books/c0924180.pdf
It is not necessary to reference any service program or binding directory during
compilation to make the built-ins available to the compiler. All of the ILE compilers
have implicit access to the MI built-ins. In fact, the compiler will often replace an
MI built-in reference with an in-line call to the actual MI function to avoid the
overhead connected to an external call.
To hide most of the complexity that's involved in calling the APIs and built-ins
and make the information they provide easily accessible to other programs, I
have created a service program containing procedures that act as wrappers
around the APIs and built-ins. The following procedures are included in the
service program:
GetSysStt() -- Get system state
Returns '1' if the system is currently in
Restricted state and '0' if not.
GetSysVal() -- Get system value
Returns the specified system value.
GetNetAtr() -- Get network attribute
Returns the specified network attribute.
GetRlsLvl() -- Get system release level
Returns the system's current release level.
GetIplDts() -- Get IPL timestamp
Returns the timestamp of the last IPL performed.
GetCumLvl() -- Get cumulative PTF package level
Returns the package ID of the most recent
cumulative PTF package that was applied.
GetPrcGrp() -- Get processor group
Returns the system's processor group.
GetPrcTyp() -- Get processor type
Returns the system's processor type.
GetKeyPos() -- Get panel key position
Returns the current key lock position on the panel.
GetIplTyp() -- Get current IPL type
Returns the current IPL type set on the panel.
To easily let you test the above procedures, I have also included a sample
program that presents some of the system information retrieved by the
procedures in a display window:
= = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
.................................................................
: :
: Last system IPL date and time: 2005-02-16-06.03.25.000000 :
: :
: :
: :
: :
: :
: Bottom :
: F12=Cancel :
: :
:...............................................................:
= = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
Press enter to continue the system information retrieval and presentation.
The sample program eventually prompts you to specify a system value of
your choice and then displays the retrieved system value in the display
window:
= = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
Display Program Messages
Please enter a system value to retrieve:
Type reply, press Enter.
Reply . . . QSECURITY
= = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
.................................................................
: :
: System value 'QSECURITY': 30 :
: :
: :
: :
: :
: :
: Bottom :
: F12=Cancel :
: :
:...............................................................:
= = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
This article demonstrates the following APIs:
Retrieve System Value (QWCRSVAL) API:
http://as400bks.rochester.ibm.com/iseries/v5r2/ic2924/info/apis/qwcrsval...
Retrieve System Status (QWCRSSTS) API:
http://as400bks.rochester.ibm.com/iseries/v5r2/ic2924/info/apis/qwcrssts...
Retrieve Network Attribute (QWCRNETA) API:
http://as400bks.rochester.ibm.com/iseries/v5r2/ic2924/info/apis/qwcrneta...
Retrieve Job Information (QUSRJOBI) API:
http://as400bks.rochester.ibm.com/iseries/v5r2/ic2924/info/apis/qusrjobi...
Retrieve Product Information (QSZRTVPR) API:
http://as400bks.rochester.ibm.com/iseries/v5r2/ic2924/info/apis/qszrtvpr...
List Program Temporary Fixes (QpzListPTF) API:
http://as400bks.rochester.ibm.com/iseries/v5r2/ic2924/info/apis/qpzlstfx...
Convert Date and Time Format (QWCCVTDT) API:
http://as400bks.rochester.ibm.com/iseries/v5r2/ic2924/info/apis/qwccvtdt...
Create User Space (QUSCRTUS) API:
http://as400bks.rochester.ibm.com/iseries/v5r2/ic2924/info/apis/quscrtus...
Delete User Space (QUSDLTUS) API:
http://as400bks.rochester.ibm.com/iseries/v5r2/ic2924/info/apis/qusdltus...
Retrieve Pointer to User Space (QUSPTRUS) API:
http://as400bks.rochester.ibm.com/iseries/v5r2/ic2924/info/apis/qusptrus...
Convert Edit Code (QECCVTEC) API:
http://as400bks.rochester.ibm.com/iseries/v5r2/ic2924/info/apis/QECCVTEC...
Display Long Text (QUILNGTX) API:
http://as400bks.rochester.ibm.com/iseries/v5r2/ic2924/info/apis/quilngtx...
Send Program Message (QMHSNDPM) API:
http://publib.boulder.ibm.com/iseries/v5r2/ic2924/info/apis/QMHSNDPM.htm
Receive Program Message (QMHRCVPM) API:
http://as400bks.rochester.ibm.com/iseries/v5r2/ic2924/info/apis/QMHRCVPM...
The following MI built-in functions are demonstrated in this article:
Late Bound Edit (_LBEDIT):
http://publib.boulder.ibm.com/iseries/v5r1/ic2924/tstudio/tech_ref/mi/ED...
Materialize Machine Attributes (_MATMATR1):
http://publib.boulder.ibm.com/iseries/v5r1/ic2924/tstudio/tech_ref/mi/MA...
The following ILE C function is demonstrated in this article:
Test Bit in String (tstbts):
http://publib.boulder.ibm.com/iseries/v5r2/ic2924/books/c0924180.pdf
You can retrieve the source code for this API example from
http://www.iseriesnetwork.com/noderesources/code/clubtechcode/RtvSystemI... .
The above article was written by Carsten Flensburg. If you have any questions, you
can contact Carsten at mailto:flensburg@novasol.dk .
**********************************************************************
SPONSORED IN PART BY BCD and WebSmart
Everything you want to do on the Web you can do with your iSeries – i5 and
WebSmart
– Right Here, Right Now. IBM added WebSmart to the iSeries Developer
– Roadmap.
Whether you have a one person
IT shop or many people – you will succeed. Nothing beats the ease-of-use,
quick
learning curve, features, and ROI for developing Inquiries, Maintenance,
Order/Entry,
Shopping Carts apps and more. Free Trials.
http://www.bcdsoftware.com/progenwebsmart.htm
**********************************************************************
2. STRDBG CAN BE GUI!
In the past two newsletters, I've presented some information about debugging
in 132-column mode. That green-screen interface is nice, but this week I've
found something better: the iSeries System Debugger.
This debugger is a GUI interface to the debugging facility on the iSeries.
It does everything that the green screen program does, plus much more. Here
are some of the advantages it has over the green screen debugger:
-- A GUI screen with help files, pull down menus, and a graphical
look and feel that makes it easy to use.
-- It can debug PASE programs, Java programs, ILE programs, and OPM RPG
and CL programs.
-- When you tell it to monitor the value of a variable in your program,
you can check an option called "watch" that will automatically display
any changes made to your variable on the screen.
-- Works with interactive programs on the iSeries. You can use it with
any terminal emulator. The screens display in the emulator, while the
debugging happens in a separate window.
-- Works with batch jobs as well. If you don't know the job identifier of
the job you want to debug, you can click "browse" to get an interface
where you can select a job from a list.
-- It's lightweight. Unlike the Distributed Debugger that comes with WDSc,
the system debugger will run respectably well on a 400mhz PC with only
128mb of RAM!
-- It's written in pure Java, so it can be run from any workstation that's
capable of running Java programs.
That last item is a big deal for me. My favorite operating system is FreeBSD,
which is a free Unix-like operating system that is like Linux in many ways. One of
my perpetual frustrations with IBM's GUI tools like iSeries Navigator and WDSc
is that they only work on Windows. I don't think IBM realizes this, but by only
making their new updated tools for Windows, they're basically telling us,
"To choose the iSeries is to choose Windows." So, when I learned that the
iSeries System Debugger runs on any system, I was pleasantly surprised.
Of course, this debugger also works on Windows, Linux, and Mac systems.
The debugger was officially released with V5R2 of OS/400, but it can be
installed on a V5R1 system by installing two PTFs, SI02871 and SI02849.
You'll also need the IBM Toolbox for Java (5722-JC1) installed on your iSeries.
Once installed, you can start the iSeries side of the debugger on your V5R2 or
later system by typing the following command:
STRTCPSVR SERVER(*DBG)
Or, on a V5R1 system, you can start it by typing the following:
CALL QSYS/QTESSTRSVR
You'll also need to install the user interface on the workstation that you'd like
to do the debugging from. To do that, take the following steps:
a) If you don't already have it, you'll need version 1.3 or later of the Java
Runtime Environment installed on your PC. You can download this from
IBM's DeveloperWorks Web site at the following link:
http://www-128.ibm.com/developerworks/java/jdk/
You can also get the JRE from Sun's Web site at the following link:
http://java.sun.com/downloads/index.html
Or, if you're a FreeBSD user like me, you can install it from the ports collection.
I installed mine from the following port directory:
/usr/ports/java/jdk14
b) I created a directory to install my system debugger files into. On my Windows
system, I called the directory C:\SysDbg
c) You'll need to get the jhall.jar file from Sun's JavaHelp package. If you have
WDSc installed, you can copy that file from the C:\WDSC\JAVA directory to the
C:\SysDbg directory. If you don't have WDSc installed, you can download the
JavaHelp software from Sun's Web site at the following link:
http://java.sun.com/products/javahelp/
d) You'll also need to copy two JAR files from your iSeries to the C:\SysDbg
directory. The two files are called jt400.jar and tes.jar, and you can find them
in the /QIBM/ProdData/HTTP/Public/jt400/lib directory of your IFS.
Once you have everything installed, you need to add the JAR files that you
downloaded to Java's CLASSPATH and launch the Debug Manager. On my
Windows system, I wrote a little .BAT file to do this. I called it DebugMgr.bat,
and it contains the following code:
@echo off
set CLASSPATH=%CLASSPATH%;c:\sysdbg\jhall.jar
set CLASSPATH=%CLASSPATH%;c:\sysdbg\jt400.jar
set CLASSPATH=%CLASSPATH%;c:\sysdbg\tes.jar
java utilities.DebugMgr
If you're running a Unix-like system such as FreeBSD or Linux, you'll have
to use a different directory and set up the CLASSPATH in a shell script instead
of a batch file.
To start the debug manager, simply run the batch file. If all is well, a Window
entitled "iSeries Debug Manager" will pop up on your screen. The next step
is to click Edit->Add System to connect the debug manager to your iSeries.
Once the debug manager has been connected, the user-id that you signed
on with will be registered to use the iSeries System Debugger. If you have
additional iSeries systems that you'd like to connect to, you can click
Edit->Add System again to add them. Likewise, if you have alternate user names
on your iSeries, you can register them for use with the GUI debugger by
clicking Edit->Add User.
There are three ways to start an actual debug session in the iSeries System
Debugger.
-- One way is to click Debug->Start Debug from the debug manager. I've
found this to be the easiest way for batch jobs.
-- You can also start it using the STRDBG command from the iSeries, the
same command that you'd use for the green screen tool. When your
userid is registered through the debug manager to use the GUI
debugger, STRDBG will automatically start it instead of the green
screen one.
-- You can also start the debugger from the Windows command prompt by
typing (though I don't see why you'd want to) the following command:
java utilties.Debug
The iSeries System Debugger is a modern, powerful tool for debugging your
iSeries programs. If you're used to the green-screen tools, there might be a
learning curve before you have the hang of it, but once
you're beyond that curve, you won't want to go back!
**********************************************************************
SPECIAL ISERIES NETWORK OFFER
GET THE LATEST INFO ON E-LEARNING AND OTHER TRAINING. Stay in tune
to iSeries training opportunities with a free subscription to iSeries Network Mail.
This must-have e-newsletter brings you the latest info on iSeries Network e-learning
classes, self-paced training courses,
technical how-to guides, and more. PLUS, we'll bring you info on special offers,
discounted training, one-time events, and more. You'll know the moment a new
tech book is available, an e-learning class added, and training courses offered
with iSeries Network Mail. Log into 'My Profile' at iSeriesNetwork.com to add this
valuable e-newsletter to your subscriptions.
***************** ABOUT ISERIES NETWORK NEWSLETTERS ******************
WHY DID I GET ONLY TWO TIPS WHEN FOUR ARE LISTED?
The last two tips in this newsletter are premium content that is available only
to Pro and Pro VIP members of the iSeries Network.
If you're not a Pro or Pro VIP member, you will see the titles of these two extra
tips but will not be able to read their content. Please consider upgrading your
membership. If you do, you will receive not only the two bonus tips but also a
subscription to iSeries NEWS magazine -- andthe cost can be as low as USD
$29/year!
More info about the benefits is here:
http://www.iseriesnetwork.com/info/join/membership_levels/index_nojs.htm...
The Subscribe/Join page is here:
http://www.iseriesnetwork.com/join/
If you're a Pro or Pro VIP member and you're not getting the extra tips, here's
what you need to do:
a) Follow this link:
http://www.iseriesnetwork.com/info/profile/profilelogin.cfm
b) Make certain that the e-mail address you're using matches the e-
mail that you're subscribed to this newsletter with. If not,
unsubscribe using the instructions at the bottom of the newsletter
and then resubscribe through the membership profile page.
c) If you're still having problems, contact
mailto:service@iseriesnetwork.com .
***************** ABOUT ISERIES NETWORK NEWSLETTERS ******************
Club Tech iSeries Programming Tips Newsletter is published weekly on
Thursday, except for the first Thursday of the month. Club Tech iSeries
Systems Management
Newsletter is published on alternate Wednesdays. NEWS Wire Daily brings
you iSeries
industry news, tech
tips, product news, and IBM announcements Monday through Thursday.
All are *FREE OF CHARGE*!
IF YOU HAVE a technical question, please submit it to
mailto:clubtechprogrammingtips@iseriesnetwork.com or post it in the
appropriate iSeriesNetwork.com forum. This issue of the Programming Tips
newsletter was edited
by Scott Klement, at
mailto:sklement@iseriesnetwork.com .
FOR NEW SUBSCRIPTIONS, you can subscribe by joining the iSeries Network
with our handy Web form at
http://www.iseriesnetwork.com/join/ .
TO CHANGE YOUR E-MAIL ADDRESS, modify your iSeries Network profile at
http://www.iseriesnetwork.com/info/profile/profilelogin.cfm .
IF YOU HAVE PROBLEMS subscribing or unsubscribing or have questions
about your subscription, e-mail customer service at
mailto:prgrmtips@iseriesnetwork.com .
IF YOU WANT TO SPONSOR a Club Tech iSeries Programming Tips Newsletter,
please contact your iSeries Network sales manager. Click here for details:
http://www.iseriesnetwork.com/info/mediakit/ad_contacts.cfm .
iSeries is a trademark of International Business Machines (IBM)
Corporation and is used by Penton Media, Inc., under license. iSeries
NEWS, iSeriesNetwork.com, and the iSeriesNetwork.com newsletters are
published independently of IBM, which is not responsible in any way
for the content. Penton Media, Inc., is solely responsible for the
editorial content and control of iSeries NEWS, iSeriesNetwork.com, and
the iSeriesNetwork.com newsletters.
___________________________
Copyright 2005
Penton Technology Media, 221 E. 29th St., Loveland, CO 80538
(800) 793-5714 or (970) 203-2894
http://www.iSeriesNetwork.com