Create SAP - PHP Connection using SAPRfc  ( Obsolete )

<< Click to Display Table of Contents >>

Navigation:  All About SAP Interface > SAP r/3 and PHP >

Create SAP - PHP Connection using SAPRfc  ( Obsolete )

Objective

Create File Logon

Create SAP Logon

Calling and Using RFC/BAPIs from SAP R/3

Support

Download Source Code

Contributor

Albertus Reinandang ( reinandang@yahoo.com )

 

Requirement

All step is already tested using this requirement

1.SAP GUI 6.40 Patch Level 0-21 or SAP GUI 7.10 Patch Level 0 (download)

2.XAMPP (download)

3.SAPRFC (download)

4.Windows 2000 or XP

In SAP system, there are roles that we must pass through SAP Logon to access SAP feature. SAP Logon need a special codes to be a standard SAP Logon system, which is:

Client (R/3 System, client number from logon)

> A client in the r/3 system that you want to connect to

ApplicationServer (Name of Application Server )

> The name of the host that you want to connect to

SystemNumber ( System Number server SAP )

> Specify the system number (e.g. 00) of the SAP System that you want to connect to

System ( System ID)

> Specify the system ID (e.g. OSS) of the SAP System that you want to connect to

User ( User Logon Name )

Password ( User Password )

Language ( System Language )

If you not completely all the condition of that code above, you can’t using/accessing a feature in SAP GUI ActiveX, especially “SAP Functions” .

 

Installed Component

1.SAP ActiveX (librfc32.dll)

2.Aphace + PHP (How to install)

3.SAPRFC as SAP Connector for PHP (How to install)

 

____________________________________________________________________________

 

Create File Logon

 

1.Create new Folder "practice" at "C:\xampp\htdocs\saprfc-1.*.Win32\sapclasses\"

2.Run "Notepad"

3.Fill the text with this value below

#Connection String

ASHOST = <SAP r/3 IP Address>

SYSNR = <System Number>

CLIENT = <Client>

USER = <SAP Username>

PASSWD = <Password>

 

Example :

#Connection String

ASHOST = 192.200.1.11

SYSNR = 00

CLIENT = 800

USER = abap01

PASSWD = 123456

 

4.Save the file with name "logon_data.conf" and put in at "C:\xampp\htdocs\saprfc-1.4.1-5.2.6.Win32\sapclasses\practice\" folder

5.Finished

 

PHP00001

 

 

____________________________________________________________________________

 

Create SAP Logon

 

SAPLogonControl Concept and Format:

 … Declare a New Connection …

 … Fill Connection Variable …

 … login …

 

Example:

 

    $sap = new SAPConnection();

    $sap->Connect("logon_data.conf");

    if ($sap->GetStatus() == SAPRFC_OK ) $sap->Open ();

    if ($sap->GetStatus() != SAPRFC_OK ) {

       $sap->PrintStatus();

       exit;

    }

 

>> … $sap->GetStatus() != SAPRFC_OK

 

Note : SAPRFC_OK” = it’s mean ‘You have Succeed Login to SAP !!’

 

The following Example show how to used SAPConnection method:

 

No

Description

 

1

Difficulty

Easy ( For beginner )

2

PHP

Standard PHP Syntax

 

Procedure:

1.Run "Notepad"

2.Fill the text with this value below

<html>

<head>

   <title>RFC/BAPI : Test Connection</title>

</head>

<body>

<h1>RFC/BAPI : Test Connection</h1>

<?

    include_once("../sap.php");

    $sap = new SAPConnection();

    $sap->Connect("logon_data.conf");

    if ($sap->GetStatus() == SAPRFC_OK ) $sap->Open ();

    if ($sap->GetStatus() != SAPRFC_OK ) {

       $sap->PrintStatus();

       exit;

    }else{
   echo "Login succeed.";
}
$sap->Close();

?>

</body>

</html>

 

6.Save the file with name "practice_php001.php" and put in at "C:\xampp\htdocs\saprfc-1.4.1-5.2.6.Win32\sapclasses\practice\" folder

7.Open web browser and open "http://localhost/saprfc-1.4.1-5.2.6.win32/sapclasses/practice/practice_php001.php"

