REXX has been around on the iSeries since, well, before my time. But rarely have I seen it utilized. However, I've found some simple uses for it that I'd like to share.
Use REXX as "Source" for Non-Source Objects
Often, iSeries applications consist of objects that
have no source to define them. Instead, they're created with CL commands. Such
objects may include data areas, data queues, and the like. And now, with ILE,
service programs and binding directories also fall into this category.
It
would be nice to see the CL commands that created these objects easily, without
having to wade through the output of DSPwhatever commands. You could put those
commands in CL programs, but then you'd have additional objects. This is why
REXX is ideal for storing Create (CRTxxx) commands for your non-source objects
and even for running the Create commands, without the need of a command line and
prompting.
When you create these "source" members, you can and probably
should set the source member type to reflect the object you are creating. If you
do, remember that PDM Option 16 and RSE Run Procedure won't work, but you can
easily place STRREXPRC in your own PDM option or RSE User Action.
Here's
an example for a data area:
"crtdtaara dtaara(FILES/CSK0940A) type(*char) len(1) value('0') ",
"text('Calculations in Process')"
Here's an example for a binding directory:
bnddir='UI00110RB';
"crtbnddir" bnddir;
"addbnddire" bnddir "((UI00110R01 *module))";
"addbnddire" bnddir "((UI00110R02 *module))";
"addbnddire" bnddir "((UI00110R03 *module))";
"addbnddire" bnddir "((UI00110R04 *module))";
"addbnddire" bnddir "((UI00110R05 *module))";
"addbnddire" bnddir "((UI00110R06 *module))";
Use REXX for One-Time and Fix-It Programs
The nice thing about using REXX for one-timer
solutions is that, as I said before, there is no program object. Also, you can
easily mix CL and SQL in the same REXX procedure (something that cannot easily
be done in CL).
Here's an example:
"cpyf HHAAUDT HHAAUDT tombr(HHAINS) mbropt(*add) ",
"increl((*if TFERROR *eq 'HHAINS'))"
address execsql execsql ,
"delete from HHAAUDT ",
"where TFERROR = 'HHAINS' with none"
"rgzpfm HHAAUDT keyfile(HHAAUDTL01 HHAAUDTL01)"
And here's another:
/* Add Triggers */
"addlible TRIGTRACK *last"
T = '*AFTER';
P = 'HHM000';
E = '*INSERT';
"TRGTADD FILE(HHMCARE) TRGTIME("T") TRGEVENT("E") PGM("P")";
"TRGTADD FILE(HHMCFR) TRGTIME("T") TRGEVENT("E") PGM("P")";
"TRGTADD FILE(HHMEWAL) TRGTIME("T") TRGEVENT("E") PGM("P")";
"TRGTADD FILE(HHMEWA) TRGTIME("T") TRGEVENT("E") PGM("P")";
"TRGTADD FILE(HHMLODR) TRGTIME("T") TRGEVENT("E") PGM("P")";
E = '*UPDATE';
"TRGTADD FILE(HHMCARE) TRGTIME("T") TRGEVENT("E") PGM("P") ",
"TRGUPDCND(*CHANGE)";
"TRGTADD FILE(HHMCFR) TRGTIME("T") TRGEVENT("E") PGM("P") ",
"TRGUPDCND(*CHANGE)";
"TRGTADD FILE(HHMLOT) TRGTIME("T") TRGEVENT("E") PGM("P") ",
"TRGUPDCND(*CHANGE)";
"TRGTADD FILE(HHMSCD) TRGTIME("T") TRGEVENT("E") PGM("P") ",
"TRGUPDCND(*CHANGE)";
"TRGTADD FILE(HHMSTOR) TRGTIME("T") TRGEVENT("E") PGM("P") ",
"TRGUPDCND(*CHANGE)";
Use REXX for Oft-Used Commands, Especially if They Are Complex
I once worked with an ODBC product that involved
incredibly complex OS/400 commands. The commands were ugly. Even when these
commands were put into CL programs, the commands were still ugly and hard to
maintain. Using REXX allowed me to code these commands in a readable,
maintainable format. Also, I did not have to recompile a CL program whenever a
change was necessary.
Here's an example, using that ODBC product:
|
What You Need to Know
You do not need to be an expert in REXX to use it
for these functions. By looking at the examples above, you can see how simple it
can be. You only need to know these basics:
Begin a REXX procedure with a
comment. Comments in REXX are like those in CL; they're embedded between /* and
*/.
- There is no need to declare variables in REXX. Simply assign a value to them.
- You can enclose the text of your command or SQL statement in single or double quotes. I suggest double quotes, in case something in the text contains single quotes.
- To put the contents of a variable into the command or SQL text, close the text with the quote, put in the variable, and use the quote to open any remaining text. If you do not want a space between the text and the variable contents, abut the text and the variable. If you do want the space, put a space between the text and the variable.
- If you need to continue a command or SQL statement to the next line, type a comma at the end of the previous line. Put a space before the comma if you need a space at that point of the command or SQL statement.
- Precede an SQL statement with address execsql execsql. Be aware of your commit level. If the file is not journaled, set the SQL commit option to *NONE, or use WITH NONE on your DML statements.
- Statements in a simple REXX procedure may end with a semicolon. It is optional.
With all the other technologies available on the
iSeries, REXX still has some uses. Avail yourself of REXX and make your life
easier.
Doug Eckersley is the iSeries
programmer with a premier homebuilder in Columbus. He has been programming on
the iSeries for 10 years and has been in the business for 15. He is certified by
IBM.
LATEST COMMENTS
MC Press Online