i5_cmd

 

Executes I5 command.

 

resource i5_cmd (

string command
[,
resource connection])

 

Detail

 

It could be a command with or without parameters, in this case it's better to use i5_remotecmd for performance as well as for error management.

Syntax is similar to a CL command, variables names with "&" in front.

Example: $ret = i5_cmd("RTVJOBA USER(&USR)");

More than 20 characters variable or with type other than CHAR must be declared in CHAR(len) or DEC(len dec). All declarations separated with semicolon ";".

Example: $ret = i5_cmd("LIBL=CHAR(2750);DFTWAIT=DEC(7 0);RTVJOBA USRLIBL(&LIBL)");

 

Further to i5_cmd call, output variables can be fetched with i5_cmdget function (one at a time).

 

Warning! If, with a correct syntax execution fails, the function does not create error but update a special variable called RC.

This variable contains, in case of fault, provoked CPF code and 0 in case of success.

It is always necessary to check every time that the RC variable is null before fetching the command proper variables.

 

Parameters

 

command

String; Command to execute

connection

Connection ID(optional)

 

Returns:

True if OK, false if failed.

 

I5_ERR_PHP_HDLDFT

256

No default connection found.

I5_ERR_PHP_HDLCONN

257

This resource has no connection active.

I5_ERR_PHP_RESOURCE_BAD

261

No resource found .

I5_ERR_PHP_TYPEPARAM

262

Type of element x in parameter -1 must be y. Type z was provided.

I5_ERR_PHP_TYPEPARAM

262

Type of element x in parameter -1 must be y. Type z was provided.

I5_ERR_PHP_NBPARAM_BAD

263

Wrong parameter count

 

 

Example

 

/* Connection to AS400 */

$conn = i5_connect("MY_AS", "USER", "PASSWORD");

 

 

/* Executes the command on AS400 */

i5_cmd("user=char(10);usrlib=char(275);syslib=char(165);curl=char(10);rtvjoba user(&user) usrlibl(&usrlib) syslibl(&syslib) curlib(&curl)");

 

if ($ret) {

 

$res = i5_cmdget("RC");

    if (RC==0) {

        $util = i5_cmdget("user", $conn);

        $bibl = i5_cmdget("usrlib", $conn);

        $sysb = i5_cmdget("syslib", $conn);

        $curl = i5_cmdget("curl", $conn);

 

        print "User: ". $util."<br>" ;

        print "User libraries list: ". $bibl . "<br>" ;

        print "System libraries list: ". $sysb."<br>" ;

        print "Current library: " . $curl . "<br>" ;

    }

}

 

 

/* Executes the command on I5 */

$ret = i5_cmd("NB=CHAR(20); RTVSYSVAL SYSVAL(QSRLNBR) RTNVAR(&NB)");

 

if ($ret) {

    $res = i5_cmdget("RC");

    if (RC==0) {

 

        /* Retrieves the executed command concerned variable */

        $num = i5_cmdget("NB");

        echo "Serial number is ". $num ."<BR>";

        }

    }

 

 

 

See also

 

i5_cmdget

i5_remotecmd