How to Code Selective prompting in CL AS400 & common mistake to avoid

How to Code Selective prompting in CL AS400 & common mistake to avoid
How to Code Selective prompting in CL and common mistake to avoid, cl command, as400, ibmi, as400 and sql tricks, as400 tutorial, ibmi tutorial, selective prompting in CL as400, selective prompting in CL ibmi, cpf6801, sndpgmmsg, SNDMSG,clle, cl as400
How to Code Selective prompting in CL and common mistake to avoid

How to code Selective prompting in CL program

To enable selective prompting in CL on any command just prefix the command with question mark sign (?). After selective prompting the command displays the list of parameters associated with the command when running in CL program and we input values to CL command parameters

  • Once we press ENTER the line having selective prompting used with the command gets executed i.e. the associated command gets executed.
  • If we press F3 or F12 or any active function keys on selective prompting command then we get CPF6801 error that needs to be handled in the CL program with the use of the selective prompting command in the CL.
  • For Example, here we are enabling selective prompting on SNDMSG command in CL program.

    ?SNDMSG

    CL program to Code Selective prompting

                 PGM                                                     
                                                                                                                                         
                 ?SNDMSG                                                 
                 MONMSG     MSGID(CPF6801) CMPDTA('F3') EXEC(RETURN)     
                                                                         
                 MONMSG     MSGID(CPF6801) EXEC(SNDPGMMSG MSG('F12 +     
                              PRESSED'))                                 
                                                                                                                                   
                 SNDPGMMSG  MSG(EXECUTED)                                
                                                                         
                 ENDPGM

    Explanation and output of the above program

  • Selective prompting used with SNDMSG CL command. Once this line gets executed the parameters of the SNDMSG command prompted while executing CL program.
  • ?SNDMSG
    Output:
                                  Send Message (SNDMSG)                             
                                                                                    
     Type choices, press Enter.                                                     
                                                                                    
     Message text . . . . . . . . . . MSG                                           
                                                                                    
                                                                                    
                                                                                    
                                                                                    
                                                                                    
                                                                                    
                                                                                    
     To user profile  . . . . . . . . TOUSR                                         

    Then you can type msg and Tousr values as below. Then you can press F10 tp see additional parameters and Input there values.

                                  Send Message (SNDMSG)                             
                                                                                    
     Type choices, press Enter.                                                     
                                                                                    
     Message text . . . . . . . . . . MSG            TEST                           
                                                                                    
                                                                                    
                                                                                    
                                                                                    
                                                                                    
                                                                                    
                                                                                    
     To user profile  . . . . . . . . TOUSR          EASYCLASS                      
    
  • Once you press ENTER key, The SNDMSG command gets executed and message gets send to the user EASYCLASS.
  •                                Display Messages               
                                                          System: 
    Queue . . . . . :   EASYCLASS               Program . . . . : 
      Library . . . :     QUSRSYS                 Library . . . : 
    Severity  . . . :   00                      Delivery  . . . : 
                                                                  
    Type reply (if required), press Enter.                        
      From  . . . :   EASYCLASS      06/09/22   20:09:10          
      TEST                                                        
  • And, If you press F3 key, we did monitor message CPF6801 handling and it compares data if you pressed F3 key then we returned from the program at this point.
  • MONMSG     MSGID(CPF6801) CMPDTA('F3') EXEC(RETURN)
  • And, If you press F12 key, we did monitor message CPF6801 handling and it compares data if we pressed F12 key then we send the program message "F12 PRESSED" and end the program.
  • MONMSG     MSGID(CPF6801) EXEC(SNDPGMMSG MSG('F12 +  
                 PRESSED'))                              
  • Otherwise, the send program message command gets executed and send the message "EXECUTED" to the program message queue.
  • SNDPGMMSG  MSG(EXECUTED)

    Common mistake to avoid

    When using selective prompting in your CL procedures, you must remember that the CL procedure stops and the command prompter appears. All function keys supported by the command prompter are active, including F3 (Exit) and F12 (Cancel). When the user presses F3 or F12, the command prompter issues an *ESCAPE message (CPF6801) to your CL procedure that must be handled in your CL program as described in above CL code.

    Post a Comment

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