PHP00002

Notes : If "Login succeed." is appear then php is succeed connect to SAP.

 

8.Finished

 

____________________________________________________________________________

 

Calling and Using RFC/BAPIs from SAP R/3

 

BAPIs (Business Application Program Interfaces) is SAP business objects held in the Business Object Repository (BOR) encapsulate their data and processes. External access to the data and processes is only possible using specific methods.

RFC (Remote Function Call) is interfaces provided for communication between SAP Systems and with external partners.

 

The BAPIs and RFC in the R/3 System are currently implemented as function modules which are created and managed in the Function Builder (SE37). Not all SAP user can used a Function Builder. Only user who have an access key from SAP can used all the feature in Function Builder. You can get Access key from http://service.sap.com.

 

In RFC or BAPI desain there are 5 variable type, which is Import, Export, Changing, Tables and Exceptions. The variable which used generally is Import, Export and Tables.

delphi0022

 

Import Variable in SAPFunctions is declare as a functionexports “, while the Export variable is declare as a functionimports “.

 

SAPFunctions Concept and Format: 

 … SAPFunction Connection …

 … Calling SAPFunctions …

         … Fill (upload) Import/Tables variable in SAP …

         … Call (download) Export/Tables variable in SAP …

 … Close Connection …

 

 

The following Example show how to call RFC :

 

No

Description

 

1

Difficulty

Middle

2

PHP

Standard PHP Syntax

3

RFC/BAPI names

BAPI_USER_GETLIST

 

Procedure :

1.Open t-Code "SE37"

2.Display Function Module "BAPI_USER_GETLIST"

Import Paramaters

PHP00003

 

Export Paramaters

PHP00004

 

Tables Paramaters

PHP00005

 

3.Run "Notepad"

4.Fill the text with this value below

<html>

<head>

   <title>RFC/BAPI: Get List of Users in SAP-System</title>

</head>

<body>

<h1>RFC/BAPI: Get List of Users in SAP-System</h1>

<?

    include_once("../sap.php");

    $sap = new SAPConnection();

    $sap->Connect("logon_data.conf");

    if ($sap->GetStatus() == SAPRFC_OK ) $sap->Open ();

    if ($sap->GetStatus() != SAPRFC_OK ) {

       $sap->PrintStatus();

       exit;

    }

 

    $fce = &$sap->NewFunction ("BAPI_USER_GETLIST");

    if ($fce == false ) {

       $sap->PrintStatus();

       exit;

    }
//Import
    $fce->MAX_ROWS = "0"; // "0" => Get All User
$fce->WITH_USERNAME = "X";
//Execute Function
    $fce->Call();
    if ($fce->GetStatus() == SAPRFC_OK) {
       //Get Data
       
       //Export
       echo "Total Rows : ", $fce->ROWS,"<br/>";
       

        //Tables

        echo "<table width = '100%' border='0' cellpadding='0' cellspacing='1'>
                       <tr bgcolor='#666666'>
                               <td>User Name in User Master Record</td>
                               <td>First name</td>
                               <td>Last name</td>
                               <td>Full Name of Person</td>
                       </tr>";
        $fce->USERLIST->Reset();
       
       //Display Tables

        while ( $fce->USERLIST->Next() ){

            echo "<tr bgcolor='#CCCCCC'>
                               <td>".$fce->USERLIST->row["USERNAME"]."</td>
                               <td>".$fce->USERLIST->row["FIRSTNAME"]."</td>
                               <td>".$fce->USERLIST->row["LASTNAME"]."</td>
                               <td>".$fce->USERLIST->row["FULLNAME"]."</td>
                         </tr>";
       }
        echo "</table>";                        

    } else

        $fce->PrintStatus();

 
$sap->Close();

?>

</body>

</html>

 

5.Save the file with name "practice_php002.php" and put in at "C:\xampp\htdocs\saprfc-1.4.1-5.2.6.Win32\sapclasses\practice\" folder

6.Open web browser and open "http://localhost/saprfc-1.4.1-5.2.6.win32/sapclasses/practice/practice_php001.php

PHP00006

 

7.Finished