StarQuest Technical Documents

Calling an AS/400 Program with QCMDEXC

Last Update: 04 June 2014
Product: StarSQL
Version: 5.x, 6x
Article ID: SQV00SQ040

Abstract

You can execute a program on the AS/400 using the program QCMDEXC.

Solution

For example, if you have a program called MYPGM that you want to execute, you could send this SQL statement to the AS/400:

CALL QSYS.QCMDEXC('CALL PGM (MYLIB/MYPGM)', 0000000022.00000)

You can also enable additional messages to be logged on the AS/400 joblog by running this command:

CALL QSYS.QCMDEXC('STRDBG UPDPROD(*YES)',0000000020.00000)

The second parameter is the number of characters, including spaces between the single quotes in the STRDBG UPDPROD(*YES) command, which in this case is 20.

Note: The second parameter must contain exactly 15 digits: ten to the left of the decimal and five to the right. (If you are building a custom application, you can write a module to count the length of the command and create the second parameter for you.)

The procedure must be registered; otherwise StarSQL will return the error:

[StarSQL][StarSQL ODBC Driver]Column not found.

To register it, execute the following SQL statement on the AS/400:

CREATE PROCEDURE QSYS.QCMDEXC(IN :CMDSTR VARCHAR(1024),IN :CMDLENGTH DECIMAL(15,5)) EXTERNAL NAME QSYS.QCMDEXC LANGUAGE C GENERAL

Additional References

For more information, see Sample SQL for Registering a Stored Procedure on the AS/400.

Please reference the IBM Book OS/400 CL Programming, Advanced Programming Topics that pertains to your specific AS/400 version.


DISCLAIMER

The information in technical documents comes without any warranty or applicability for a specific purpose. The author(s) or distributor(s) will not accept responsibility for any damage incurred directly or indirectly through use of the information contained in these documents. The instructions may need to be modified to be appropriate for the hardware and software that has been installed and configured within a particular organization.  The information in technical documents should be considered only as an example and may include information from various sources, including IBM, Microsoft, and other organizations.