Monday, March 16, 2009

Integrating SAP NetWeaver in Zero PHP

I've been playing with the Big Daddy of enterprise systems, SAP

I thought it would be interesting to hook up a Zero PHP application with a SAP NetWeaver system. So last weekend I summoned up the courage and, armed with a bottle of red wine, set about the task. Surprisingly enough it wasn't too difficult (setting aside finding 20GB of disk space needed by the installer).

The bit I was interested in was the SAP Java connector. SAP Java Connector (SAP JCo) is a middleware component that enables the development of SAP-compatible components and applications in Java. Since we have a PHP/Java Bridge in Zero I thought it should be possible to wire them up.

Here is an example that invokes a SAP remote function call (RFC):

try {

java_import("", NULL, FALSE, NULL, FALSE);
// Establish the client connection to SAP
  $connection = JCO::createClient("000", "bcuser", 
  "minisap", null, "localhost", "00");
$repository = JCO::createRepository("ZeroRepository", $connection);
  $template = $repository->getFunctionTemplate("RFC_SYSTEM_INFO");
  $function = new Java("", $template);
$list = $function->getExportParameterList();
  $structure = $list->getStructure("RFCSI_EXPORT");

$iterator = $structure->fields();
  while ($iterator->hasMoreElements()) {
  $field = $iterator->nextField();
  echo $field->getName()." : ".$field->getString()."\n";

} catch (Exception $exception) {
echo $exception->getMessage();

The code turns out to be pretty straightforward. In a production environment it would be better to use some of the connection pooling options to avoid the repetitive connect/disconnect overhead. The function RFC_SYSTEM_INFO doesn't require any arguments but those can be passed as well if required.

If anyone is interested in SAP there is an un-conference event being organised by Nigel James and Zoe Slattery on Saturday 4th April. More details here (beware the SAP/SDN sites do not work in Google Chrome). I am planning to be there to chat about Zero/Java/PHP with SAP NetWeaver.

No comments:

Post a Comment