I like building AS/400 menus with SDA. I can create or change a menu quickly and easily and move on to other things. One thing I dislike about SDA menus is that I can put only one command behind an option. I often have to write a CL program just to run two CL commands behind a menu option, and I dislike cluttering up my libraries with tiny CL programs that are used on only one menu.
The Execute Command (XC) command (shown in Figures 1 and 2) provides a way to execute more than one command when choosing a menu option. The first parameter is a series of CL commands separated by some delimiter. The system executes each command in order. All commands in the command string must be executable by the QCMDEXC program. To check whether QCMDEXC will execute a command, use the Display Command (DSPCMD) command. If the "Where allowed to run" parameter includes *EXEC, you can use the command within an XC command string.
The second parameter is the delimiter. It defaults to a backslash (), but any character that isn't used in the commands in the command string will do.
The third parameter tells the job what to do if a command terminates abnormally. You can ignore the error and continue with the next command or cancel processing the command string.
3 illustrates how I might issue an override, call two programs, and delete the override from one menu option. Because I wanted to be able to enter a long command string, I kept the name of the command and all parameters as short as I could. I also provided defaults for parameters D and F so they would not have to be coded.
Figure 3 illustrates how I might issue an override, call two programs, and delete the override from one menu option. Because I wanted to be able to enter a long command string, I kept the name of the command and all parameters as short as I could. I also provided defaults for parameters D and F so they would not have to be coded.
- Ted Holt
TechTalk: Execute multiple commands from an SDA menu without writing a CL program.
Figure 1: The XC Command Definition
/*==================================================================*/ /* To compile: */ /* */ /* CRTCLPGM PGM(XXX/XC) SRCFILE(XXX/QCLSRC) */ /* */ /*==================================================================*/ CMD PROMPT('Execute commands') PARM KWD(C) TYPE(*CHAR) LEN(110) MIN(1) + PROMPT('Commands') PARM KWD(D) TYPE(*CHAR) LEN(1) DFT('') + PROMPT('Command delimiter') PARM KWD(F) TYPE(*CHAR) LEN(1) RSTD(*YES) DFT(C) + VALUES(C I) CHOICE('C=cancel, I=ignore') + PROMPT('Command failure option')
TechTalk: Execute multiple commands from an SDA menu without writing a CL program.
Figure 2: CL Program XCL
/*==================================================================*/ /* To compile: */ /* */ /* CRTCLPGM PGM(XXX/XCL) SRCFILE(XXX/QCLSRC) */ /* */ /*==================================================================*/ PGM PARM(&CMDSTRING &DELIMITER &FAILOPTION) DCL VAR(&CMDSTRING) TYPE(*CHAR) LEN(110) DCL VAR(&DELIMITER) TYPE(*CHAR) LEN(1) DCL VAR(&FAILOPTION) TYPE(*CHAR) LEN(1) DCL VAR(&CMDS) TYPE(*CHAR) LEN(111) DCL VAR(&COMMAND) TYPE(*CHAR) LEN(110) DCL VAR(&FX) TYPE(*DEC) LEN(3) DCL VAR(&TX) TYPE(*DEC) LEN(3) DCL VAR(&MSGDTA) TYPE(*CHAR) LEN(132) DCL VAR(&MSGF) TYPE(*CHAR) LEN(10) DCL VAR(&MSGFLIB) TYPE(*CHAR) LEN(10) DCL VAR(&MSGID) TYPE(*CHAR) LEN(7) CHGVAR VAR(&CMDS) VALUE(&CMDSTRING *CAT &DELIMITER) /* Begin extraction of next command in series */ NEXTCMD: CHGVAR VAR(&COMMAND) VALUE(' ') CHGVAR VAR(&TX) VALUE(0) /* Build a command 1 character at a time */ BLDCMD: CHGVAR VAR(&FX) VALUE(&FX + 1) IF COND(%SST(&CMDS &FX 1) *EQ &DELIMITER) + THEN(GOTO CMDLBL(RUNCMD)) CHGVAR VAR(&TX) VALUE(&TX + 1) CHGVAR VAR(%SST(&COMMAND &TX 1)) VALUE(%SST(&CMDS + &FX 1)) GOTO CMDLBL(BLDCMD) /* Command has been extracted -- execute it */ RUNCMD: IF COND(&COMMAND *NE ' ') THEN(DO) CALL PGM(QCMDEXC) PARM(&COMMAND 110) MONMSG MSGID(CPF0000) EXEC(DO) FWDMSG: RCVMSG MSGDTA(&MSGDTA) MSGID(&MSGID) MSGF(&MSGF) + SNDMSGFLIB(&MSGFLIB) IF COND(&MSGID *NE ' ') THEN(DO) SNDPGMMSG MSGID(&MSGID) MSGF(&MSGFLIB/&MSGF) + MSGDTA(&MSGDTA) GOTO CMDLBL(FWDMSG) ENDDO IF COND(&FAILOPTION *EQ C) THEN(GOTO + CMDLBL(ENDPGM)) ENDDO ENDDO IF COND(&FX *LT 110) THEN(GOTO CMDLBL(NEXTCMD)) ENDPGM: ENDPGM
TechTalk: Execute multiple commands from an SDA menu without writing a CL program.
Figure 3: Example Use of XC
XC ('ovrprtf arrpt hold(*yes)call pgmacall pgmbdltovr arrpt')
LATEST COMMENTS
MC Press Online