Error in calling service program module that returns a value

Error in calling service program module that returns a value

Postby kenberg on Wed Jan 16, 2013 6:26 pm

I have spent hours looking for an answer to what I am doing wrong with no luck. Probably searching wrong.

I have created a test program that receives two 10 byte char fields, and in the procedure returns a 20 byte field that concatenates the two input fields together (original huh). I have tested on the iSeries and it works as designed.

I have the following code

Code: Select all
include_once 'ToolkitService.php';

try {
   $ToolkitServiceObj  = ToolkitService::getInstance('SYSTEMNANME', 'USERID', 'PASSWORD');
}
catch (Exception $e) {
   echo  $e->getMessage(), "\n";
   exit();
}

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


$param[] = $ToolkitServiceObj->AddParameterChar('both', 10,'Parameter1','parm1', 'Ken');
$param[] = $ToolkitServiceObj->AddParameterChar('both', 10,'Parameter2','parm2', 'Berg');

$OutputParams = $ToolkitServiceObj->PgmCall('SP_MODWR', "KEN", $param, NULL, array('func'=>'MODWRETURN') );

echo 'Output Parameters: '.$OutputParams;


The RPGLE module code is very simple

Code: Select all
H NoMain                                                         
                                                                 
// prototype for pgmwentry                                     
D ModWReturn      PR            20                               
D Parm1                         10                               
D Parm2                         10                               
*----------------------------------------------------           
P ModWReturn      B                   EXPORT                     
// *entry interface for main procedure                         
D ModWReturn      PI            20                               
D Parm1                         10                               
D Parm2                         10                               
                                                                 
// stand alone values                                           
D ReturnVal       S             20                               
                                                                 
/Free                                                           
  returnVal = parm1 + parm2;                                     
  *INLR = *ON;                                                   

  return returnVal;                 
                                   
/End-Free                         
P  ModWReturn     E                 
                                   



When I run this in debug I get into the program on the iSeries, see both input variables, see the combining of the values and show that I return it (saw this debugging in an iSeries program as well). At this point though I see the error "Pointer not set for location referenced. " in the XTOOLKIT job that is running under my profile.

The documentation shows that the 4th parm for the PgmCall function is the return value. I have tried to put a variable in this rather than NULL both as an array, and just a variable with no luck either.

Hope someone has seen this before. One of the things about the Toolkit that has exited me was the ability to call functions and receive back values other than integers.
kenberg
 
Posts: 10
Joined: Sun Jan 03, 2010 8:12 pm

Re: Error in calling service program module that returns a v

Postby aseiden on Sat Jan 19, 2013 1:29 am

Hi, Ken,

This functionality--getting return values from RPG procedures--has been vastly improved (you might say corrected) in the latest toolkit version (PHP Toolkit 1.4.0).

This update is available as a PTF from the Zend Server for IBM i download page (http://www.zend.com/en/products/server/downloads and click IBM i tab) and is listed as "XML Toolkit for IBM i update 12.12."

I recently wrote a short tutorial on the topic:
http://www.alanseiden.com/2012/12/27/se ... for-ibm-i/

The important part for you begins in the second half where the parameters get defined.

Please try it and let us know how it goes for you.

Alan Seiden
Toolkit co-developer
aseiden
 
Posts: 823
Joined: Thu Apr 09, 2009 5:45 pm

Re: Error in calling service program module that returns a v

Postby kenberg on Mon Jan 21, 2013 5:53 pm

Thank you so much Alan. Applying the PTF's solved the problem. I had the correct process at some point as to getting the information from the return but it was not working due to the version of the toolkit being used.

With that said I also worked with your article and very well done and excellent boilerplate for our future use. Thanks for all you do for the IBM i community.
kenberg
 
Posts: 10
Joined: Sun Jan 03, 2010 8:12 pm

Re: Error in calling service program module that returns a v

Postby kenberg on Mon Jan 21, 2013 11:28 pm

Alan,

One more item on this. My first test was with a single char field being returned and this had no problems. Documentation says I can return a DS. My procedure returns the contents of a files entire record format. Of course has many fields some of which are packed. When I get the data back I see not errors on the call but get no data back. How should this be handled.

I have a parm defined as

$retParam[] = $ToolkitServiceObj->AddParameterChar('out', 417, 'CashDebitReturn','CASHDEBITRETURN' ,' ');

I try to look at the value but see nothing.

I looked at the log and see (just last couple of lines):

<parm comment='DebitAmount'>
<data var='DebitAmount' type='11p6'><![CDATA[2.560000]]></data>
</parm>
<return io='out' comment='CashDebitReturn'>
<data var='CASHDEBITRETURN' type='417A'><![CDATA[
Exec end: 2013-01-21 14:15:41. Seconds to execute: 0.060694932937622.

If the DebitAmount field shows what it does I would expect the CASHDEBITRETURN field to contain something and it looks like it is stopping during the loading of the field.

Could there still be a problem in the toolkit or am I doing something wrong?
kenberg
 
Posts: 10
Joined: Sun Jan 03, 2010 8:12 pm

Re: Error in calling service program module that returns a v

Postby aseiden on Wed Jan 23, 2013 1:06 am

Hi, Ken,

If the return value is not actually a character field, but a data structure that contains packed fields, then you'll need to define it that way.

See this forum posting for an example of defining a data structure containing packed fields:
viewtopic.php?f=113&t=106488

The difference here is that $retParam[] would get the data structure:
$ds[] = ....
$ds[] = ....

and then

$retParam[] = $ToolkitServiceObj->addDataStruct($ds, 'myNiceDataStruct'); // (I prefer the name $conn but $ToolkitServiceObj is fine, too)

and then you call the program as you showed.

--Alan
aseiden
 
Posts: 823
Joined: Thu Apr 09, 2009 5:45 pm

Re: Error in calling service program module that returns a v

Postby kenberg on Thu Jan 24, 2013 9:22 pm

Alan,

I have followed the coding style for the return values that you have given in conjunction on how you showed in the other forum article you refer to above.

By doing this process I am not getting valid values from my service program procedure through a returned data structure.

Thank you so much for your help.
kenberg
 
Posts: 10
Joined: Sun Jan 03, 2010 8:12 pm

Re: Error in calling service program module that returns a v

Postby aseiden on Fri Jan 25, 2013 10:56 pm

Ken,

Please provide some additional information and I will check it out.

1. Set debug=true in toolkit.ini, run your test again, and then post the relevant section of the debug log here on the forum.

2. Post the relevant section of PHP code where you defined the return data structure.

--Alan
aseiden
 
Posts: 823
Joined: Thu Apr 09, 2009 5:45 pm


Return to New Toolkit

Who is online

Users browsing this forum: No registered users and 1 guest