If you've ever written command definitions, you may have discovered that creating a parameter with a default value forces that parameter to be optional. Once a parameter is defined as optional (MIN value of 0), no parameter defined after it can be made mandatory (MIN value greater than 0). This requirement often causes programmers to make a parameter optional when it should be mandatory. There is a workaround for this problem that you might want to consider.
Here's an example to illustrate this technique: Let's say you want to create a command with two parameters. The first parameter is FROMDATE, for which you want to supply a default value of *CURRENT. The second parameter is TODATE, which must be entered. Since FROMDATE is optional (because it has a default value), you can't make TODATE mandatory.
To get around this problem, you can specify a display position relative to the other parameters in the PROMPT parameter of the PARM statement. The display position is specified as the second element of the PROMPT parameter, immediately after the prompt text. For an example of how this is done, look at the command definition in 9.
To get around this problem, you can specify a display position relative to the other parameters in the PROMPT parameter of the PARM statement. The display position is specified as the second element of the PROMPT parameter, immediately after the prompt text. For an example of how this is done, look at the command definition in Figure 9.
In this example, you can define TODATE first as a mandatory parameter with a relative display position value of 2. You can then define FROMDATE second with a relative display position value of 1. This way, you're satisfying the command compiler's requirement of a mandatory parameter definition ahead of an optional parameter definition. At the same time, you're causing the parameters to appear in the order you want, as shown in 10.
In this example, you can define TODATE first as a mandatory parameter with a relative display position value of 2. You can then define FROMDATE second with a relative display position value of 1. This way, you're satisfying the command compiler's requirement of a mandatory parameter definition ahead of an optional parameter definition. At the same time, you're causing the parameters to appear in the order you want, as shown in Figure 10.
? Robin Klima
TechTalk: Placing Required Parms After Optional
Figure 9: Example Command Source
CMD PROMPT('Example Command') PARM KWD(TODATE) TYPE(*DATE) MIN(1) PROMPT('To + date' 2) PARM KWD(FROMDATE) TYPE(*DATE) DFT(*CURRENT) + SPCVAL((*CURRENT 000000)) PROMPT('From + date' 1)TechTalk: Placing Required Parms After Optional
Figure 10: Example Command Prompt
Midrange Computing Magazine - December 1995
TechTalk: REXX Fetches SQL
by Jim Hoopes by 19951234 by 1995 DecemberHidden deep in the V3R1 announcement is support for SQL in REXX procedures. A new REXX keyword (EXECSQL) has been added to enable SQL support. 11 is an example REXX procedure that uses an SQL INSERT statement.
Hidden deep in the V3R1 announcement is support for SQL in REXX procedures. A new REXX keyword (EXECSQL) has been added to enable SQL support. Figure 11 is an example REXX procedure that uses an SQL INSERT statement.
The first EXECSQL statement in the example code sets off the commitment control level. That way, the file we're inserting the record into doesn't need to be journaled. The second EXECSQL statement runs the INSERT SQL statement using a REXX variable.
You can use either REXX variables or parameter markers for an SQL statement. Parameter markers allow you to create an SQL statement but fill in specific values later in the program. For example, you can code an SQL statement like this:
SELECT DEPT,DEPTDESC FROM DEPTMSTR WHERE DEPT=?That way, you could fill in the department number when you actually run the program.
Most SQL statements are supported, but a few aren't. Examples of SQL statements not supported in REXX include CONNECT, DECLARE PROCEDURE, and SELECT INTO. Even with the minor limitations, this new feature gives REXX powerful database capabilities.
One more tip: When you run the REXX procedure, make sure you code the Start REXXProcedure (STRREXPRC) command with the CMDENV(*EXECSQL) parameter. Otherwise, the REXX processor won't know what to do with the EXECSQL statements.
? Jim Hoopes
TechTalk: REXX Fetches SQL
Figure 11: Example REXX Procedure Using SQL
/* */ RC=0 INSRT_SQL = "Insert into items (ITEM#, ITEMDS, ITEMPR, ITEMVN) ", "VALUES(573, 'Widget', 12.95, 1232)" EXECSQL "SET OPTION COMMIT=*NONE" EXECSQL INSRT_SQL if rc = 0 then say "Record successfully inserted." else do say "SQL statement failed. SQL Code:" SQLCODE "SQL State:" SQLSTATE say "SQL Statement:" INSRT_SQL end
LATEST COMMENTS
MC Press Online