Program Samples

i5 Program Call

The i5 program call process contains the following PHP functions:

  • i5_connect
  • i5_program_prepare
  • i5_program_call
  • i5_close    

The sample PHP script below invokes an i5 program:

<?php

$conn = i5_connect($i5_server_ip, $i5_uname, $i5_pass);

if ($conn === false)

{

   print ("FAIL : Failed to connect to server : $i5_server_ip, with user name : $i5_uname and password : $i5_pass <br>\n");

   $errorTab = i5_error();

   var_dump($errorTab);

   die();

}

/* Prepare File for execution */

$desc = array (

array ("name"=>"code", "io"=>I5_INOUT, "type" => I5_TYPE_CHAR, "length"=> "10"),

array ("name"=>"name", "io"=>I5_INOUT, "type" => I5_TYPE_CHAR, "length"=> "10"),

);

$prog = i5_program_prepare("EACDEMO/TESTSTP2", $desc);

if ($prog === FALSE)

{

   $errorTab = i5_error();

   echo "Program prepare failed <br>\n";

   var_dump($errorTab);

   die();

}

/* Execute Program */

$params = array ("code"=>" ","name"=>" ");

$retvals = array("code"=>"code","name"=>"name");

$ret = i5_program_call($prog, $params, $retvals) ;

echo "The return values are: <br>", "Name: ", $name, "<br> Code: ", $code, "<br>";

if ($ret === FALSE)

{

   $errorTab = i5_error();

   echo "FAIL : i5_program_call failure code <br>";

   var_dump($errorTab);

   die();

}

$close_val = i5_program_close ($prog);

if ($close_val === false )

{

   print ("FAIL : i5_program_close returned fales, closing an open prog.<br>\n");

   $errorTab = i5_error();

   var_dump($errorTab);

}

i5_close($conn) || print ("FAIL : Failed to disconnect from server :$i5_server_ip");

?>

Back to Top

Service Program

<?php

// This program calls a service program (*SRVPGM), which was created using the following i5/OS commands:

// CRTRPGMOD SRCFILE(EACDEMO/QRPGLESRC) SRCMBR(TESTMOD)  

// CRTSRVPGM SRVPGM(EACDEMO/TESTSTRUC2) MODULE(EACDEMO/TESTMOD) EXPORT(*ALL)

$Hdlcon = i5_connect($connect, $user, $pass, array(I5_OPTIONS_JOBNAME => "PHPAIX"));

if (is_bool($Hdlcon) && $Hdlcon == FALSE)

die(i5_errormsg());

echo "Connected!<BR>";

$desc = array (

array ("name"=>"code", "io"=>I5_INOUT, "type" => I5_TYPE_CHAR, "length"=> "10"),

array ("name"=>"name", "io"=>I5_INOUT, "type" => I5_TYPE_CHAR, "length"=> "10"),

);

$ret = $prog = i5_program_prepare("EACDEMO/TESTP2SRV(TESTSTMOD)", $desc);

if (!$ret){

getError(I5_ERR_OK, -1);

} else {

echo "1. Prepare - It works! <br>";

}

$hdlPgm = $ret;

$parameter = array("code"=>" ", "name"=>" ");

$parmOut = array("code"=>"code", "name"=>"name");

$ret = i5_program_call($hdlPgm, $parameter, $parmOut);

if (!$ret){

getError(I5_ERR_OK, -1);

} else {

echo "2. Call - It works! <br>";

}

echo "code : $code<BR> name : $name<BR>";

?>

Back to Top

Data Retrieval

<?php

$Hdlcon = i5_connect($connect, $user, $pass);

if (!$Hdlcon) {

die(i5_errormsg());

}

$HdlFile = i5_open("eacdemo/sp_cust", I5_OPEN_READWRITE, $Hdlcon);

if (!is_bool($HdlFile))

{

echo "It works <br>\n";

}

$fealds = i5_list_fields($HdlFile);

$fetch_array = i5_fetch_array($HdlFile,I5_READ_FIRST);

$fetch_assoc = i5_fetch_assoc($HdlFile,I5_READ_NEXT);

$fetch_object = i5_fetch_object($HdlFile,I5_READ_PREV);

$fetch_row = i5_fetch_row($HdlFile,I5_READ_LAST);

print_r($fetch_array); echo"<br>\n <br>\n";

print_r($fetch_assoc); echo"<br>\n <br>\n";

