1. Go to this page and download the library: Download avadaneidanut/sapphp library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
avadaneidanut / sapphp example snippets
use SapPhp\Connection;
use SapPhp\Exceptions\BoxNotFoundException;
try {
$connection = new Connection(
'box', // SAP Box Name
'user', // SAP Username
'passwd', // SAP Password
'500' // SAP Client Code
);
} catch(sapnwrfcConnectionException $ex) {
// Do something if login failed.
} catch(BoxNotFoundException $ex) {
// Do something if box doesn't exist.
}
// ... connection
// Instantiate new Function Module interface.
$function = $connection->fm(
'BAPI_USER_GET_DETAIL', // RFC Enable FM
true // Parse result (trim all strings and decode GUIDs)
);
// Get function description.
print_r($function->description());
// Add import parameter.
// Will trigger an \SapPhp\Exceptions\ParamNotFoundException if param is not found in function description.
$function->param('USERNAME', 'USER');
// Perform function call and retrieve result.
$result = $function->invoke();
// ... connection
// fm method will check if RfcReadTable is an FunctionModule interface Class, if so will return a new instance.
$function = $connection->fm('RfcReadTable');
// Let's do the same thing as before.
$result = $function->table('usr01') // set the query table
->where('bname', ['USER', 'USER5']) // add multiple where clause (simulating where in )
->orWhere('bname', 'LIKE', 'USER5*') // add custom comparation operator
->limit(5) // limit the result to 5 rows
->get() // perform function call, parse the result and return a \Illuminate\Support\Collection object.
;
print_r($result->toArray());
$query->where('column', 'value') // Add WHERE clause
->andWhere('column2,' 'value2') // AND logical operarator
->orWhere('column3', '<>', 'value3') // OR logical operator
->orWhere(function ($query) { // WHERE group
$query->where('column11', 'value11')
->andWhere('column22', 'value22');
})
->orWhere('column5', '<>', [1, 2, 3, 4]); // Simulate WHERE IN clause