Selective Prompting and QCMDCHK in CL |
Selecting Prompting for CL commands
Selective prompting for CL commands is especially helpful when you are using some of the longer commands and do not want to be prompted for certain parameters. You can use selective prompting to:
What is QCMDCHK program?
The Check Command Syntax (QCMDCHK) API is an IBM-supplied program that performs syntax checking for a single command, and alternately prompts for the command.
Selective Prompting and QCMDCHK in CL
We can request prommpting for the command by placing question mark(?) before the command string passed to the QCMDCHK api or any other selective prompt characters. If no errors are detected during checking and prompting for the CL command then the updated CL command string is placed in the variable specified in the first parameter for the QCMDCHK api. The prompt request characters are removed from the command string as well. Please refer the below example program to better understand the selective prompting and QCMDCHK api in integration.
CL Program using Selective Prompting and QCMDCHK API
PGM DCL VAR(&CMD) TYPE(*CHAR) LEN(500) DCL VAR(&LEN) TYPE(*DEC) LEN(15 5) CHGVAR VAR(&CMD) VALUE('?DLTF') CHGVAR VAR(&LEN) VALUE(%LEN(&CMD)) CALL PGM(QCMDCHK) PARM(&CMD &LEN) MONMSG MSGID(CPF6801) CMPDTA('F3') EXEC(RETURN) MONMSG MSGID(CPF6801) EXEC(SNDPGMMSG MSG('F12 + PRESSED')) SNDPGMMSG MSG(EXECUTED) ENDPGM
Explanation
CHGVAR VAR(&CMD) VALUE('?DLTF') CHGVAR VAR(&LEN) VALUE(%LEN(&CMD))`
CALL PGM(QCMDCHK) PARM(&CMD &LEN) MONMSG MSGID(CPF6801) CMPDTA('F3') EXEC(RETURN) MONMSG MSGID(CPF6801) EXEC(SNDPGMMSG MSG('F12 + PRESSED')) SNDPGMMSG MSG(EXECUTED)
Once QCMDCHK api gets executed, we will see the DLTF command gets checked and prompted.
Delete File (DLTF) Type choices, press Enter. File . . . . . . . . . . . . . . FILE Library . . . . . . . . . . . *LIBL
We input value to the DLTF command parameter as below and press Enter.
? DLTF FILE(QTEMP/TEST)
After the call to the QCMDCHK api got executed, variable &CMD contains the command string with all the values entered through the selective prompt command. The final command will be as below after selective prompt characters such as question mark(?) gets removed.
Note:Please note thate when selective prompting is requested through the QCMDCHK api, the command string must be passed through the CL variable so that updated command must be returned to CL variable and the CL variable must be defined long enough to hold the returned updated command string after selective prompting got executed through the QCMDCHK program. If it is not long enough then message CPF0005 is sent, and the variable contains the command string is not changed.
If we press F3 or F12 to exit the selective prompting while running QCMDCHK, message CPF6801 is sent to the procedure or program that called QCMDCHK api and the variabke containing the command string is not changed therefore, we must handle the monitor message CPF6801 as done in the above code.