Toolkit Sample Scripts

This topics details the PHP XMLSER

Name Code

Display Library (DSPLIBL)

<pre>

This program runs following CL commands:

- ADDLIBLE ZENDSVR6

- DSPLIBL

</pre>

 

<?php

include_once 'authorization.php';

include_once 'ToolkitService.php';

 

try {

$obj = ToolkitService::getInstance($db, $user, $pass);

}

catch (Exception $e) {

echo $e->getMessage(), "\n";

exit();

}

 

$obj->setToolkitServiceParams(array('InternalKey'=>"/tmp/$user",

'debug'=>true,

'plug' => "iPLUG32K"));

$cmd = "addlible ZENDSVR";

$obj->CLCommand($cmd);

echo "<pre>";

$Rows = $obj->CLInteractiveCommand("DSPLIBL");

/*$Rows = $obj->CLInteractiveCommand("WRKSYSVAL OUTPUT(*PRINT)");*/

if(!$Rows )

echo $obj->getLastError();

else

var_dump($Rows);

 

echo "</pre>";

 

/* Do not use the disconnect() function for "state full" connection */

$obj->disconnect();

?>

Program Call (Two Parameters)

<?php

/*

RPG program parameters definition

PLIST

PARM CODE 10

PARM NAME 10

 

*/

 

include_once 'authorization.php';

include_once 'ToolkitService.php';

include_once 'helpshow.php';

//The ToolkitService connection method/function uses either IBM_DB2(default)or ODBC extensions to connect

//to IBM i server. In order to switch to ODBC connection assign an "odbc' value to the $extension varibale

//and make sure that the ODBC extension is enabled in the PHP.INI file.

//The ODBC extension usage in ToolkitService is preferable in 2 tier environment: Zend Server running in Windows/Linux

//and accessing database and/or programs in IBM i server

$extension='ibm_db2';

try {

$ToolkitServiceObj = ToolkitService::getInstance($db, $user, $pass, $extension);

}

catch (Exception $e)

{

echo $e->getMessage(), "\n";

exit();

}

 

$ToolkitServiceObj->setToolkitServiceParams(array('InternalKey'=>"/tmp/$user"));

$code = $_POST ['code'];

$desc = ' ';

 

$param[] = $ToolkitServiceObj->AddParameterChar('both', 10,'CODE', 'CODE', $code);

$param[] = $ToolkitServiceObj->AddParameterChar('both', 10,'DESC', 'DESC', $desc);

$result = $ToolkitServiceObj->PgmCall("COMMONPGM", "ZENDSVR6", $param, null, null);

if($result){

showTable( $result['io_param']);

}

else

echo "Execution failed.";

 

/* Do not use the disconnect() function for "state full" connection */

$ToolkitServiceObj->disconnect();

?>

Program Call (Data Structure Parameters)

<?php

/*

RPG program parameters definition

INCHARA S 1a

INCHARB S 1a

INDEC1 S 7p 4

INDEC2 S 12p 2

INDS1 DS

DSCHARA 1a

DSCHARB 1a

DSDEC1 7p 4

DSDEC2 12p 2

*/

include_once 'authorization.php';

include_once 'ToolkitService.php';

include_once 'helpshow.php';

try {

$ToolkitServiceObj = ToolkitService::getInstance($db, $user, $pass);

}

catch (Exception $e) {

echo $e->getMessage(), "\n";

exit();

}

$ToolkitServiceObj->setToolkitServiceParams(array('InternalKey'=>"/tmp/$user"));

 

$IOParam['var1'] = array("in"=>"Y", "out"=>"" );

$param[] = $ToolkitServiceObj->AddParameterChar('both', 1,'INCHARA', 'var1', $IOParam['var1']['in']);

$IOParam['var2'] = array( "in"=>"Z", "out"=>"" );

$param[] = $ToolkitServiceObj->AddParameterChar('both', 1,'INCHARB', 'var2', $IOParam['var2']['in']);

