php5.2 extending remote connections through SAPRFC sap730 success stories

Source: Internet
Author: User
Tags rfc

The company just on the SAP system, because of limited funds, SAP and other systems of data exchange needs to be implemented within the company. Therefore, the leader decides the warehousing application process needs to realize the electronic signature flow in SAP and OA system, the heavy burden falls on me indeed. Fortunately, I am only responsible for OA, and one colleague is responsible for SAP.

OA is developed in PHP, so the connection language naturally uses PHP. Online search, found that PHP has saprfc extension as early as 2005, fortunately, although after so many years, the extension is still available.

First, download the SAPRFC extension and enable it in php.ini. Visit http://pan.baidu.com/s/1kVPemn9, download saprfc1.4.1 full version, which contains Windows version php4.4, php5.2, php5.3 dll extension files, As well as the interface classes under the Sapclasses folder. Copy the corresponding version of the Php_saprfc_5xx.dll to PHP extension folder, modify the PHP configuration file php.ini, add a line below the dynamic extensions: EXTENSION=PHP_SAPRFC_ 5xx.dll. Then restart the httpd service. Web Access Phpinfo (), the following message appears, indicating that the PHP SAPRFC extension was successfully installed.

Second, install the SAP client and test the connection with the SAP server according to the example_userlist.php in the saprfc1.4.1 full version. SAPRFC is essentially a simulated SAPgui login. So you need to install RFCSDK to make the connection. To simplify the operation, install the SAPgui client directly, then the RFCSDK installation is complete. Similarly, if the Linux version of PHP, need to install Non-unicode SAP rfcsdk 6.40, but it seems that this thing is not easy to find. Then modify the Logindata parameter in the example_userlist.php to save the SAP parameters of the company, for example

$sap=NewSAPRFC (Array(                        "Logindata" =Array(                            "Ashost" = "Yourhostip"//Application Server, "Sysnr" = "00"//System Number, "CLIENT" = "800"//Client, "USER" = "Youruser"//User, "PASSWD" = "yourpwd"//Password, "CODEPAGE" = "8300"//define character set, otherwise it will be garbled in Chinese
) , "show_errors" =false //Let class printout errors, "Debug" =false)) ;//Detailed debugging Information

Web Access http://xxxxxx/example_userlist.php, if the following information appears, the PHP and SAP communication success.

Third, use the SAPRFC class to connect SAP. The full version of saprfc1.4.1 provides a series of classes to connect to SAP, invoke functions, manipulate tables, and create service interfaces.

$params=Array(                            "Ashost" = "Appip"//Application Server, "Sysnr" = "00"//System Number, "CLIENT" = "600"//Client, "USER" = "Account"//User, "PASSWD" = "pwd"//Password//, "LANG" = "ZH ", "CODEPAGE" = "6240"//8400 GBK Code                            );include_once("sapclasses/sap.class.php"); $sapConn=Newsapconnection (); $sapConn->connect ($params);//set CONNCET data array  $sapConn->open ();//Set/get RFC handle $sapConn->RFC  $sapFunc=Newsapfunction (); $sapFunc->discover ($sapConn->RFC, "z_oa_sign");//set/get function handle $sapFunc->fce,z_oa_sign function name    $para=Array(                                        Array("EXPORT", "TYP"),//The export parameter is not defined by default, but the definition is OK                                    Array("EXPORT", "MSG"),Array("IMPORT", "Zoanum",$oanum)                                ); RFC function input import, output export parameter definition$sapFunc->defvars ($para);                                 The Defvars method is not in the class, it needs to be added manually, and the code is shown below. $sapFunc-Call (); //Echo $sapFunc->typ; echo $sapFunc->msg;  if($sapFunc->typ== "S")EchoS;//typ, MSG is the return value of the RFC functionElse Echo $sapFunc-MSG; $sapFunc-Close (); $sapConn->close ();

Defvars methods for the Sapfunction class:

functionDefvars ($parameters){          foreach($parameters  as $key=$param) {              $type=$param[0]; $name=$param[1]; $value=isset($param[2])?$param[2]: ""; Switch($type) {                  Case"IMPORT":$this-$name=$value;  Break;  Case"EXPORT":$this-$name="";  Break; default:return"Saprfc::callfunction () wrong parameter-type. Must be IMPORT, EXPORT or TABLE. "; }      }        }

After mastering the above code, it is not easy to use PHP to connect to SAP.

php5.2 extending remote connections through SAPRFC sap730 success stories

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.