Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

This command API is used to execute an IBM i CL command. 

Info

Note: In Profound.js release 7.10.0, API pjs.runCommand() was improved to work very similar to the C library function system() as called by RPG programs, with the following additions:

  • 2nd optional parameter ignoreError

  • 3rd optional parameter msgId.

  • return value of -1, 1, or 0.

These changes are backward-compatible with earlier releases of Profound.js; i.e. any current Profound.js modules that do NOT use these new features will behave as before.

  • 2nd optional parameter ignoreError

  • 3rd optional parameter msgId.

  • return value of -1, 1, or 0

    .

    Parameters

    1. Command - A string containing a CL command to execute.

    2. ignoreError - optional boolean value: “true” = ignore error if command fails; “false” = throw error if command fails. Default is “false”.

    3. msgId - optional strongly-defined char(7) field to be updated with the error MsgId if the command fails.

    ...

    • -1 : null is passed for command

    • 1: command fails

    • 0: command is successful

    Exception Handling

    An If the command fails, an Error instance will be thrown with the following properties, if the 2nd optional parameter ignoreError is not specified or “false”.

    ...

    RPG Equivalent 

    QCMDEXC System API or C library function system() .

    Examples

    Example 1: Check for existence of an object

    ...

    Code Block
    var command = "CRTDUPOBJ OBJ(ORDERSP) FROMLIB(DATALIB) OBJTYPE(*FILE) TOLIB(QTEMP) NEWOBJ(WORKFILE) DATA(*NO)";
    pjs.runCommand(command);

    Example 3: Run a command with parameters with return value (this feature is available since Profound.js 6.0.0

    ...

    )
    Code Block
    CL code:
    DCL        VAR(&NBRRCD) TYPE(*DEC) LEN(10 0)         
    RTVMBRD    FILE(PJSTEST/PRODUCTSP) NBRCURRCD(&NBRRCD)
    
    PJS code:
      pjs.define("nbrRcd", { type: 'packed', length: 10, decimals: 0});
      pjs.runCommand(`RTVMBRD FILE(PJSTEST/PRODUCTSP) NBRCURRCD(&nbrRcd)`);
      console.log(`nbrRcd = ${nbrRcd}`);

    ...