print_r($fetch_object); echo"<br>\n <br>\n";

print_r($fetch_row); echo"<br>\n <br>\n";

$info = i5_info($HdlFile,1);

print_r($info); echo"<br>\n <br>\n";

$field_length = i5_field_len($HdlFile,1);

$field_name = i5_field_name($HdlFile,1);

$field_type = i5_field_type($HdlFile,1);

$field_scale = i5_field_scale($HdlFile,1);

echo "Field Name: {$field_name} <br>\n Field Lenght: {$field_length} <br>\n Field Type: {$field_type} <br>\n Field Scale: {$field_scale}<br>\n";

$list_fields = i5_list_fields($HdlFile);

print_r($list_fields);

$num_fields = i5_num_fields($HdlFile);

echo "<br>\n {$num_fields}";

$result = i5_result($HdlFile,2);

echo "<br>\n {$result}";

i5_close($Hdlcon);

?>

Back to Top

Native File Access sample

<?php

$conn = i5_connect($connect, $user, $pass);

if ($conn === false) die(i5_errormsg());

$file = i5_open("EACDEMO/SP_CUST", I5_OPEN_READWRITE, $conn);

if ($file === false) die(i5_errormsg());

i5_addnew($file);

i5_setvalue($file,array('11111', 'Kauai', 'Erica', 'Norm', '4-976 Hwy', 'Suite 103', 'Kapaa', 'HI', '94766', 'US', '808-555', '808-555'));

i5_update($file);

i5_edit($file);

i5_delete($file);

i5_cancel_edit($file);

$tabf = array(1500);

i5_range_from($file, FALSE, $tabf);

$tabf = array(1600);

i5_range_to($file, FALSE, $tabf);

$fetch = i5_fetch_row($file, I5_READ_FIRST);

echo $fetch[0], " ",$fetch[1], " ", $fetch[2], "<br>";

$fetch = i5_fetch_row($file, I5_READ_NEXT);

echo $fetch[0], " ",$fetch[1], " ", $fetch[2], "<br>";

i5_range_clear($file);

$fetch = i5_fetch_row($file, I5_READ_FIRST);

echo $fetch[0], " ",$fetch[1], " ", $fetch[2], "<br><br>";

i5_data_seek($file, 2);

$rowTab = i5_fetch_row($file);

echo $rowTab[0], " ",$rowTab[1], " ", $rowTab[2], "<br>";

$tab=array(1510);

$seek = i5_seek($file, "=", $tab);

$rowTab = i5_fetch_row($file);

echo $rowTab[0], " ",$rowTab[1], " ", $rowTab[2], "<br>";

$id = i5_bookmark($file);

echo $id, "<br>";

i5_new_record($file, array('1229', 'Kauai Dive Shoppe ', 'Irica', 'Norman', '4-976 Sugarloaf Hwy', 'Suite 103', 'Kapaa Kauai', 'HI', '94766-1234', 'US', '808-555-0269', '808-555-0278'));

i5_fetch_row($file,I5_READ_FIRST);

i5_update_record($file,array("FIRSTNAME"=>"Lina","LASTNAME"=>"Karasko"));

i5_delete_record($file);

$keys = i5_get_keys($file);

echo $keys;

i5_free_file($file);

?>

Back to Top

Data Queues

Data Queue Without Key

<?php

$conn = i5_connect($i5_server_ip, $i5_uname, $i5_pass);

if (!$conn) {

  die(i5_errormsg());

}

$description = array("Name"=>"DATA", "Type"=>I5_TYPE_CHAR, "Length"=>"50");

$queue = i5_dtaq_prepare("eacdemo/DTAQ_FIFO", $description);

$ret = i5_dtaq_send($queue,"","the dataqueue test data");

var_dump($ret); echo "<br>\n";

if(!$ret)  var_dump(i5_error());

$ret = i5_dtaq_receive($queue);

var_dump($ret);

i5_dtaq_close($queue);

i5_close($conn);

?>

Data Queue With key

<?php

$conn = i5_connect($i5_server_ip, $i5_uname, $i5_pass);

if (!$conn) {

  die(i5_errormsg());

}

$descriptionC = array("DSName"=>"PS", "DSParm"=>array(

array("Name"=>"PS1", "Type"=>I5_TYPE_CHAR, "Length"=>"10"),

array("Name"=>"PS2", "Type"=>I5_TYPE_PACKED, "Length"=>"10.4"),

array("Name"=>"PS3", "Type"=>I5_TYPE_CHAR, "Length"=>"10")

)

);

