CheckCLCommand() method.

Description.

The CheckCLCommand method queries the QCMDCHK API to validate a CL command (*CMD).

This method is used to check the syntax and validity of the supplied command without executing it. It is particularly useful for ensuring that a command is correctly formatted before sending it for execution.

Syntax.

CheckCLCommand(string commandText)

Parameters.

Name Type Description
commandText string The full text of the command to be validated (variable length).

Return.

If the command is valid, no error is raised and the command is considered correct with a return code of 0.
If the command is incorrect, an exception of type NTiProgramException is thrown with a CPF code from the IBM i system, indicating a specific validation error.

Exceptions.

  • NTiProgramException: Thrown if order validation fails, accompanied by a CPF error code to detail the nature of the error.

Examples of use.

try 
{ 
    conn.CheckCLCommand(‘CRTLIB LIB(TESTLIB)’); 
    Console.WriteLine(‘✅ The command is valid.’); 
} 
catch (NTiProgramException ex)
{ 
    Console.WriteLine($‘❌ The command is incorrect: {ex.Message}’); 
}

References.

For more information on the QCMDCHK API, see the official IBM documentation.