cancel
Showing results for 
Search instead for 
Did you mean: 

How does execute PHP Script from SAP?

Former Member
0 Kudos

I've already installed SAPRFC and run SAP Function from PHP successfully. But failed when tried execute PHP script from SAP (SM59). Anyone can help me for a clear instruction for this problem?

Thanks

View Entire Topic
gregorw
Active Contributor
0 Kudos

Hi Budi,

do you want to try out the server.php coming with SAPRFC? I've tried it but had also no sucess.

Regards

Gregor

Former Member
0 Kudos

Yes, Gregor. I've tried server.php, but failed.

Former Member
0 Kudos

When you say fail, what do you mena it did not run?

gregorw
Active Contributor
0 Kudos

Hi Craig,

when I run:

./server.php -a phpgw -g localhost -x sapgw00

I got this error:

Fatal error: Call to undefined function: saprfc_function_define() in /var/www/saprfc/server.php on line 76

Regards

Gregor

Former Member
0 Kudos

That I have not seen, nor can I seem to duplicate it?

maximilian_schaufler
Active Contributor
0 Kudos

I don't have the php files available for research at the moment, but based on my PHP experience this does sound like there is a missing or a wrong include command ... are there any files included within server.php? I guess there are, make sure you check these commands so that all the necessary functions from sub-files become available in the main file.

Greets,

Max

gregorw
Active Contributor
0 Kudos

Hi Max,

here is the Source:

[code]

#!/usr/bin/php -q

<?php

// -


// SAPRFC - Server example

// PHP server function RFC_READ_REPORT

// Require: CGI version PHP, RFC destination defined in SAP R/3 (SM59)

// http://saprfc.sourceforge.net

// -


// Interface definiton for RFC_READ_REPORT

// (generated by saprfc.php - option Generate PHP)

$DEF_RFC_READ_REPORT = array (

array (

"name"=>"SYSTEM",

"type"=>"EXPORT",

"optional"=>"0",

"def"=> array (

array ("name"=>"","abap"=>"C","len"=>8,"dec"=>0)

)

),

array (

"name"=>"TRDIR",

"type"=>"EXPORT",

"optional"=>"0",

"def"=> array (

array ("name"=>"NAME","abap"=>"C","len"=>40,"dec"=>0),

array ("name"=>"SQLX","abap"=>"C","len"=>1,"dec"=>0),

array ("name"=>"EDTX","abap"=>"C","len"=>1,"dec"=>0),

array ("name"=>"VARCL","abap"=>"C","len"=>1,"dec"=>0),

array ("name"=>"DBAPL","abap"=>"C","len"=>1,"dec"=>0),

array ("name"=>"DBNA","abap"=>"C","len"=>2,"dec"=>0),

array ("name"=>"CLAS","abap"=>"C","len"=>4,"dec"=>0),

array ("name"=>"TYPE","abap"=>"C","len"=>3,"dec"=>0),

array ("name"=>"OCCURS","abap"=>"C","len"=>1,"dec"=>0),

array ("name"=>"SUBC","abap"=>"C","len"=>1,"dec"=>0),

array ("name"=>"APPL","abap"=>"C","len"=>1,"dec"=>0),

array ("name"=>"SECU","abap"=>"C","len"=>8,"dec"=>0),

array ("name"=>"CNAM","abap"=>"C","len"=>12,"dec"=>0),

array ("name"=>"CDAT","abap"=>"D","len"=>8,"dec"=>0),

array ("name"=>"UNAM","abap"=>"C","len"=>12,"dec"=>0),

array ("name"=>"UDAT","abap"=>"D","len"=>8,"dec"=>0),

array ("name"=>"VERN","abap"=>"C","len"=>6,"dec"=>0),

array ("name"=>"LEVL","abap"=>"C","len"=>4,"dec"=>0),

array ("name"=>"RSTAT","abap"=>"C","len"=>1,"dec"=>0),

array ("name"=>"RMAND","abap"=>"C","len"=>3,"dec"=>0),

array ("name"=>"RLOAD","abap"=>"C","len"=>1,"dec"=>0),

array ("name"=>"FIXPT","abap"=>"C","len"=>1,"dec"=>0),

array ("name"=>"SSET","abap"=>"C","len"=>1,"dec"=>0),

array ("name"=>"SDATE","abap"=>"D","len"=>8,"dec"=>0),

array ("name"=>"STIME","abap"=>"C","len"=>6,"dec"=>0),

array ("name"=>"IDATE","abap"=>"D","len"=>8,"dec"=>0),

array ("name"=>"ITIME","abap"=>"C","len"=>6,"dec"=>0),

array ("name"=>"LDBNAME","abap"=>"C","len"=>20,"dec"=>0)

)

),

array (

"name"=>"PROGRAM",

"type"=>"IMPORT",

"optional"=>"0",

"def"=> array (

array ("name"=>"","abap"=>"C","len"=>40,"dec"=>0)

)

),

array (

"name"=>"QTAB",

"type"=>"TABLE",

"optional"=>"0",

"def"=> array (

array ("name"=>"LINE","abap"=>"C","len"=>72,"dec"=>0)

)

)

);

// Create list of PHP server functions

$GLOBAL_FCE_LIST[RFC_READ_REPORT] = saprfc_function_define(0,"RFC_READ_REPORT",$DEF_RFC_READ_REPORT);

// PHP server function

function RFC_READ_REPORT ($fce)

{

$REPORT = saprfc_server_import ($fce,"PROGRAM");

saprfc_table_init ($fce,"QTAB");

$fd = fopen ($REPORT,"r");

if (!$fd)

return ("NOTFOUND"); // raise exception "NOTFOUND"

while (!feof($fd))

{

$LINE = fgets ($fd,73);

saprfc_table_append ($fce,"QTAB",array("LINE"=>$LINE));

}

fclose ($fd);

saprfc_server_export ($fce,"SYSTEM","PHP");

return (true);

}

// Call script with: ./server.php -a phpgw -g hostname -x sapgw00

$rfc = saprfc_server_accept ($argv);

// Dispatch one function call

$rc = saprfc_server_dispatch ($rfc,$GLOBAL_FCE_LIST);

saprfc_close ($rfc);

?>

[/code]

Regards

Gregor

Message was edited by: Gregor Wolf

maximilian_schaufler
Active Contributor
0 Kudos

I don't see any definition of the function saprfc_function_define() within this file, and there is no included file.

Maybe there is some missing PHP configuration entry that is required in order for SAPRFC to work (in order to use the functions without having to include certain files manually all the time). Can you check the docu on that?

gregorw
Active Contributor
0 Kudos

Hi Max,

I have found the problem on my system. The PHP4 Command Line Interface (CLI) has a different php.ini file. It is located at /etc/php4/cli/php.ini. I had to add the line:

extension=saprfc.so

to activate saprfc also for CLI. The function saprfc_function_define is part of the extention and <a href="http://saprfc.sourceforge.net/src/saprfc.html#function.saprfc-function-define.html">well documented</a>.

Regards

Gregor

maximilian_schaufler
Active Contributor
0 Kudos

Expected something like this ...

thx Gregor, nice collaborative effort