$dtaqHdl_KEY = i5_dtaq_prepare("EACDEMO/DTAQ_KEY", $descriptionC,10);

var_dump($dtaqHdl_KEY); echo "<br>\n";

$parameter = array("PS1"=>"test1", "PS2"=>13.1415, "PS3"=>"test2");

$key = "abcd";

$ret = i5_dtaq_send($dtaqHdl_KEY, $key, $parameter);

var_dump($ret); echo "<br>\n";

$ret = i5_dtaq_receive($dtaqHdl_KEY, "EQ", $key);

var_dump($ret);

i5_dtaq_close($dtaqHdl_KEY);

i5_close($conn);

?>

Back to Top

System Values

<?php

$conn = i5_connect($i5_server_ip, $i5_uname, $i5_pass);

print "Date is: ".i5_get_system_value("QDATE");

i5_close($conn);

?>

Back to Top

User Spaces

<?php

$conn = i5_connect($connect, $user, $pass);

if (!$Hdlcon) {

die(i5_errormsg());

}

$property = array(

I5_INITSIZE=>10,

I5_DESCRIPTION=>"Created by PHP",

I5_INIT_VALUE=>"A",

I5_EXTEND_ATTRIBUT=>"File",

I5_AUTHORITY=>"*ALL",

I5_LIBNAME=>"EACDEMO",

I5_NAME=>"USERSPACE"

);

$ret = i5_userspace_create($property);

if ($ret) echo "1. It works! <br>\n";

$description = Array(

array("Name"=>"filler0", "IO"=>I5_INOUT, "Type"=>I5_TYPE_CHAR, "Length"=>"64"),

array("Name"=>"generic", "IO"=>I5_INOUT, "Type"=>I5_TYPE_LONG),

array("Name"=>"filler", "IO"=>I5_INOUT, "Type"=>I5_TYPE_CHAR, "Length"=>"36"),

array("Name"=>"outputsize", "IO"=>I5_INOUT, "Type"=>I5_TYPE_LONG),

array("Name"=>"offsetInput", "IO"=>I5_INOUT, "Type"=>I5_TYPE_LONG)

);

 

$parameter = Array(

"filler0"=>"AAAA",

"generic"=>10,

"filler"=>"BBB",

"outputsize"=>100,

"offsetInput"=> 0

);

 

$parmOut = array("filler0"=>"filler0", "filler"=>"filler",

"generic"=>"generic", "outputsize"=>"outputsize",

"offsetInput"=>"offsetInput");

$UspcHdlBad = i5_userspace_prepare("EACDEMO/USERSPACE", $description);

if ($UspcHdlBad) echo "2. It works! <br>\n";

$ret = i5_userspace_put($UspcHdlBad, $parameter);

if ($ret) echo "3. It works! <br>\n";

$ret = i5_userspace_get($UspcHdl, $parmOut);

if (!$ret) echo "4. It works! <br>\n";

if ($ret) echo "5. It works!";

var_dump($ret);*/

$ret = i5_command("DLTUSRSPC USRSPC(EACDEMO/USERSPACE)");

if ($ret) echo "6. It works!";

i5_close($conn);

?>

Back to Top

Active Job List

<?php

$Hdlcon = i5_connect($connect, $user, $pass, array(I5_OPTIONS_JOBNAME => "PHPAIX"));

if (is_bool($Hdlcon) && $Hdlcon == FALSE){

die(i5_errormsg());}

 

echo "i5_job_list: ";

$ret = i5_job_list();

if (!$ret)

die(i5_errormsg());

else

echo "It works!<br>";

 

$listHdl = $ret;

echo 'i5_job_list_read: ';

$ret = i5_job_list_read($listHdl);

if (!$ret)

die(i5_errormsg());

 else

echo "It works! <br>";

 

echo 'i5_job_list_close: ';

$ret = i5_job_list_close($listHdl);

if (!$ret) {

die(i5_errormsg());

} else {

echo "It works! <br>";

}

 

$listHdl = i5_job_list(array(I5_JOBNAME=>"*ALL", I5_JOBTYPE=>"S"));

if (is_bool($listHdl))

die(i5_errormsg());

else

