IBM Support

Usage of QCMDEXC in ILE RPG IV program

Troubleshooting


Problem

This document provides a simple example of using QCMDEXC in ILE RPG IV program.

Resolving The Problem

This document provides a simple example of using QCMDEXC in ILE RPG IV program. The program is a very simple interpreter of CL commands. It provides the user with a command line and passes the user's input to QCMDEXC for execution. This process is repeated in a loop that the user can end by pressing F3.

The program does not trap errors so code unrelated to the purpose of this example is not included. Therefore, program execution ends if a CL command errors out when executed. In addition, prompting of command parameters using F4 is not supported.

DDS for the externally described DSPF INTERPDSPF:
     A                                      DSPSIZ(24 80 *DS3)
     A          R COMMANDREC                CA03(93)
     A                                 10  1'CL COMMAND: '
     A            COMMANDFLD    80A  B 12  1
     A                                 14  1'F3 = EXIT'       
Example ILE RPG IV COMMANDER2:
**FREE
  // This program is a simple CL command interpreter.
  // The essential control flow consists of a loop, which prompts the user
  // for a CL command and then executes it.  The loop ends when the user
  // presses <F3>.
  // The code segment is intended to demonstrate the basic machinery involved
  // in using QCMDEXC in ILE RPG.
  //
  //
  // Externally described DSPF under user control.
  Dcl-F INTERPDSPF WORKSTN USROPN;
  //
  // Standalone field specifying the length of the command passed to QCMDEXC
  Dcl-S COMMANDLEN      Packed(15:5)    INZ(80);
  // Prototype for QCMDEXC
  Dcl-Pr Pgm_QCMDEXC ExtPgm('QCMDEXC');
    COMMANDFLD      Char(80);
    COMMANDLEN      Packed(15:5);
  End-Pr;
  //
  Open INTERPDSPF;
  //
  // Do until the user presses <F3>
  DoU *IN93 = *ON;
    //
    // Prompt user for a CL command and read response
    Exfmt COMMANDREC;
    //
    // Execute the command the user entered
    Pgm_QCMDEXC(COMMANDFLD : COMMANDLEN);
    //
    // Clear the DSPF record (clears out the last command the user keyed in)
    Clear COMMANDREC;
    //
    // Exit loop if user pressed <F3>
  EndDo;
  //
  Close INTERPDSPF;
  //
  *INLR = *ON; 
Compile using CRTBNDRPG
Call from command line:
 ===> call commander2
image-20241124091452-1
image-20241124091541-2

[{"Type":"MASTER","Line of Business":{"code":"LOB68","label":"Power HW"},"Business Unit":{"code":"BU070","label":"IBM Infrastructure"},"Product":{"code":"SWG60","label":"IBM i"},"ARM Category":[{"code":"a8m3p0000006x8GAAQ","label":"CL"},{"code":"a8m0z0000000CHtAAM","label":"Programming ILE Languages"}],"ARM Case Number":"","Platform":[{"code":"PF012","label":"IBM i"}],"Version":"All Versions"}]

Historical Number

15345624

Document Information

Modified date:
24 November 2024

UID

nas8N1018113