The QSYS.QCMDCHK API
The QCMDCHK API from the QSYS library validates the syntax and correctness of a CL command before execution. Its IBM documentation specifies two input parameters:
| Parameter | IBM i type | Direction | Role |
|---|---|---|---|
Command string |
Char(*) | I/O | command to check |
Length of command string |
Packed(15,5) | Input | length in number of characters |
Call QSYS.QCMDCHK from .NET with NTi
In this example, the API is called to validate the following command:
CRTLIB CLIENTSStep 1 - Establish the connection
var conn = new NTiConnection(connectionString);
conn.Open();Step 2 - Declare the parameters
var cmd = "CRTLIB CLIENTS";
var parms = new List<NTiProgramParameter>()
{
new NTiProgramParameter(cmd, cmd.Length),
new NTiProgramParameter(cmd.Length, 15, 5)
};
NTi supports all parameter types: integers, packed decimals, character strings.
Step 3 - Call the API
conn.CallProgram("QSYS", "QCMDCHK", parms);Summary
The QCMDCHK call is achieved with the following code:
var conn = new NTiConnection(connectionString);
conn.Open();
var cmd = "CRTLIB CLIENTS";
var parms = new List<NTiProgramParameter>()
{
new NTiProgramParameter(cmd, cmd.Length),
new NTiProgramParameter(cmd.Length, 15, 5)
};
conn.CallProgram("QSYS", "QCMDCHK", parms);
Two possible outcomes at runtime:
✅ Valid command - no exception thrown, return code is 0.
❌Invalid command - an exception is raised on the C# side with a CPFXXXX code and its explanation.
Conclusion
With NTi Data Provider, call an IBM i system API takes just a few lines of C#, with no green screen involved. By combining system APIs, CL commands and SQL services, IBM i administration tasks can be automated and integrated into modern interfaces.
This example uses two parameters, but the same principle applies regardless of the complexity of the API being called..
Rémi Rouillot