echo "List <BR>";

 

 

$a= 0;

$ret = true;

 

while($ret && $a < 3){

echo "<p>Message $a<BR>";

$ret = i5_job_list_read($listHdl);

$a ++;

if (is_bool($ret))

die(i5_errormsg());

else

{

print_r($ret);echo "<p>";

echo "Job queueA simple and manageable system for off-loading tasks from the synchronous user request, to an external, parallel PHP process. Name : " . $ret[I5_JOB_QUEUE_NAME] . ", Response Id : " . $ret[I5_JOB_PROCESS_ID] . "
";

echo "I5_JOB_JOBMSGQFL : " . $ret[I5_JOB_JOBMSGQFL] . "<BR>";

}

}

$ret = i5_job_list_close($listHdl);

?>

Back to Top

Job Log List

<?php

$Hdlcon = i5_connect($connect, $user, $pass, array(I5_OPTIONS_JOBNAME => "PHPAIX"));

if (is_bool($Hdlcon) && $Hdlcon == FALSE){

die(i5_errormsg());}

 

$listHdl = i5_jobLog_list();

if (is_bool($listHdl))

die(i5_errormsg());

 else

echo "List<BR>";

 

$a= 0;

$ret = true;

 

while($ret && $a < 2){

echo "Message $a<BR>";

$ret = i5_jobLog_list_read($listHdl);

$a ++;

if (is_bool($ret))

die(i5_errormsg());

else

{

print_r($ret);echo "<p>";

echo "Message : " . $ret[I5_LOBJ_MSG]. ",<BR> data : ". $ret[I5_LOBJ_MSGDTA] . "<BR>";

}

}

$ret = i5_jobLog_list_close($listHdl);

if (is_bool($ret))

