Now, Get RPG Codes in all three formats only on this website on every RPGLE related programming article.

Fixed, /Free and Fully Free RPG


Using QCMDCHK (Check Command Syntax) API in CL

Using QCMDCHK (Check Command Syntax) API in CL
Using QCMDCHK API in CL, Check Command Syntax (QCMDCHK) API , cl commands, cl api, c apis, as400, ibmi, as400 and sql tricks, as400 tutorial, ibmi tutorial,
Using QCMDCHK API in CL

What is QCMDCHK API in CL?

The Check Command Syntax (QCMDCHK) API executes syntax checking for a single command, and alternately prompts for the command.

When prompting is requested i.e. question mark (?) prefixed with the CL command then the command string gets returned to the calling procedure or program with the updated values that are entered through prompting of command.

  • QCMDCHK prompts the user for a command and then save the command for later execution.
  • Find the parameters that user specified for the command.
  • We can first prompt the command using QCMDCHK and then execute with QCMDEXC command
  • Prototype of QCMDCHK api

    CALL PGM(QCMDCHK) PARM(command  command-length)

    The first parameter to QCMDCHK api is a character string having the command to be prompted and validated. If the first parameter is variable and prompting is requested then the command inputted by the workstation user is placed in the variable.

    The second parameter is the maximum length of the command string being passed to QCMDCHK api. The second parameter must be packed decimal of length 15 with 5 decimal positions.

    The QCMDCHK program do the syntax checking on the command string being passed to it. It verifies that all required parameters to the comamnd are passed and that all parameters have valid values. If a syntax check error encountered on the passed command string then message CPF0006 is sent. We can monitor this CPF0006 message.

    Using QCMDCHK API in CL

                 PGM                                                         
                 DCL        VAR(&CMD) TYPE(*CHAR) LEN(500)                   
                 DCL        VAR(&LEN) TYPE(*DEC) LEN(15 5)                   
                                                                             
                 DCL        VAR(&MSGID) TYPE(*CHAR) LEN(7)                   
                 DCL        VAR(&MSGF) TYPE(*CHAR) LEN(10)                   
                 DCL        VAR(&MSGFLIB) TYPE(*CHAR) LEN(10)                
                 DCL        VAR(&MSGDTA) TYPE(*CHAR) LEN(80)                 
                                                                             
                 CHGVAR     VAR(&CMD) VALUE('DLTF FILE(QTEMP/A1234567894)')  
                 CHGVAR     VAR(&LEN) VALUE(%LEN(&CMD))                      
                                                                             
                 CALL       PGM(QCMDCHK) PARM(&CMD &LEN)                     
                 MONMSG     MSGID(CPF0006) EXEC(DO)                          
                 RCVMSG     MSGTYPE(*DIAG) MSGDTA(&MSGDTA) MSGID(&MSGID) +   
                              MSGF(&MSGF) MSGFLIB(&MSGFLIB)                  
                 ENDDO                                                       
                                                                             
                 ENDPGM                                                      
    

    Explanation

    The above program checks syntax of the command DLTF passed to QCMDCHK api. In DLTF command you can see the file name is longer than 10 characters that is incorrect. Therefore, CPF0006 message is detected during execution and we recieve the diagnostic message using RCVMSG command.

    Output:
  • DSPJOBLOG
  •  4 > CALL EASYCLASS1/CLPGM11                                              
           1300 - CALL PGM(QCMDCHK)          /* The CALL command contains     
           parameters */                                                      
         Value 'A123456789' for FILE exceeds 10 characters.                   
         Error found on DLTF command.                                         
         Errors occurred in command.                                          
    &MSGDTA =   ?FILE      A123456789 ?
    &MSGID = 'CPD0074' 
    &MSGF = 'QCPFMSG   '
    &MSGFLIB = '*LIBL     ' 
    

    Post a Comment

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