Skip to Content
Introduction

Following the weather magnet challenge (Weather Magnet) a more involved challenge was issued. Use the user control BAPIs to allow a PHP interface to the users.
The competition prizes are still on offer, a chance to get your hands on a copy of Zend Studio and PHP 5 book.

The following 3 code samples provide a stepping stone for the PHP User control. The examples concentrate on the interaction with the backend and leave the presentation aspects open to creativity.
The BAPIs available are:

BAPI_USER_DELETE
BAPI_USER_DISPLAY (This may not be so useful in this scenario)
BAPI_USER_EXISTANCE_CHECK
BAPI_USER_GETLIST
BAPI_USER_GET_DETAIL
BAPI_USER_UNLOCK
BAPI_USER_LOCK

The example implements only the BAPI_USER_GET_DETAIL method, the rest are left to the imagination of the contestant.

Code

The code is separated into two classes, one for the user and one for backend access. The backend access uses the BAPIs provided as Web Services. It you want to use RFC then simply replace this class with one that implements the RFC interface.

showuser.php

The first piece is simply a test script to display the contents of the user class to the user.

Simple example to show some user data. If you want to change the username at runtime you can specify the user in the URL e.g. showusers.php?user=ME The last name of $username is “.$user->getLastName(); //print_r($user); ?> 

userclass.php

This provides the beginnings of a class to represent a single user. An instance is populated via calls to the static methods of the backend class.

backendclass.php

This is the interface to the backend system. The implementation uses the BAPI as a webservice..

Exception
“; echo $exception; echo “

Request :
“, htmlspecialchars($client->__getLastRequest()), “
“; echo “Response :
“, htmlspecialchars($client->__getLastResponse()), “
“; } } } ?>

To report this post you need to login first.

5 Comments

You must be Logged on to comment or reply to a post.

  1. Gwa GILLES

    Thanks for your helpful topic.<br/><br/>I have copied your example (changing wsdl url, login and pasword of course 😉 ) and I get an error I can’t resolve :<br/><br/>Exception<br/>SoapFault exception: Unauthorized in C:\Program Files\EasyPHP 2.0b1\www\saprfc\sapclasses\examples\backendclass.php:67 Stack trace: #0 : SoapClient->__doRequest(‘__call(‘BAPI_USER_GET_D…’, Array) #2 C:\Program Files\EasyPHP 2.0b1\www\saprfc\sapclasses\examples\backendclass.php(67): SoapClient->BAPI_USER_GET_DETAIL(Array) #3 C:\Program Files\EasyPHP 2.0b1\www\saprfc\sapclasses\examples\userclass.php(29): backend->GetUserDetail(Object(user)) #4 C:\Program Files\EasyPHP 2.0b1\www\saprfc\sapclasses\examples\showuser.php(17): user->user(‘JORGED’) #5 <br/><br/>Request :<br/><?xml version=”1.0″ encoding=”UTF-8″?> <SOAP-ENV:Envelope xmlns:SOAP-ENV=”http://schemas.xmlsoap.org/soap/envelope/” xmlns:ns1=”urn:sap-com:document:sap:rfc:functions”><SOAP-ENV:Body><ns1:BAPI_USER_GET_DETAIL><ACTIVITYGROUPS/><ADDCOMREM/><ADDFAX/><ADDPAG/><ADDPRT/><ADDRFC/><ADDRML/><ADDSMTP/><ADDSSF/><ADDTEL/><ADDTLX/><ADDTTX/><ADDURI/><ADDX400/><EXTIDHEAD/><EXTIDPART/><GROUPS/><PARAMETER/><PARAMETER1/><PROFILES/><RETURN/><SYSTEMS/><UCLASSSYS/><USERNAME>JORGED</USERNAME></ns1:BAPI_USER_GET_DETAIL></SOAP-ENV:Body></SOAP-ENV:Envelope><br/>Response :<br/><br/>The last name of JORGED is <br/><br/>If you could help me…<br/><br/>

    (0) 

Leave a Reply