$IOParam['var3'] = array( "in"=>"001.0001" ,"out"=>"");

$param[] = $ToolkitServiceObj->AddParameterPackDec('both', 7, 4, 'INDEC1', 'var3', '001.0001');

$IOParam['var4'] = array( "in"=>"0000000003.04","out"=>"" );

$param[] = $ToolkitServiceObj->AddParameterPackDec('both',12,2,'INDEC2', 'var4', '0000000003.04');

$IOParam['ds1'] = array( "in"=>"A" ,"out"=>"");

$ds[] = $ToolkitServiceObj->AddParameterChar('both', 1, 'DSCHARA', 'ds1','A');

$IOParam['ds2'] = array( "in"=>"B" ,"out"=>"");

$ds[] = $ToolkitServiceObj->AddParameterChar('both', 1, 'DSCHARB', 'ds2','B');

$IOParam['ds3'] = array( "in"=>"005.0007","out"=>"" );

$ds[] = $ToolkitServiceObj->AddParameterPackDec('both',7, 4, 'DSDEC1', 'ds3', '005.0007' );

$IOParam['ds4'] = array("in"=>"0000000006.08" ,"out"=>"");

$ds[] = $ToolkitServiceObj->AddParameterPackDec('both',12, 2, 'DSDEC1', 'ds4', '0000000006.08');

//$param[] = array('ds'=>$ds);

$param[] = $ToolkitServiceObj->AddDataStruct($ds);

$result = $ToolkitServiceObj->PgmCall('ZZCALL', "ZENDSVR6", $param, null, null);

if($result){

/*update parameters array by return values */

foreach($IOParam as $key=> &$element){

$element['out'] = $result['io_param'][$key];

}

echo "<br>";

showTableWithHeader(array("Parameter name","Input value", "Output value"), $IOParam);

}

else

echo "Execution failed.";

/* Do not use the disconnect() function for "state full" connection */

$ToolkitServiceObj->disconnect();

?>

Service Program Call that Returns Function Value

<?php

/* This program is calling a service program (*SRVPGM) function which retrieves QCCSID system value

*/

include_once 'authorization.php';

include_once 'ToolkitService.php';

try {

$ToolkitServiceObj = ToolkitService::getInstance($db, $user, $pass);

}

catch (Exception $e) {

echo $e->getMessage(), "\n";

exit();

}

$ToolkitServiceObj->setToolkitServiceParams(array('InternalKey'=>"/tmp/$user"));

$SysValueName = "QCCSID";

$Err = ' ';

$SysValue= ' ';

 

$param[] = $ToolkitServiceObj->AddParameterChar('both', 1,'ErrorCode','errcode', $Err);

$param[] = $ToolkitServiceObj->AddParameterChar('both', 10,'SysValName','sysvalname', $SysValueName);

$param[] = $ToolkitServiceObj->AddParameterChar('both', 1024,'SysValue','sysvalue', $SysValue);

$OutputParams = $ToolkitServiceObj->PgmCall('ZSXMLSRV', "ZENDSVR6", $param, NULL, array('func'=>'RTVSYSVAL') );

if( isset($OutputParams['io_param']['sysvalname'])){

echo " System value ".$SysValueName." = ".$OutputParams['io_param']['sysvalue'];

}

else

echo " Operation failed. System value $SysValueName did not retrieve.";

/*change parameter value and execute again PgmCall()*/

ProgramParameter::UpdateParameterValues( $param, array("sysvalname"=>"QLANGID"));

$OutputParams = $ToolkitServiceObj->PgmCall('ZSXMLSRV', "ZENDSVR6", $param, NULL, array('func'=>'RTVSYSVAL') );

if( isset($OutputParams['io_param']['sysvalname'])){

echo " System value ".$SysValueName." = ".$OutputParams['io_param']['sysvalue'];

}

else

echo " Operation failed. System value $SysValueName did not retrieve.";

 

$ToolkitServiceObj->disconnect();

?>