You are on page 1of 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