SAPRFC use RFC (remote call function) API to make call a function module in SAP R/3. You can also write RFC server program in PHP and call PHP functions from SAP R/3. Function modules are defined in transaction SE37 (Function Builder). Each function module has interface defined. The interface definition consist from import parameters (input), export parameters (output), internal tables (input/output) and exceptions. The function module have to set RFC support enable to be able called by RFC from a remote system. More information about function modules and programming concepts in SAP R/3 you can find on http://help.sap.com under the BC manuals.
You need to compile PHP with the --with-saprfc parameter to enable this extension. You also need SAP RFCSDK (if you are SAP customer, you can find it on the "Presentation CD").
Return array with some information about an RFC connection, such as host name, service of the connected application server and SAP gateway, the R/3 system number, client, user and language.
It should be called after saprfc_call_and_receive() or saprfc_server_dispatch().
You need to compile PHP with the --with-saprfc parameter to enable this extension. You also need SAP RFCSDK (if you are SAP customer, you can find it on the "Presentation CD").
- Table of Contents
saprfc_attributes — Gets some information about RFC connection
- saprfc_call_and_receive — Does a remote call of an function module
- saprfc_close — Closes a RFC connection
- saprfc_error — Gets the last RFC error message
- saprfc_exception — Gets a exception string for last call of an function module
- saprfc_export — Gets a value of a export parameter
- saprfc_function_debug info — Prinst an interface definition of a function module and content of internal buffers
- saprfc_function_define — Defines an interface of a function module
- saprfc_function_discover — Discovers an interface of a function module
- saprfc_function_free — Frees a function module resources
- saprfc_function_interface — Gets an interface definition of a function module
- saprfc_function_name — Gets the name of function module
- saprfc_import — Sets a value of a import parameter
- saprfc_server_accept — Accepts an incoming RFC connection
- saprfc_server_export — Sets a value of a export parameter
- saprfc_server_import — Gets a value of a import parameter
- saprfc_server_dispatch — Receives a single RFC request and call a corresponding PHP function
- saprfc_server_register_check — Check for registered RFC server at a SAP gateway
- saprfc_server_register_cancel — Cancel all registered RFC servers at a SAP gateway
- saprfc_set_trace — Activate/Deactivate the RFC trace
- saprfc_table_append — Appends a line at end of internal table
- saprfc_table_init — Init a internal table
- saprfc_table_insert — Inserts a line into an internal table
- saprfc_table_modify — Modify a line of an internal table
- saprfc_table_read — Reads a line from an internal table
- saprfc_table_remove — Removes a line of an internal table
- saprfc_table_rows — Gets a number of lines an internal table
- saprfc_trfc_call — Calls a function module in R/3 indirectly (tRFC)
- saprfc_trfc_dispatch — Receives a single RFC request and call a corresponding PHP function (tRFC)
- saprfc_trfc_install — Installs functions to control transactional behaviour (tRFC)
- saprfc_trfc_tid — Gets a transaction-ID for a following call of a function module using tRFC
- saprfc_open — Open a RFC connection to SAP R/3
- saprfc_optional — Set a import parameter as optional
- saprfc_set_code_page — Set SAP codepage for a RFC connection
- saprfc_allow_start_program — Explicitly allows the RFC library to start the programs
- saprfc_get_ticket — Retrieve backend generated cookie version 2 after calling saprfc_open with flag GETSSO2
saprfc_attributes
(PHP 4, PHP 5)
saprfc_attributes -- Get some information about RFC connection
saprfc_attributes -- Get some information about RFC connection
Description
array saprfc_attributes (int rfc)
It should be called after saprfc_call_and_receive() or saprfc_server_dispatch().
$attr[dest] | field RFC destination |
$attr[own_host] | Own host name |
$attr[partner_host] | Partner host name |
$attr[systnr] | R/3 system number |
$attr[sysid] | R/3 system name |
$attr[client] | Client |
$attr[user] | User |
$attr[language] | Language |
$attr[trace] | ON/OFF: 'X'/' ' |
$attr[ISO_language] | 2-byte ISO-Language |
$attr[own_codepage] | Own code page |
$attr[partner_codepage] | Partner code page |
$attr[rfc_role] | C/S: RFC Client / RFC Server |
$attr[own_type] | 2/3/E/R: R/2,R/3,Ext,Reg.Ext |
$attr[own_rel] | My system release |
$attr[partner_type] | 2/3/E/R: R/2,R/3,Ext,Reg.Ext |
$attr[partner_rel] | Partner system release |
$attr[kernel_rel] | Partner kernel release |
$attr[CPIC_convid] | CPI-C Conversation ID |
saprfc_call_and_receive
(PHP 4, PHP 5)
saprfc_call_and_receive -- Do a remote call of an function module
saprfc_call_and_receive -- Do a remote call of an function module
Description
int saprfc_call_and_receive (int fce)
List of SAP RFC return codes:
SAPRFC_OK | O.K. |
SAPRFC_FAILURE | Error occurred |
SAPRFC_EXCEPTION | Exception raised |
SAPRFC_SYS_EXCEPTION | System exception raised, connection closed |
SAPRFC_CALL | Call received |
SAPRFC_INTERNAL_COM | Internal communication, repeat (internal use only) |
SAPRFC_CLOSED | Connection closed by the other side |
SAPRFC_RETRY | No data yet |
SAPRFC_NO_TID | No Transaction ID available |
SAPRFC_EXECUTED | Function already executed |
SAPRFC_SYNCHRONIZE | Synchronous Call in Progress |
SAPRFC_MEMORY_INSUFFICIENT | Memory insufficient |
SAPRFC_VERSION_MISMATCH | Version mismatch |
SAPRFC_NOT_FOUND | Function not found (internal use only) |
SAPRFC_CALL_NOT_SUPPORTED | This call is not supported |
SAPRFC_NOT_OWNER | Caller does not own the specified handle |
SAPRFC_NOT_INITIALIZED | RFC not yet initialized. |
SAPRFC_SYSTEM_CALLED | A system call such as RFC_PING for connectiontest is executed |
SAPRFC_INVALID_HANDLE | An invalid handle was passed to an API call. |
SAPRFC_INVALID_PARAMETER | An invalid parameter was passed to an API call. |
SAPRFC_CANCELED | Internal use only |
Example 1. Call ABAP function module
|
saprfc_close
(PHP 4, PHP 5)
saprfc_close -- Close a RFC connection
saprfc_close -- Close a RFC connection
Description
bool saprfc_close (int rfc)
See also: saprfc_open(), saprfc_server_accept()
saprfc_error
(PHP 4, PHP 5)
saprfc_error -- Get a last RFC error message
saprfc_error -- Get a last RFC error message
Description
string saprfc_error ()
saprfc_exception
(PHP 4, PHP 5)
saprfc_exception -- Get a exception string for last call of an function module
saprfc_exception -- Get a exception string for last call of an function module
Description
string saprfc_exception (int fce)
See also: saprfc_call_and_receive()
saprfc_export
(PHP 4, PHP 5)
saprfc_export -- Get a value of a export parameter
saprfc_export -- Get a value of a export parameter
Description
mixed saprfc_export (int fce, string name)
Example 1. Set of the import parameter
|
saprfc_function_debug info
(PHP 4, PHP 5)
saprfc_function_debug info -- Print an interface definition of a function module and content of internal buffers
saprfc_function_debug info -- Print an interface definition of a function module and content of internal buffers
Description
void saprfc_function_debug_info (int fce, [bool only_values])
saprfc_function_define
(PHP 4, PHP 5)
saprfc_function_define -- Define an interface of a function module
saprfc_function_define -- Define an interface of a function module
Description
int saprfc_function_define (int rfc, string function_module, array def, [bool not_trim = false])
For definition of PHP server function can be rfc parameter set to 0.
Example 1: Interface definition for function module RFC_READ_REPORT
|
saprfc_function_discover
(PHP 4, PHP 5)
saprfc_function_discover -- Discover an interface of a function module
saprfc_function_discover -- Discover an interface of a function module
Description
int saprfc_function_discover (int rfc, string function_module, [bool not_trim = false])
See also: saprfc_function_define(), saprfc_function_interface(), saprfc_function_debug_info(), saprfc_function_free()
saprfc_function_free
(PHP 4, PHP 5)
saprfc_function_free -- Free a function module resources
saprfc_function_free -- Free a function module resources
Description
bool saprfc_function_free (int fce)
saprfc_function_interface
(PHP 4, PHP 5)
saprfc_function_interface -- Get an interface definition of a function module
saprfc_function_interface -- Get an interface definition of a function module
Description
array saprfc_function_interface (int fce)
See also: saprfc_function_define(), saprfc_function_discover()
saprfc_function_name
(PHP 4, PHP 5)
saprfc_function_name -- Gets the name of function module
saprfc_function_name -- Gets the name of function module
Description
string saprfc_function_name (int fce)
saprfc_import
(PHP 4, PHP 5)
saprfc_import -- Set a value of a import parameter
saprfc_import -- Set a value of a import parameter
Description
bool saprfc_import (int fce, string name, mixed value)
Example 1. Set of the import parameter
|
saprfc_server_accept
(PHP 4, PHP 5)
saprfc_server_accept -- Accept an incoming RFC connection
saprfc_server_accept -- Accept an incoming RFC connection
Description
int saprfc_server_accept (mixed args)
Args parameter is used for registration on SAP Gateway (transaction SM59). The value of parameter can be $argv array or a command line string:
– a | program ID e.g. own_host_name.program_name |
– g | host name of the SAP gateway |
– x | service of the SAP gateway e.g. sapgw00 |
– t | Use RFC-trace |
Example 1. Checking Constants
|
saprfc_server_export
(PHP 4, PHP 5)
saprfc_server_export -- Set a value of a export parameter
saprfc_server_export -- Set a value of a export parameter
Description
bool saprfc_server_export (int fce, string name, mixed value)
See also: saprfc_export(), saprfc_import(), saprfc_server_export()
saprfc_server_import
(PHP 4, PHP 5)
saprfc_server_import -- Get a value of a import parameter
saprfc_server_import -- Get a value of a import parameter
Description
mixed saprfc_server_import (int fce, string name)
saprfc_server_dispatch
(PHP 4, PHP 5)
saprfc_server_dispatch -- Receive a single RFC request and call a corresponding PHP function
saprfc_server_dispatch -- Receive a single RFC request and call a corresponding PHP function
Description
int saprfc_server_dispatch (int rfc, array list [, int timeout])
Example 1. Implementation of server PHP function RFC_READ_REPORT()
|
saprfc_server_register_check
(PHP 4, PHP 5)
saprfc_server_register_check -- Check for registered RFC server at a SAP gateway
saprfc_server_register_check -- Check for registered RFC server at a SAP gateway
Description
array saprfc_server_register_check (string tpid, string gwhost, string gwservice)
An RFC program can use this call to check whether and how many RFC server programs are registered at a SAP gateway with a defined program ID (tpid). Values are returned in the array ("ntotal"=>?, "ninit"=>?,"nready"=>?,"nbusy"=>? )
An RFC server program which registers at a SAP gateway and then waits for RFC requests from any R/2 or R/3 or another external program can have one of the following 3 states:
INIT: RFC server is only registered at the SAP gateway, it doesn't wait at this moment for RFC request. An RFC server enters in this state after saprfc_server_accept() .
READY: RFC server enters in this state after saprfc_server_dispatch(), saprfc_trfc_dispatch() ; It is now ready to process incoming RFC requests.
BUSY: RFC server is processing an RFC request and is not available for other ones.
saprfc_server_register_cancel
(PHP 4, PHP 5)
saprfc_server_register_cancel -- Cancel all registered RFC servers at a SAP gateway
saprfc_server_register_cancel -- Cancel all registered RFC servers at a SAP gateway
Description
array saprfc_server_register_cancel (string tpid, string gwhost, string gwservice)
Pay attention that RFC servers in BUSY state cannot be canceled. In this case you will have a difference between the output parameters $array[ntotal] and $array[ncancel] returned by this call.
saprfc_set_trace
(PHP 4, PHP 5)
saprfc_set_trace -- Activate/Deactivate the RFC trace
saprfc_set_trace -- Activate/Deactivate the RFC trace
Description
void saprfc_set_trace (int rfc, bool level)
Activates the RFC trace (level = true) for a specified connection (valid rfc handle) or for all RFC connections (rfc = 0).
saprfc_table_append
(PHP 4, PHP 5)
saprfc_table_append -- Append a line at end of internal table
saprfc_table_append -- Append a line at end of internal table
Description
bool saprfc_table_append (int fce, string name, array value)
saprfc_table_init
(PHP 4, PHP 5)
saprfc_table_init -- Init a internal table
saprfc_table_init -- Init a internal table
Description
bool saprfc_table_init (int fce, string name)
saprfc_table_insert
(PHP 4, PHP 5)
saprfc_table_insert -- Insert a line to an internal table
saprfc_table_insert -- Insert a line to an internal table
Description
bool saprfc_table_insert (int fce, string name, array value, int index)
saprfc_table_modify
(PHP 4, PHP 5)
saprfc_table_modify -- Modify a line of an internal table
saprfc_table_modify -- Modify a line of an internal table
Description
bool saprfc_table_modify (int fce, string name, array value, int index)
saprfc_table_read
(PHP 4, PHP 5)
saprfc_table_read -- Read a line from an internal table
saprfc_table_read -- Read a line from an internal table
Description
array saprfc_table_read (int fce, string name, int index)
saprfc_table_remove
(PHP 4, PHP 5)
saprfc_table_remove -- Remove a line of an internal table
saprfc_table_remove -- Remove a line of an internal table
Description
bool saprfc_table_remove(int fce, string name, int index)
saprfc_table_rows
(PHP 4, PHP 5)
saprfc_table_rows -- Get a number of lines an internal table
saprfc_table_rows -- Get a number of lines an internal table
Description
int saprfc_table_rows (int fce, string name)
saprfc_trfc_call
(PHP 4, PHP 5)
saprfc_trfc_call -- Calls a function module in R/3 indirectly (tRFC)
saprfc_trfc_call -- Calls a function module in R/3 indirectly (tRFC)
Description
int saprfc_trfc_call (int fce, string tid)
With this function, the call of a function module in R/3 will use the transactional RFC interface in R/3.
Export parameters are not supported.
If an error occurs (almost only communication errors), the RFC client program has to reconnect to R/3 later and repeat this RFC call with the specific TransID. It must not create a new TransID via saprfc_trfc_tid()
saprfc_trfc_dispatch
(PHP 4, PHP 5)
saprfc_trfc_dispatch -- Receives a single RFC request and call a corresponding PHP function (tRFC)
saprfc_trfc_dispatch -- Receives a single RFC request and call a corresponding PHP function (tRFC)
Description
int saprfc_trfc_dispatch (int rfc, array list [, int timeout])
Alias to saprfc_server_dispatch().
saprfc_trfc_install
(PHP 4, PHP 5)
saprfc_trfc_dispatch -- Installs functions to control transactional behaviour (tRFC)
saprfc_trfc_dispatch -- Installs functions to control transactional behaviour (tRFC)
Description
bool saprfc_trfc_install (string tid_check, string tid_commit, string tid_rollback, string tid_confirm, string dispatcher)
This function was introduced to allow an RFC server program to ensure exactly-once behaviour for functions being called via tRFC in ABAP: saprfc_trfc_install() must thus be called by RFC server program before thesaprfc_trfc_dispatch() loop is entered if this program wants to receive transactional RFC calls and must ensure that RFC calls are done excatly once.
Without installing these functions it can only be guaranteed that an RFC function call issued by 'Call Function... In Background Task' is done at least once. Then all function modules offered by such a server program which are called via 'Call Function... In Background Task' must cope with being called more then once.
If installed, the first function tid_check, if a transactional RFC is to be called. The actual Transaction ID is passed. The function has to store this transaction-ID in permanent storage and return 0. If the same function will be called later again with the same transaction-ID, it has to make sure that it will return a non-zero value. If the same transaction is already running by another process but is not completed, the function has to wait until the transaction completes.
The second function tid_commit is called if all the RFC function module calls are done and the local transaction can be completed. It should be used to locally commit the transaction, if necessary .
The third function tid_rollback is called instead of the second function, if, from the point of view of the RFC library, there occurred an error while processing the local transaction. This function can be used to roll back the local transaction.
The fourth function tid_confirm will be called if the local transaction is completed also from the point of view of the calling system and all information on this transaction-ID can be discarded.
The last function dispatcher is called from saprfc_trfc_dispatch() and return function handle for function name.
See the trfcserv.php example.
saprfc_trfc_tid
(PHP 4, PHP 5)
saprfc_trfc_tid -- Gets a transaction-ID for a following call of a function module using tRFC
saprfc_trfc_tid -- Gets a transaction-ID for a following call of a function module using tRFC
Description
string saprfc_trfc_tid (int rfc)
Gets a transaction-ID for a following call of a function module in R/3 using the transactional RFC interface in R/3. With this function a new TransID will be produced from the R/3 System. The RFC client program has to call a function module in R/3 via saprfc_trfc_call() with this TransID.
If an error occurs (e.g. communication error) during the call of a function module in R/3 via saprfc_trfc_call(), the RFC client program has to reconnect the RFC connection and repeat the saprfc_trfc_call() without creating a new TransId
saprfc_open
(PHP 4, PHP 5)
saprfc_open -- Open a RFC connection to SAP R/3
saprfc_open -- Open a RFC connection to SAP R/3
Description
int saprfc_open (array conn)
conn = array ("ASHOST" => "",
"SYSNR" => "",
"CLIENT" => "",
"USER" => "",
"PASSWD" => "",
"GWHOST" =>"",
"GWSERV" =>"",
"MSHOST" =>"",
"R3NAME" =>"",
"GROUP" =>"",
"LANG" =>"",
"TRACE" =>"");
Example 1. Login to aplication server
|
Example 2. Login to logon group (using load balancing)
|
See also: saprfc_error(), saprfc_close()
saprfc_optional
(PHP 4, PHP 5)
saprfc_optional -- Set a import parameter as optional
saprfc_optional -- Set a import parameter as optional
Description
bool saprfc_optional (int fce, string name, bool value)
saprfc_set_code_page
(PHP 4, PHP 5)
saprfc_set_code_page -- Set SAP codepage for a RFC connection
saprfc_set_code_page -- Set SAP codepage for a RFC connection
Description
bool saprfc_set_code_page (int rfc, string codepage)
saprfc_allow_start_program
(PHP 4, PHP 5)
saprfc_allow_start_program -- Explicitly allows the RFC library to start the programs
saprfc_allow_start_program -- Explicitly allows the RFC library to start the programs
Description
bool saprfc_allow_start_program ([ string program_list ])
This call can be used either in RFC client or RFC server program.
It can be useful if you have a document management system within R/3 and want to check out documents (from sap) or check in documents (to sap) with the help of the external programs sapftp/saphttp (very comfortable; ftp/http-clients that can be controlled from external here from the sap stack; can be downloaded from the SAP Service Marketplace). The call of saprfc_allow_start_program() is needed for BAPIs like BAPI_DOCUMENT_CHECKOUTMODIFY2 or BAPI_DOCUMENT_CHECKIN2 and the like.
Example 1: Allow start external program sapftp and saphttp
|
Example 2: Allow start any external program
|
saprfc_get_ticket
(PHP 4, PHP 5)
saprfc_get_ticket -- Retrieve backend generated cookie version 2 after calling saprfc_open with flag GETSSO2
saprfc_get_ticket -- Retrieve backend generated cookie version 2 after calling saprfc_open with flag GETSSO2
Description
string saprfc_get_ticket ( int rfc)
Example 1: Get SSO2 logon ticket
|
Example 2: Login with SSO2 ticket
|
No comments:
Post a Comment