die(i5_errormsg());

 else {

print_r($ret);echo "<p>";

echo "Message : " . $ret[I5_LOBJ_MSG]. ",<BR> data : ". $ret[I5_LOBJ_MSGDTA] . "<BR>";

?>

Back to Top

Data Areas

<?php

$Hdlcon = i5_connect($connect, $user, $pass);

if (!$Hdlcon) {

die(i5_errormsg());

}

$ret = i5_data_area_create("eacdemo/MYDTA", "50");

if ($ret) echo "1.It works! <br>";

$ret = i5_data_area_write("eacdemo/MYDTA", "coucou");

if ($ret) echo "3.It works! <br>";

$ret = i5_data_area_read("eacdemo/MYDTA", 2, 4);

if ($ret) echo "4.It works!: ", $ret, "<br>";

$ret = i5_data_area_read("eacdemo/MYDTA");

if ($ret) echo "5.It works!: ", $ret, "<br>";

$ret = i5_data_area_write("eacdemo/MYDTA", "lina", 5, 45);

if ($ret) echo "6.It works! <br>";

$ret = i5_data_area_read("eacdemo/MYDTA", 1, 5);

if ($ret) echo "7.It works!: ", $ret, "<br>";

$ret = i5_data_area_read("eacdemo/MYDTA");

if ($ret) echo "8.It works!: ", $ret, "<br>";

$ret = i5_data_area_delete("eacdemo/MYDTA");

if ($ret) echo "9.It works! <br>";

?>

Back to Top

Spooled Files

<?php

$conn = i5_connect($connect, $user, $pass);

if (!$conn) die("<br>Connect fail");

echo "<br>================<br>";

echo "<br>connected.";

$spool = i5_spool_list(array("username"=>"lina"),$conn);

if ($spool)

{

$count = 0;

while (($a = i5_spool_list_read($spool)) && ($count <= 2))

{

        echo "<br>================<br>";

        var_dump($a);

        echo "<br>data {$count}:<br>";

        $data = i5_spool_get_data($a['SPLFNAME'], $a['JOBNAME'],

                              $a['USERNAME'], $a['JOBNBR'],  

                              $a['SPLFNBR']);

       if (is_bool($data)) var_dump(i5_error());

       var_dump($data);

       $count++;

   }

  

   i5_spool_list_close($spool);

}

else echo "No spool today.";

i5_close($conn);

XII. Object Listing

$conn = i5_connect($connect, $user, $pass);

if (!$conn) die("<br>Connect fail");

echo "<br>================<br>";

echo "<br>connected. <br>";

$objects = i5_objects_list("EACDEMO", "*ALL", "*PGM");

if ($objects) echo "1.It works! <br>";

$HdlObj = $objects;

$objects = i5_objects_list_read($HdlObj);

if (!is_bool($objects))

{

   echo "2.It works! <br>";

   print_r($objects); echo "<br>";

}

$continue = true;

$count = 0;

while($continue)

{

$objects = i5_objects_list_read($HdlObj);

if (is_bool($objects) && $objects == FALSE )

$continue = false;

else

{

   echo "3.It works! <br>";

   print_r($objects); echo "<br>";

}

$count ++;

if ($count == 2) break;

}

$objects = i5_objects_list_close($HdlObj);

if (is_bool($objects) && $objects == FALSE)

   $continue = false;

else

   echo "4.It works! <br>";

?>

Back to Top

PCML Program Call - PCML Description Used in the PHP Program

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">

<html>

<head>

<title>Program call example using PCML</title>

<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">

<link href="style.css" rel="stylesheet" type="text/css">

<link rel="shortcut icon" type="image/x-icon" href="favicon.ico">

</head>

<body>

<?php

include("conn.php");

/* connection step  */

$Hdlcon = i5_connect($connect,$user, $pass, array(I5_OPTIONS_JOBNAME=>"I5JOB"));

// This is the PCML taken from the following i5/OS command:

// CRTRPGMOD SRCFILE(EACDEMO/QRPGLESRC) SRCMBR(TESTSTRUC)  PGMINFO(*PCML) INFOSTMF('/tmp/teststruc.pcml')

// we only defined some parameters as "output" to have minimal network load

// we also changed the program name tag to specify the "path" value for the program

// we also replace " with \" to have a correct PHP syntax. We also could load it from the IFS.

$description = "<pcml version=\"4.0\">                                                                

   <!-- RPG module: TESTSTRUC  -->                                                  

   <!-- created: 2006-10-12-11.46.56 -->                                            

   <!-- source: EACDEMO/QRPGLESRC(TESTSTRUC) -->                                    

   <!-- 5 -->                                                                       

   <struct name=\"S2\">                                                               

      <data name=\"ZOND2\" type=\"zoned\" length=\"10\" precision=\"5\" usage=\"inherit\" />  

      <data name=\"PACK2\" type=\"packed\" length=\"19\" precision=\"5\" usage=\"inherit\" />

      <data name=\"PACK3\" type=\"packed\" length=\"19\" precision=\"5\" usage=\"inherit\" />

      <data name=\"ALPH2\" type=\"char\" length=\"20\" usage=\"inherit\" />                 

   </struct>                                                                        

   <!-- 1 -->                                                                       

   <struct name=\"S1\">                                                               

      <data name=\"ZOND\" type=\"zoned\" length=\"10\" precision=\"5\" usage=\"inherit\" />   

      <data name=\"PACK1\" type=\"packed\" length=\"19\" precision=\"5\" usage=\"inherit\" />

      <data name=\"ALPH1\" type=\"char\" length=\"10\" usage=\"inherit\" />                 

   </struct>                                                                        

   <program name=\"TESTSTRUC\" path=\"/QSYS.LIB/EACDEMO.LIB/TESTSTRUC.PGM\">   

      <data name=\"CODE\" type=\"char\" length=\"10\" usage=\"output\" />                  

      <data name=\"S1\" type=\"struct\" struct=\"S1\" usage=\"inputoutput\" />                  

      <data name=\"S2\" type=\"struct\" struct=\"S2\" usage=\"inputoutput\" />                  

      <data name=\"PACK\" type=\"packed\" length=\"1\" precision=\"1\" usage=\"output\" />   

      <data name=\"CH10\" type=\"char\" length=\"19\" usage=\"output\" />                  

      <data name=\"CH11\" type=\"char\" length=\"20\" usage=\"output\" />                  

      <data name=\"CH12\" type=\"char\" length=\"29\" usage=\"output\" />                  

      <data name=\"CH13\" type=\"char\" length=\"33\" usage=\"output\" />                  

   </program>                                                                           

</pcml>                                                                                 

   ";

// define some input values

$pack3value=7789777.44;

$alph2value=4;

// now, prepare the program (only pcml parsing at this stage)

($hdlPgm = i5_program_prepare_PCML($description))

or trigger_error("Error while parsing PCML: " . i5_errormsg(), E_USER_ERROR);

// let's define some input values

$in_parameters = Array(

"S1"=>Array("ZOND"=>54.77, "PACK1"=>16.2, "ALPH1"=>"MyValue"),

"S2"=>Array("ZOND2"=>44.66, "PACK2"=>24444.99945, "PACK3"=>$pack3value, "ALPH2"=>$alph2value)

);

// now we need to define where to place output values; it will create new local variables

$out_parameters = array(

"S1"=>"S1_Value", "S2"=>"S2_Value",

"CH10"=>"CH10_Value", "CH11"=>"CH11_Value", "CH12"=>"CH12_Value", "CH13"=>"CH13_Value",

"CODE"=>"Code_Value", "PACK"=>"Pack"

);

// the call is made here

i5_program_call($hdlPgm, $in_parameters, $out_parameters)

or trigger_error("Error while executing program: " . i5_errormsg(), E_USER_ERROR);

// all variables are now filled with program results.

echo "<br>S1:"; var_dump($S1_Value);

echo "<br>S2:"; var_dump($S2_Value);

echo "<br>CH10:"; var_dump($CH10_Value);

echo "<br>CH11:"; var_dump($CH11_Value);

echo "<br>CH12:"; var_dump($CH12_Value);

echo "<br>CH13:"; var_dump($CH13_Value);

echo "<br>Code:"; var_dump($Code_Value);

echo "<br>Pack:"; var_dump($Pack);

 

?>

</body>

</html>

Back to Top

PCML Program Call 2 - PCML File External to PHP Program

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">

<html>

<head>

<title>Program call example using PCML</title>

<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">

<link href="style.css" rel="stylesheet" type="text/css">

<link rel="shortcut icon" type="image/x-icon" href="favicon.ico">

</head>

<body>

<?php

include("conn.php");

/* connection step  */

$Hdlcon = i5_connect($connect,$user, $pass, array(I5_OPTIONS_JOBNAME=>"I5JOB"));

// This is the PCML taken from the following i5/OS command:

// CRTRPGMOD SRCFILE(EACDEMO/QRPGLESRC) SRCMBR(TESTSTRUC)  PGMINFO(*PCML) INFOSTMF('/tmp/teststruc.pcml')

// we only defined some parameters as "output" to have minimal network load

// we also changed the program name tag to specify the "path" value for the program

// we also replace " with \" to have a correct PHP syntax. We also could load it from the IFS.

// the PCML file is located in the same location as the PHP program

($description = file_get_contents("/www/zendcore/htdocs/teststruc.pcml"))

or trigger_error("Error while opening PCML file", E_USER_ERROR);

// define some input values

$pack3value=7789777.44;

$alph2value=4;

// now, prepare the program (only pcml parsing at this stage)

($hdlPgm = i5_program_prepare_PCML($description))

 or trigger_error("Error while parsing PCML: " . i5_errormsg(), E_USER_ERROR);

// let's define some input values

$in_parameters = Array(

"S1"=>Array("ZOND"=>54.77, "PACK1"=>16.2, "ALPH1"=>"MyValue"),

"S2"=>Array("ZOND2"=>44.66, "PACK2"=>24444.99945, "PACK3"=>$pack3value, "ALPH2"=>$alph2value)

);

// now we need to define where to place output values; it will create new local variables

$out_parameters = array(

"S1"=>"S1_Value", "S2"=>"S2_Value",

"CH10"=>"CH10_Value", "CH11"=>"CH11_Value", "CH12"=>"CH12_Value", "CH13"=>"CH13_Value",

"CODE"=>"Code_Value", "PACK"=>"Pack"

);

// the call is made here

i5_program_call($hdlPgm, $in_parameters, $out_parameters)

or trigger_error("Error while executing program: " . i5_errormsg(), E_USER_ERROR);

// all variables are now filled with program results.

echo "<br>S1:"; var_dump($S1_Value);

echo "<br>S2:"; var_dump($S2_Value);

echo "<br>CH10:"; var_dump($CH10_Value);

echo "<br>CH11:"; var_dump($CH11_Value);

echo "<br>CH12:"; var_dump($CH12_Value);

echo "<br>CH13:"; var_dump($CH13_Value);

echo "<br>Code:"; var_dump($Code_Value);

echo "<br>Pack:"; var_dump($Pack);

 

?>

</body>

</html>

Back to Top

List of an RPG Program, "TESTSTRUC", Called by the PCML Sample Programs  

D S1              DS

     D  ZOND                   1     10S 5

     D  pack1                  11    20P 5

     D  alph1                  21    30

     D S2              DS

     D  ZOND2                  1     10S 5

     D  pack2                  11    20P 5

     D  pack3                  21    30P 5

     D  alph2                  31    50

     D                SDS

     D  $PGM                    1      10

     D  $LIB                    81     90

     D  $JOB                    244   253

     D  $USER                   254   263

     D  $JOBNM                  264   269

     D INFDS           DS

     D  KEY                     369   369

     D  PAGRRN                  378   379B 0

     D*

     D F03             C                   CONST(X'33')

     C*-------------------------------------------------------------------

  ******************

     C     *ENTRY        PLIST

     C                   PARM                    CODE            10

     C                   PARM                    S1

     C                   PARM                    S2

     C                   PARM                    PACK              1 1

     C                   PARM                    ch10             19

     C                   PARM                    ch11             20

     C                   PARM                    ch12             29

     C                   PARM                    ch13             33

     **********************

     C                   MOVEL     'HELLO'       CODE

     C                   Z-SUB     0.5           PACK

     C                   eval      ch10 = *all'A'

     C                   eval      ch11 = *all'B'

     C                   eval      ch12 = *all'ZX'

     C                   eval      ch13 = *all'5'

     C                   eval      ZOND = 0 - zond

     C                   eval      pack1 = 0 - pack1

     C                   eval      alph1 ='alph1'

     C                   - service side eval      ZOND2 = 0 - zond2

     C                   eval      pack2 = 0-pack2

     C                   eval      pack3 =0 - pack3

     C                   eval      alph2 ='alph2'

     C*

     C                   SETON                                        LR

     C                   RETURN

Back to Top

Web Services

<?php

/*

This service invokes a RPG program with two parameters

*/

class i5_program_service {

 

private $conn = false;

function __construct() {

    

        $this->conn = i5_connect('127.0.0.1', 'user', 'password'/*, $connection_parameters*/);

        if (!is_resource($this->conn)) {

     throw new SoapFault('i5_program_service', 'Connection to i5 server failed, use i5_errormsg() to get the failure reason');

    }

 

}

 

public function service_for_i5_program($var_0, $var_1) {

        $description = Array (

        array ('Name' => 'code', 'IO' => I5_INOUT, 'Type' => I5_TYPE_CHAR, 'Length' => '10'),

        array ('Name' => 'name', 'IO' => I5_INOUT, 'Type' => I5_TYPE_CHAR, 'Length' => '10'));

    

        $prog = i5_program_prepare('eacdemo/teststp2', $description, $this->conn);

        if (is_resource($prog)) {   

    

         /* Execute Program */

            $params = array (

            'code' => $var_0, 'name' => $var_1);

           

            $retvals = array(

            'code' => 'ret_val_1', 'name' => 'ret_val_2');

            $ret = i5_program_call($prog, $params, $retvals) ;

            if ($ret === true) {

                 $ret = array($ret_val_1, $ret_val_2);

                 return $ret;

            }

            

            else {

                throw new SoapFault('i5_program_service', 'Failed to call the program, use i5_errormsg() to get the failure reason');

            }

                

            if (!i5_program_close ($prog) ) {

                 throw new SoapFault('i5_program_service', 'Failed to free program resource handle, use i5_errormsg() to get the failure reason');

            }  

        }

      

        else {

            throw new SoapFault('i5_program_service', 'Program prepare failed, use i5_errormsg() to get the failure reason');      

        }   

}

    function __destruct() {

    

    if (!i5_close($this->conn)) {

            // Failed to disconnect from i5 server, use i5_errormsg() to get the failure reason

        }

    }

}

ini_set('soap.wsdl_cache_enabled', '0');

$server = new SoapServer('zend.wsdl');

$server->setClass('i5_program_service');

$server->handle();

?>

Web Services - Client Side

<?php

/*

This client calls the above service using ’r;zend.wsdl’ XML file generated by the WSDL Wizard in the Zend Studio.

/*

ini_set('soap.wsdl_cache_enabled', '0');

$my_client =  new SoapClient('zend.wsdl');

try{

var_dump($my_client->service_for_i5_program('111', ' '));    

} catch (SoapFault $exception) {

    echo $exception;       

  }       

                                    

?