Application Development and Automation Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

Data from SAP BAPI using PHP Script

Former Member
0 Likes
3,724

Hi,

Company wants to fetch data from Customer Details BAPI - BAPI_CUSTOMER_GETDETAIL2 using PHP Script,

How to go about it kindly help

Thanks and Regards,
Nishant Bhargava

1 ACCEPTED SOLUTION
Read only

former_member184675
Active Participant
0 Likes
1,860

Hi,

There is plenty of online documentations and examples on how to call BAPI's from PHP..

Check these out

http://www.sdn.sap.com/irj/sdn/index?rid=/webcontent/uuid/5d9fb155-0b01-0010-8e8a-d8703df8bb9e

http://saprfc.sourceforge.net/

Best regards,

Andrei Sosea

10 REPLIES 10
Read only

former_member184675
Active Participant
0 Likes
1,861

Hi,

There is plenty of online documentations and examples on how to call BAPI's from PHP..

Check these out

http://www.sdn.sap.com/irj/sdn/index?rid=/webcontent/uuid/5d9fb155-0b01-0010-8e8a-d8703df8bb9e

http://saprfc.sourceforge.net/

Best regards,

Andrei Sosea

Read only

0 Likes
1,860

Sir,

I am getting following error while connecting SAP and PHP, Kindly help

RFC Error Info : Key : RFC_NOT_INIT Status : Message : RFC subsystem not yet initialized. Internal:

Read only

former_member214878
Active Participant
0 Likes
1,860

Dear Nishant,

There is a typical way to do this, first of all you need to understand the RFC and Normal BAPI behaviour.
There is a significant difference in both, but time being you dont have to bother about it.

The way usually people do it is they create a MySql Table in a PHP environment, (Usually PHP goes smoothly with MySql thats why I have said MySql), and then by use of SAPRFC extension for PHP and using couple of predefined functions in PHP, fetch the data from SAP R/3.   That data usually be stored in the created database undelaying in APACHE, MYSQL environment. (APACHE is HTTP server). 

Its not that easy as we read it above, but you can refer to - Typical example below
http://www.sap-hefte.de/download/dateien/935/066_leseprobe.pdf


Complete set of ZEND API AND RFC API.
http://saprfc.sourceforge.net/

Lets try once .........

Cheers

Read only

0 Likes
1,860

Sir,

I am developed the below code, but not able to connect to SAP RFC to PHP Server, kindly check where I am going wrong in it.

I have installed SAPRFC on PHP server nut still its not connecting.

<html>

<h1>SAPRFC-Class: ---PHP</h1>

<?php

      require_once("saprfc.php");

      // Create saprfc-instance

 

     $sap = new saprfc(array(

                              "logindata"=>array(

                                   "ASHOST"=>" "          // application server

                                   ,"SYSNR"=>"00"                    // system number

                                   ,"CLIENT"=>"600"               // client

                                   ,"USER"=>" "               // user name

                                   ,"PASSWD"=>""          // password

                                   )

                              ,"show_errors"=>false               // let class printout errors

                              ,"debug"=>true)) ;                     // detailed debugging information

         // Call-Function

     $result=$sap->callFunction("BAPI_SALESORDER_GETLIST",

                                        array(     array("IMPORT","CUSTOMER_NUMBER",5),

                                                  array("IMPORT","SALES_ORGANIZATION",1130),

                                                  array("EXPORT","RETURN",""),

                                                  array("TABLE","SALES_ORDERS",array())

                                        ));                                        

                      

     // Call successfull?

     if ($sap->getStatus() == SAPRFC_OK) {

          // Yes, print out the Userlist

          ?><table>

               <tr><td>SD_DOC</td><td>SHORT_TEXT</td></tr><?php

          //$sap->printStatus();

          //var_dump($result);

          foreach ($result["SALES_ORDERS"] as $orders) {

               echo "<tr><td>", $orders["SD_DOC"],"</td><td>",$orders["SHORT_TEXT"],"</td></tr>";

          }

          ?></table><?php

     } else {

          // No, print long Version of last Error

          $sap->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();

?>

Read only

0 Likes
1,860

Hi,

I guess your Php script is not connecting to

sap.If you are a  SAP consultant put External break point in to the BAPI and Execute your script again (if not Ask ur sap consultant ).If your script is connecting to the SAP ,it would Execute the bapi in Debugging mode.But by looking in to your code i couldn't see any connection string( I am not a PHP developer,but having bit idea).Just check your script ,whether the script is sufficient or not.

Best Regards

Naresh Bammidi

Read only

0 Likes
1,860

Dear Naresh,

Putting a break-point in a BAPI wont trigger a BP I guess, and as far as the PHP connection string goes he dont need it one.

As the RFC needs a BOR registration and provides several API's to connect to R/3 from outside world, the instance creation to the class here is the same as a connection to the SAP R/3. As u see closely its a parameterized constructor and having username/pass/client etc. information.

Considering I do not know PHP and Nishant knows it better than both of us, I would like to suggest Nishant to debug his code, whether he is properly calling each required API, and if he can get any help in debugging a BAPI/RFC whatever it is from a ABAPer, would lead to the problem then he can paste the problem and can seek for more information on the answer. ...

Thanks and Regards,

Ravindra Sonar.

Read only

former_member184675
Active Participant
0 Likes
1,860

Hi please confirm the following:

- have you copied saprfc.dll in php ext folder? (assuming you're on windows)

- have you modified php.ini to add saprfc.dll as an extension?

- do you see the SAP module in phpinfo()?

- is saprfc.php in your project's root folder?

- has the sap user you're using sufficient authorizations ?

- have you passed on the log on variables correctly (they are missing in the code you posted )

To what concerns your code look into the following aspects:

- change the CUSTOMER_NUMBER from 5 to 000000005.

- check the length of $result["SALES_ORDERS"] in case the BAPI returns 0 values due to incorrect/missing CUSTOMER_NUMBER

- check for any error messages in $result["RETURN"]

Andrei

Read only

0 Likes
1,860

Hi Andrei,

Please help me, how to insert into database like mysql from that result data.

Thanks

Deny

Read only

0 Likes
1,860

Hi,

You need to call RFC enabled FM. Either existing ones or you create them yourself . What exactly do you plan to insert into SAP  ?

-

Andrei

Read only

Former Member
0 Likes
1,860

Hi,

you can achieve this through web service function module.

Regards,

John.