Additional Blogs by SAP
cancel
Showing results for 
Search instead for 
Did you mean: 
craigcmehil
Community Manager
Community Manager
0 Kudos
My intention here is not to tell you how to program or anything like that, it's simply to help you get started with the whole PHP thing that of course in terms of SAP.

Again, I'm no expert with PHP, in fact I guess you could say I am still a newbie myself. I've been playing around with it now for about 2 years and originally I said that I would avoid it. It just so happens that I'm flexible and I learned how flexible it was and things just took off from there. So let's get to it shall we?

There are 3 things you need to get started with PHP for SAP development, oh and if you remember my bag you'll know I am a big fan of those cost free solutions. So what are these three magical items?
So please go out there and download each of those items so we can move along. So go ahead and install your apache server for example I have a partition on my system (T:) just for development it's only 5GB in size but it's more than enough. There I install the Apache HTTP server. Just the basic system install was all. Then I installed PHP, now I downloaded the PHP version 5 since for me it's just playing around, I installed that under Apachephp. Then I configured the httpd.conf file located under apacheconf:

I'm not going to go through each line of the config just the ones related to connecting PHP to it.

I set the PHPRC variable, I believe this is only for the PHP 5 version but don't quote me on that.

DocumentRoot "T:/websites"
SetEnv PHPRC T:/apache/php

Then I set my script alias so Apache knows what a .php file is.

ScriptAlias /php/ "T:/apache/php/"

Then of course to distinguish what a php script is I had to

AddType application/x-httpd-php .php .phtml

And of course the action for the type

Action application/x-httpd-php "/php/php-cgi.exe"

So with my Apache configuration all taken care of I jumped over to my PHP config. That's the php.ini file located inder Apache/php. I didn't do much at all to this file other than ensure that the extension directory was pointing to the right location and that the module for the SAPRFC was in place.

; Directory in which the loadable extensions (modules) reside.
extension_dir = "t:/apache/php/extensions"

extension=php_saprfc.dll

Then I also copied the php_saprfc.dll to the extension directory from where I unpacked my SAPRFC download.

Now because I have this hooked to my Mini Me of WAS 6.20, the Saga continues.... system from this point I was done with what I needed to get started. However, if you don't have the GUI installed please take a look at this Installing SAPRFC the topic of what needs to be done on the system has been covered there.

You'll of course need to open up the example pages that come with SAPRFC and make some changes but you are basically all done and can get started. A nice quick example would be this one here:

SAPRFC-Class: Get List of Users in SAP-System

array( "ASHOST"=>"2.2.2.183" // application server ,"SYSNR"=>"00" // system number ,"CLIENT"=>"000" // client ,"USER"=>"cmehcr1" // user ,"PASSWD"=>"xxxxxxx" // password ) ,"show_errors"=>false // let class printout errors ,"debug"=>false)) ; // detailed debugging information // Call-Function $result=$sap->callFunction("SO_USER_LIST_READ", array( array("IMPORT","USER_GENERIC_NAME","*"), array("TABLE","USER_DISPLAY_TAB",array()) )); // Call successfull? if ($sap->getStatus() == SAPRFC_OK) { // Yes, print out the Userlist ?>"; } ?>
SAP-NameUser-Nummer
", $user["SAPNAM"],"",$user["USRNO"],"
printStatus(); // or print your own error-message with the strings received from // $sap->getStatusText() or $sap->getStatusTextLong() } // Logoff/Close saprfc-connection LL/2001-08 $sap->logoff(); ?> 

So the example there is the standard one from SAPRFC, example_userlist.php, and so in order to use this you will need a few pieces from SAPRFC. OK, you really only need to ensure that the saprfc.php file is located. This file is the main class file containing all the little bits and pieces you need to connect.

// saprfc-class-library
require_once("saprfc.php");


or something like
// saprfc-class-library
require_once("saprfc/saprfc.php");


So you don't have to have copies of the file everywhere. Just remember it should be a relative path meaning within the same structure, I tried with http://2.2.2.183/saprfc/saprfc.php and it just didn't work perhaps one of those PHP experts might know a way do it?



As for editing and working with the files I tend to use whatever editor is handy at the moment whether it be Eclipse with PHP Eclipse or just plain old Notepad. There are a ton of editors out there for PHP and they vary in what they offer. I've been dealing with HTML and web based development for awhile so I tend to stick to Eclipse with PHP Eclipse mainly because I still do Java and Perl development. But if you are strictly PHP you might want to check out one of these editors, located at Snapfiles or jump over to PHP.net there you'll find some good links for editors as well.

Now that about covers all the basics of what you need to get started. From here you just have to learn how to program in PHP. For that you simple need to type "PHP tutorial" into your favorite search engine and you'll find a million resources. As for the connection to the SAP system, that is a RFC function call, the function of course you'll still need to program in ABAP.

With that I'll leave you to playing around, watch for my next weblog in the next couple of days regarding PHP and SAP.


14 Comments