2017 © Pedro Peláez
 

library saprfc

Saprfc abstraction layer

image

cti/saprfc

Saprfc abstraction layer

  • Wednesday, April 9, 2014
  • by nekufa
  • Repository
  • 3 Watchers
  • 1 Stars
  • 197 Installations
  • PHP
  • 0 Dependents
  • 1 Suggesters
  • 2 Forks
  • 0 Open issues
  • 4 Versions
  • 13 % Grown

The README.md

SapRfc library

Latest Stable Version Total Downloads License Build Status Coverage Status, (*1)

This component is wrapper for native saprfc extension (saprfc.sourceforge.net).
Function module reverse-engeneering and providing only one method to do all tasks.
You can write your code using GatewayInterface and then use proxy or direct connection., (*2)

Installation

Using composer., (*3)

{
    "require": {
        "cti/saprfc": "*"    
    }
}

Basic usage

Server has saprfc extension and can connect to SAP R/3 (same network)., (*4)

<?php

use Cti\SapRfc\Gateway;

// params for saprfc_open
// http://saprfc.sourceforge.net/src/saprfc.html#function.saprfc-open.html
$connectionParams = array(
    'USER' => 'USERNAME',
    'PASSWD' => 'PASSWORD',
    // ...
);

$sap = new Gateway($connectionParams);

$request = array(
    // use import params
    'I_ID_USER' => 12345,
    'I_LIMIT' => 50,
    'I_OFFSET' => 25,

    // fill tables
    'IT_FILTER' => array(
        array('FIELD' => 'STATUS', 'VALUE' => 'ACTIVE')
    )
);

$response = array(
    // use export params
    'TOTAL_CNT', 'LAST_UPDATE', 

    // use table result
    'IT_RECIPE_LIST'
);


$result = $sap->execute('Z_GET_RECIPE_LIST', $request, $response);

// $result contains properties TOTAL_CNT, LAST_UPDATE, IT_RECIPE_LIST.
// TOTAL_CNT and LAST_UPDATE are scalar values
// IT_RECIPE_LIST is array of data
// 
echo $result->TOTAL_CNT; 

foreach($result->IT_RECIPE_LIST as $recipe) {
    echo $recipe->ID_RECIPE, ' ', $recipe->name, '<br/>';
}

Proxy usage

Sap rfc library can be used in proxy mode. For example: - first server is in intranet and it can connect to Sap R/3 - second server has vpn connection to first server and has no saprfc extension, (*5)

First server proxy.php file:, (*6)

<?php

use Cti\SapRfc\Gateway;
use Cti\SapRfc\Proxy;

// params for saprfc_open
// http://saprfc.sourceforge.net/src/saprfc.html#function.saprfc-open.html
$connectionParams = array(
    'USER' => 'USERNAME',
    'PASSWD' => 'PASSWORD',
    // ...
);

$sap = new Gateway($connectionParams);

$proxy = new Proxy();
$proxy->processRequest($sap);

Second server request.php file:, (*7)

<?php

use Cti\SapRfc\Proxy;

$request = array(
    // use import params
    'I_ID_USER' => 12345,
    'I_LIMIT' => 50,
    'I_OFFSET' => 25,

    // fill tables
    'IT_FILTER' => array(
        array('FIELD' => 'STATUS', 'VALUE' => 'ACTIVE')
    )
);

$response = array(
    // use export params
    'TOTAL_CNT', 'LAST_UPDATE', 

    // use table result
    'IT_RECIPE_LIST'
);


$proxy = new Proxy();
$proxy->setUrl("http://intranet_server_url/proxy.php");

$result = $proxy->execute('Z_GET_RECIPE_LIST', $request, $response);

// $result contains properties TOTAL_CNT, LAST_UPDATE, IT_RECIPE_LIST.
// TOTAL_CNT and LAST_UPDATE are scalar values
// IT_RECIPE_LIST is array of data
// 
echo $result->TOTAL_CNT; 

foreach($result->IT_RECIPE_LIST as $recipe) {
    echo $recipe->ID_RECIPE, ' ', $recipe->name, '<br/>';
}

Profiling your requests

Gateway interface provides profiler injection.
With this object you can analyze your call, time and memory usage., (*8)

<?php

use Cti\SapRfc\Gateway;
use Cti\SapRfc\Profiler;

// params for saprfc_open
// http://saprfc.sourceforge.net/src/saprfc.html#function.saprfc-open.html
$connectionParams = array(
    'USER' => 'USERNAME',
    'PASSWD' => 'PASSWORD',
    // ...
);

$sap = new Gateway($connectionParams);

$sap->setProfiler(new Profiler());

$name = 'FUNCTIONAL_MODULE_NAME';

$request = array(
    // ...
);

$response = array(
    // ...
);

$result = $sap->execute($name, $request, $response);

foreach($sap->getProfiler()->getData() as $transaction) {

    echo $transaction->name;
    var_dump($transaction->request);

    if($transaction->success) {
        var_dump($transaction->response);

    } else {
        echo 'FAIL: ', $transaction->message;
    }

    echo $transaction->time, ' seconds' ;
}

The Versions

09/04 2014

dev-master

9999999-dev

Saprfc abstraction layer

  Sources   Download

MIT

The Development Requires

by Dmitry.Krokhin

09/04 2014

2.0.0

2.0.0.0

Saprfc abstraction layer

  Sources   Download

MIT

The Development Requires

by Dmitry.Krokhin

31/03 2014

1.0.1

1.0.1.0

Saprfc abstraction layer

  Sources   Download

MIT

The Development Requires

by Dmitry.Krokhin

31/03 2014

1.0.0

1.0.0.0

  Sources   Download

by Dmitry.Krokhin