elielelie / laravel-sap
SAP features integrated with Laravel.
Requires
- php: ^8.2
- illuminate/console: ^10.0|^11.0|^12.0
- illuminate/support: ^10.0|^11.0|^12.0
Requires (Dev)
- laravel/pint: ^1.27
- mockery/mockery: ^1.6
- pestphp/pest: ^2.35
- pestphp/pest-plugin-arch: ^2.0
- pestphp/pest-plugin-laravel: ^2.0
README
SAP features integrated with Laravel.
Installation
Make sure you have the php7-sapnwrfc extension installed.
composer require elielelie/laravel-sap
To establish the connection with SAP, you need to add the following variables to your .env file:
SAP_HOST Host
SAP_SYSTEM System number
SAP_LANGUAGE Language default
SAP_CLIENT Client instance
SAP_USERNAME Username
SAP_PASSWORD Password
You can publish the configuration file and add new connections by running:
$ php artisan vendor:publish --provider="Elielelie\Sap\SapServiceProvider"
Usage
Connecting to SAP
<?php use Elielelie\Sap\Sap; $sap = app(Sap::class); $connection = $sap->open(); or // Connection name defined in the configuration file config/sap.php $connection = $sap->open('name');
Perform Function Module call
<?php // ... connection $function = $connection->fm('BAPI_USER_GET_DETAIL'); // Get function description. print_r($function->description()); // Add import parameter. $function->param('USERNAME', 'USER'); // Perform function call and retrieve result. $results = $function->execute(); $connection->close();
Getting details about a user using RFC_READ_TABLE
<?php // ... connection $function = $connection->fm('RFC_READ_TABLE'); $function->param('QUERY_TABLE', 'USR01') ->param('OPTIONS', [ ['TEXT' => 'BNAME = 'USER' OR BNAME = 'USER2' OR BNAME LIKE 'USER5*'] ]) ->param('ROWCOUNT', 5) ->param('DELIMITER', '~') ; $result = $function->execute(); $connection->close();
Query Builder usage
<?php // ... connection $fm = $connection->fmc(Table::class); $results = $fm->table('USR01') ->fields(['BNAME', 'STCOD', 'MANDT' ...]) ->where('bname', ['USER', 'USER5']) ->orWhere('bname', 'LIKE', 'USER5*') ->limit(5) ->get() ;
Testing
This package includes a comprehensive test suite using Pest PHP.
Running Tests
# Run all tests php vendor/bin/pest # Run with detailed output php vendor/bin/pest --testdox # Run with coverage php vendor/bin/pest --coverage
Test Coverage
- ✅ Unit Tests: Guid, Arr, QueryBuilder, Server (100% coverage)
- ⏭️ Feature Tests: Connection, Sap, FunctionModule, Table (require SAP connection or mocking)
For more information about testing, see TESTING.md.
License
This software is licensed under the MIT license. See LICENSE for details.
Legal Notice
SAP and other SAP products and services mentioned herein are trademarks or registered trademarks of SAP SE (or an SAP affiliate company) in Germany and other countries.