How to make prompt selective in CL

How to make prompt selective in CL.
How to make prompt selective in CL, Create CL Program (CRTCLPGM) command,SNDMSG, selective prompting in CL, as400, ibmi, as400 and sql tricks, as400 tutorial, ibmi tutorial, working with ifs
How to make prompt selective in CL

Making the prompt selective in CL

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:

  • Select the parameters for which prompting is needed.
  • Regulate which parameters are protected.
  • Take out parameters from the prompt.
  • Here, In this article you can have an basic idea of how to code selective prompting in CL program. In this article, you will learn how to prompt for specific parameters of the CL command using selective prompting. We will use the SNDMSG comamnd as an example to make the prompt selective.

    How to make prompt selective in CL program

                  PGM                                                                    
                                                                                                                                                                      
                  ?SNDMSG ??MSG()                                                        
                  MONMSG     MSGID(CPF6801) CMPDTA('F3') EXEC(RETURN)                    
                                                                                         
                  MONMSG     MSGID(CPF6801) EXEC(SNDPGMMSG MSG('F12 +                    
                               PRESSED'))                                                
                                                                                         
                                                                                         
                  SNDPGMMSG  MSG(EXECUTED1)                                              
                                                                                         
                  ?SNDMSG ??MSG('TEST MESSAGE')                                          
                  MONMSG     MSGID(CPF6801) CMPDTA('F3') EXEC(RETURN)                    
                                                                                         
                  MONMSG     MSGID(CPF6801) EXEC(SNDPGMMSG MSG('F12 +                    
                               PRESSED'))                                                
                                                                                         
                  SNDPGMMSG  MSG(EXECUTED2)                                              
                                                                                         
                                                                                         
                  ?SNDMSG ?*TOMSGQ()                                                     
                  MONMSG     MSGID(CPF6801) CMPDTA('F3') EXEC(RETURN)                    
                                                                                         
                  MONMSG     MSGID(CPF6801) EXEC(SNDPGMMSG MSG('F12 +                    
                               PRESSED'))                                                
                                                                                         
                  SNDPGMMSG  MSG(EXECUTED3)                                              
                                                                                         
                                                                                         
                  ?SNDMSG ?*TOMSGQ(QSYSOPR)                                              
                  MONMSG     MSGID(CPF6801) CMPDTA('F3') EXEC(RETURN)                    
                                                                                         
                  MONMSG     MSGID(CPF6801) EXEC(SNDPGMMSG MSG('F12 +                    
                               PRESSED'))                                                
                                                                                         
                  SNDPGMMSG  MSG(EXECUTED4)                                              
                                                                                         
                                                                                         
                                                                                        
                  ?SNDMSG ?-MSGTYPE()                                                    
                  MONMSG     MSGID(CPF6801) CMPDTA('F3') EXEC(RETURN)                    
                                                                                         
                  MONMSG     MSGID(CPF6801) EXEC(SNDPGMMSG MSG('F12 +                    
                               PRESSED'))                                                
                                                                                         
                  SNDPGMMSG  MSG(EXECUTED5)                                              
                                                                                         
                                                                                         
                  ?          SNDMSG ?-MSGTYPE(*INQ)                                      
                  MONMSG     MSGID(CPF6801) CMPDTA('F3') EXEC(RETURN)                    
                                                                                         
                  MONMSG     MSGID(CPF6801) EXEC(SNDPGMMSG MSG('F12 +                    
                               PRESSED'))                                                
                                                                                         
                  SNDPGMMSG  MSG(EXECUTED6)                                              
                                                                                         
                                                                                         
                  ENDPGM                                                                 
    

    Explanation

  • Prefixed the SNDMSG command with control character i.e. question mark(?) to make prompt selective and then we use double question mark (??) with parameter MSG() then that means msg() parameter is input capable and we must have to input value to this parameter during prompting. The default value is blank for msg() parameter. We can change this message during selective prompting.
  • We do monitor message CPF6801 handling with selective prompting just because at any time user can press F3 or F12 to exit from the selective prompting.In case user do not press F3 or F12 then SNDMSG command got execure and we send a message to the program message queue using SNDPGMMSG command.

                  ?SNDMSG ??MSG()                                                        
                  MONMSG     MSGID(CPF6801) CMPDTA('F3') EXEC(RETURN)                    
                                                                                         
                  MONMSG     MSGID(CPF6801) EXEC(SNDPGMMSG MSG('F12 +                    
                               PRESSED'))                                                
                                                                                         
                                                                                         
                  SNDPGMMSG  MSG(EXECUTED1)            
    Output:

    Below MSG param is input capable and must be entered. If we do not enter any value to the MSG parameter of the SNDMSG command then we get error message i.e. "parameter MSG required".

  • This code is same as the above snippet, the only difference is we have provided default message as "TEST MESSAGE" instead of blank in above case.
  •               ?SNDMSG ??MSG('TEST MESSAGE')                                          
                  MONMSG     MSGID(CPF6801) CMPDTA('F3') EXEC(RETURN)                    
                                                                                         
                  MONMSG     MSGID(CPF6801) EXEC(SNDPGMMSG MSG('F12 +                    
                               PRESSED'))                                                
                                                                                         
                  SNDPGMMSG  MSG(EXECUTED2)            
    Output:

    Here, MSG() parameter is input capable and having default value "TEST MESSAGE" and can be changed during selective prompting of command SNDMSG.

  • Here, In this code snippet we use one question mark and aestrisk character with TOMSGQ() parameter of the SNDMSG command which means this TOMSGQ() is not anymore input capabale field. It's now an output capable field i.e. we cannot change the value of this TOMSGQ() parameter during selecive prompting.
  •               ?SNDMSG ?*TOMSGQ()                                                     
                  MONMSG     MSGID(CPF6801) CMPDTA('F3') EXEC(RETURN)                    
                                                                                         
                  MONMSG     MSGID(CPF6801) EXEC(SNDPGMMSG MSG('F12 +                    
                               PRESSED'))                                                
                                                                                         
                  SNDPGMMSG  MSG(EXECUTED3)      
    Output:

    Here, TOMSGQ() parameter is output capable and having default value blank and cannot be changed during selective prompting of command SNDMSG.

  • This code is same as the above snippet, the only difference is we have provided default value as "QSYSOPR" instead of blank to TOMSGQ() parameter in above case.
  •               ?SNDMSG ?*TOMSGQ(QSYSOPR)                                              
                  MONMSG     MSGID(CPF6801) CMPDTA('F3') EXEC(RETURN)                    
                                                                                         
                  MONMSG     MSGID(CPF6801) EXEC(SNDPGMMSG MSG('F12 +                    
                               PRESSED'))                                                
    
                  SNDPGMMSG  MSG(EXECUTED4)      
    Output:

    Here, TOMSGQ() parameter is output capable and having default value "QSYSOPR" and cannot be changed during selective prompting of command SNDMSG.

  • Here, In this code snippet we use one question mark(?) and dash(-) character with MSGTYPE() parameter of the SNDMSG command which means this MSGTYPE() parameter is now hidden during selective prompting. We cannot be able to see this parameter in the command during execution.
  •               ?SNDMSG ?-MSGTYPE()                                                    
                  MONMSG     MSGID(CPF6801) CMPDTA('F3') EXEC(RETURN)                    
                                                                                         
                  MONMSG     MSGID(CPF6801) EXEC(SNDPGMMSG MSG('F12 +                    
                               PRESSED'))                                                
                                                                                         
                  SNDPGMMSG  MSG(EXECUTED5)              
    Output:

    Here, MSGTYPE() parameter is hidden during selective prompting of command SNDMSG. Its default value is blank.

  • This code is same as the above snippet, the only difference is we have provided default value as "*INQ" instead of blank to MSGTYPE() parameter in above case.
  •               ?          SNDMSG ?-MSGTYPE(*INQ)                                      
                  MONMSG     MSGID(CPF6801) CMPDTA('F3') EXEC(RETURN)                    
                                                                                         
                  MONMSG     MSGID(CPF6801) EXEC(SNDPGMMSG MSG('F12 +                    
                               PRESSED'))                                                
                                                                                         
                  SNDPGMMSG  MSG(EXECUTED6)     
    Output:

    Here, MSGTYPE() parameter is hidden during selective prompting of command SNDMSG. Its default value is "*INQ".

    But, when you press SHIFT + F2, you will see the hidden parameter and its provided value for selective prompting.

    Post a Comment

    © AS400 and SQL Tricks. All rights reserved. Developed by Jago Desain