0% found this document useful (0 votes)
261 views

Connecting SAP and PHP

The document discusses connecting SAP to PHP using the SAPRFC module. It explains how to download and configure the SAPRFC module for PHP. It also describes the steps to create a remote-enabled function module in SAP and then call that function module from a PHP program using the SAPRFC library. Code examples are provided to demonstrate how to login to SAP, call the remote function module, and log off from SAP.

Uploaded by

Yerlan Guevara
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
261 views

Connecting SAP and PHP

The document discusses connecting SAP to PHP using the SAPRFC module. It explains how to download and configure the SAPRFC module for PHP. It also describes the steps to create a remote-enabled function module in SAP and then call that function module from a PHP program using the SAPRFC library. Code examples are provided to demonstrate how to login to SAP, call the remote function module, and log off from SAP.

Uploaded by

Yerlan Guevara
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

24/11/2016 ConnectingSAPandPHPRaminduDeshapriya

ConnectingSAPandPHP
SAPissaidtobethemostcomprehensiveandwidelyusedEnterpriseResourcePlanningsystemever.Duetoitswidespreaduse,
SAPusersanddeveloperscomeacrossavarietyofsituationswheretheyneedtoconnectaninstallationofSAPtoadifferent
platform/programminglanguagesothatthedataanddatainterpretationscontainedinrelationtothatinstallationcanbeaccessedby
thatplatformorprogramminglanguage.HenceamyriadofSAPconnectorsfordifferentprogramminglanguageshavebeenborn.

PHP,beingthemostwidelyusedserversideprogramminglanguageontheweb,isoneofthemostprobablelanguagesthatwould
needtoconnecttoSAPatsomepointortheother.Forthis,theextremelyhandySAPRFCmoduleforPHPhasbeendeveloped.This
postwilldiscussanendtoendimplementationoftheSAPRFCPHPmoduleandexplainhowtoconnectSAPtothemoduleaswell.

Thefirststepistogototheabovelinkanddownloadthecompletesaprfcpackage.TheeasiestwaytointerfacesaprfcwithPHPand
togetittoworkistodownloadXAMPP1.7.1(NOTthelatestversion).ThiscontainsPHP5.28whichseemstobetheonlyPHP
versionwhichworkscorrectlywiththeSAPRFCmodule.

UnzipXAMPPandcopyphp_saprfc_528.dllfromyoursaprfc/extfolderovertothe/php/ext/folderinyourXAMPPdirectory.
Locatethephp.inifileinXAMPPandopenitforediting.Hereyouwillhavetofindtheextensionssectionandaddtheline

extension=php_saprfc_528.dll

tothissection.NowopentheXAMPPControlPanelandstartApache.Ifyoufollowedtheabovestepscorrectly,Apacheshouldstart
nowwithoutanyproblems.IFitgivesanerror,goovertheabovestepsagain.

Firstofall,wellseewhatweneedtodoontheSAPsidetoexposeaRemoteFunctionModulewhichcanbeaccessedviaRFC.All
youneedtodoistocreatearemoteenabledFunctionModuleinSAP.ThiscanbedonebytickingRemoteenabledmoduleunder
thefunctionmodulesattributes,asshownbelow:

http://rdeshapriya.com/connectingsapandphp/ 1/3
24/11/2016 ConnectingSAPandPHPRaminduDeshapriya

YoucanwritewhateverprogramlogicinABAPintheFunctionModule.PayspecialattentiontotheImportingandExporting
parametersoftheFunctionModuleasthesewillbewhatarepassedtoandfromyourPHPprogram.

Next,youneedtocopyoverthesaprfc.phplibraryfileoverfromthesaprfcmodulefoldertoyourPHPprojectdirectory.Youcanuse
thefunctionscontainedinthisfiletocreateasaprfcobjectwhichcanlogintoSAPandaccessyourremoteenabledFunctionModule.

ThefollowingcodeisessentialforyourPHPprogramtoaccessSAP:

1 require_once('saprfc.php');
2 $submitted=$_GET['submitted'];
3 /**
4 *LogintoSAPsystem
5 *@paramString$user
6 *@paramString$pwd
7 */
8 functionlogin($user,$pwd){
http://rdeshapriya.com/connectingsapandphp/ 2/3
24/11/2016 ConnectingSAPandPHPRaminduDeshapriya

8 functionlogin($user,$pwd){
9 //CreateSAPRFCinstance
10 $sap=newsaprfc(array(
11 "logindata"=>;array(
12 "ASHOST"=>;"HOSTNAME",
13 "SYSNR"=>;"SYSTEMNUMBER",
14 "CLIENT"=>;"CLIENTNUMBEr",
15 "USER"=>;"USERNAME",
16 "PASSWD"=>;"PASSWORD"
17 ),
18 "show_errors"=>;true,
19 "debug"=>;false));
20
21 return$sap;
22 }
23 functionlogoff($sap){
24 $sap>;logoff();
25 }
26 /**
27 *FunctiontocallSAPRFC
28 *@paramsaprfc$sap
29 */
30 functioncallRFC($sap,$params){
31 $cust_params=$params['cust_params'];
32 $task_params=$params['task_params'];
33 $proj_params=$params['proj_params'];
34 $result=$sap>;callFunction("ZGRAPH_TOTALDAYS_RFC"
35 array(
36 array("IMPORT","CUST_PARAMS",$cust_params
37 array("IMPORT","TASK_PARAMS",$task_params
38 array("IMPORT","PROJ_PARAMS",$proj_params
39 array("EXPORT","CATEGORIES",array
40 array("EXPORT","DATA_ACTUAL",array
41 array("EXPORT","DATA_ESTIMATE",
42 )
43 );
44 return$result;
45 }

http://rdeshapriya.com/connectingsapandphp/ 3/3

You might also like