Hi, my name is Pascal and I am a SAP & Supply Chain specialist. I work for PLAUT and I do things others can't.
This blog only contains my personal views, thoughts and opinions. It is not endorsed by my employer nor does it constitute any official communication of PLAUT. You can contact me via email at pascal[at]renet-web.net or use the contact form that you will find by following the 'Contact' link and you can follow me on twitter here.
Posted on January 9, 2006 | Category: SAP
About 4 months ago I was trying out various things with SAPRrfc. To be more precise I was trying to mimick the the transaction code that most consultant refer to by its transaction code as opposed to the name of it. Yes (this is an easy one if you are an LO consultant) I’m talking about MD04 – the stock/requirements list.
In case you are not familiar with that transaction, this is what it looks like in SAP.

Nothing extraordinary – it has a material number, a plant code, a list of planning elements, associated dates, exception messages….Now the screen below is what I’ve been able to get in my internet browser (styled with a nice css file, it even looks a bit like SAP). 
By the way if anybody wants the php code to get that result, just leave a message and I will send it to you. You’ll notice that there is no selection made on the material number – that’s because it has been hard coded in the php file. I could of course load the material number (and associated plant) in a MySQL database but that is not geecky enough. Does anybody know how to get a material list in a
U2VsZWN0IExpc3Q=
with the help of a BAPI? I’ve tried but it ain’t workin’.
What I want to build is a php file that first uses a BAPI to get a list of materials (and associated plant) – then a submit to the function module I’m using here in order to get the stock requirements list in my browser.
Thursday 26th January 2006 update SAPRfc – stock/requirements list in browser
As the code has been requested, I’ve put up a link to the .php file used in this example. Save it to your drive, rename it from .txt to .php extension, change the necessary variables and use it. All you then have to do is improve the code, make it better and distribute back to the community. The file is here.
Code is released under Creative Commons License:
![]()
This work is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 2.5 License.
Monday 20th February 2006 update SAPRfc – stock/requirements list in browser
Thanks to Jako (Jopac) and his great suggestions I did some changes to the code and it works like a charm! Stay tuned as I will soon write a complete post just for retrieving mateial numbers (via php of course). I’ll later on whip up the complete code that combines retrieving material numbers and getting the stock requirements list
» Filed Under SAP
January 24th, 2006 at 8:25 pm
dear sir
i am interested with the code you have preview on about using transaction code maybe i can have more infor and the code of this
February 11th, 2006 at 5:36 am
Hi
What you mean with Select List?
Do you want to obtain a list of materials for a plant?
M
February 11th, 2006 at 10:19 am
Hello Mordix,
Yes that is what I mean. Ideally I would be able to retrieve a list of materials using the SAPrfc method (for example select all materials in plant XXXX), build up some sort of selection list, select a material and then submit that material number to the code available on this page so as to show its stock requirements list. Any input is appreciated.
February 17th, 2006 at 4:30 am
moi je pense que il faut :
1/ reflechir au pb de la taille de la base article
2/ ne pas oublier que BAPi veut simplement dire que la fonction est de type RFC.
=> du coup, attention au select list dynamique qui solliciterai trop le serveur et be aware sur les autres fonctions
Cependant pour répondre à la question :
BAPi_material_get_list. doit etre nickel
et si pas assez de criteres de selection :
RFC_read_table… ( je crois que c’est devenu interdit, mais c’est bien efficace, notamment pour s’assurer du nbre d’enregistrement repondant aux criteres de selections… ;) )
Moi si j’etais un ancien sbs , je reflechirai à la methodologie suivante :
– je compte le nbre d’enregistrement candidats dans SAP via rfc_read_table. (rapide )
- je compare avec le nbre d’enreg dans mysql. si different, je rapatrie le resultat dans ma base mysql.
– je fais une jolie boucle en php
du genre
$list_art = mysql_query(“Select matnr from Table_des_articles_sap where matnr like var_matnr);
$tab = array();
while ( $ligne = mysql_fetch_array( $list_art ) )
construire le select list
….
ou bien je ruse avec javascript et formulaire. moi j’avais joué il y a longtemps avec un truc comme ca :
Département
Alpes-Maritimes
Var
.
on remplace departement par article… etc
———————————–
A plus pascal…. Bonne traduction ;-)
———————————–
February 17th, 2006 at 8:38 am
Merci Jako, ah SBS, le bon vieux temps!
J’avais essaye de jouer avec BAPi_material_get_list mais je n’ai jamais réussi a la faire fonctionner. Merci pour la piste du..READ_TABLE..Je vais essayer cela!
A
February 18th, 2006 at 8:50 pm
Mister renet,
May be this “code” can help you….
“blabla.pachoud.siemens.fr”, “SYSNR”=>”30″, “CLIENT”=>”212″, “USER”=>”devpro”, “PASSWD”=>”devine_petit_malin”, “CODEPAGE”=>”1100″);
$rfc = saprfc_open ($login );
if (! $rfc ) { echo “RFC connection failed”; exit; }
$fce = saprfc_function_discover($rfc,”BAPI_MATERIAL_GETLIST”);
if (! $fce ) { echo “Discovering interface of function module failed”; exit; }
//saprfc_import ($fce,”MAXROWS”,”");
saprfc_table_append ($fce,”MATNRSELECTION”,
array (“SIGN”=>”I”,”OPTION”=>”BT”,”MATNR_LOW”=>”1FK7043-7AK71-1AG0″,”MATNR_HIGH”=>”1FK7060-5AF71-1EH3″));
$rfc_rc = saprfc_call_and_receive ($fce);
if ($rfc_rc != SAPRFC_OK) {
if ($rfc == SAPRFC_EXCEPTION ) echo (“Exception raised: “.saprfc_exception($fce));
else echo (saprfc_error($fce)); exit; }
$rows = saprfc_table_rows ($fce,”RETURN”);
if ($rows){
for ($i=1;$i”); }
}
$rows = saprfc_table_rows ($fce,”MATNRLIST”);
for ($i=1;$i”; }
saprfc_function_free($fce);
saprfc_close($rfc);
A
February 18th, 2006 at 8:52 pm
error, il manque du code ….
“sdso28u.par.siemens.fr”, “SYSNR”=>”30″, “CLIENT”=>”212″, “USER”=>”dev10″, “PASSWD”=>”paspourtoi”, “CODEPAGE”=>”1100″);
$rfc = saprfc_open ($login );
if (! $rfc ) { echo “RFC connection failed”; exit; }
$fce = saprfc_function_discover($rfc,”BAPI_MATERIAL_GETLIST”);
if (! $fce ) { echo “Discovering interface of function module failed”; exit; }
//saprfc_import ($fce,”MAXROWS”,”");
saprfc_table_append ($fce,”MATNRSELECTION”,
array (“SIGN”=>”I”,”OPTION”=>”BT”,”MATNR_LOW”=>”1FK7043-7AK71-1AG0″,”MATNR_HIGH”=>”1FK7060-5AF71-1EH3″));
$rfc_rc = saprfc_call_and_receive ($fce);
if ($rfc_rc != SAPRFC_OK) {
if ($rfc == SAPRFC_EXCEPTION ) echo (“Exception raised: “.saprfc_exception($fce));
else echo (saprfc_error($fce)); exit; }
$rows = saprfc_table_rows ($fce,”RETURN”);
if ($rows){
for ($i=1;$i”); }
}
$rows = saprfc_table_rows ($fce,”MATNRLIST”);
for ($i=1;$i”; }
saprfc_function_free($fce);
saprfc_close($rfc);
–>
“”
February 18th, 2006 at 8:57 pm
en fait je n’arrive pas à te transmettre le debut
car il s’agit de balise php que ton “blob” interprete
au debut c’est la chaine de connexion. que tu connais je pense …
un truc du type :
February 18th, 2006 at 8:59 pm
bon je crois que c’est le signe “inferieur ” debut de balise qu’il n’aime pas…
je repete donc
“inferieur” “point d’interro”
$login = array (“ASHOST”
etc…
February 20th, 2006 at 8:20 pm
C’est bon Jako! J’ai fait quelques modifications au code que tu as ajoute a ce billet et ca marche nickel! – Merci pour tes suggestions. Je vais tres prochainement faire un billet rien que pour ca.
A
February 23rd, 2006 at 1:15 pm
[...] This post deals with using PHP to communicate with SAP, so you’ll need to have acces to a SAP system if you want to reproduce this. All-right, some time ago I wrote a post in which I said that I wanted to use a BAPI (or other) to retrieve a list of material numbers from a SAP client and build a select list as opposed to hard coding it in my PHP script. At the time my other options might have been to upload a list of material numbers into an SQL database or hard code a list of materials numbers in my script : The downside here being that you could hardly call this dynamic. Anyway, thanks to Jako (Jopac) and his valuable contributions , success is the name of the game – nothing is going to stop me now! I’m kinda eager to post this , so you’ll have to wait a bit longer for the complete code where I: [...]
May 13th, 2006 at 6:43 pm
[...] Don’t let the title fool you, I’m not quite there yet. I’ve already written a few posts that dealt with integrating SAP and PHP (which you can find here and here to get you started), but I thought it was time to take it to another level. So what I’ve done here is to try and build a portal of sorts and bundled together scripts that will allow one to perform various request to a SAP system. All the scripts I’ve written so far deal with material masters in one way or another. [...]
October 31st, 2007 at 3:37 pm
Dear sir,
I am interested with the code you have preview in PHP on about using transaction code.I can have more information and the code of this. Now a day I am developing Leave management in PHP.
thanks
minaxi
October 31st, 2007 at 3:41 pm
Minaxi, the code is no longer available.
October 31st, 2007 at 4:47 pm
Dear Sir,
I am trying to develop leave management progrom.I want the data of employee but prog. doen’t display. my code is as below. Please guide me where I am wrong.
“” // application server
,”SYSNR”=>”00″ // system number
,”CLIENT”=>”900″ // client
,”USER”=>”" // user
,”PASSWD”=>”" // password
,”show_errors”=>false // let class printout errors
,”debug”=>true)) ; // detailed debugging information
// saprfc-class-library
$stno = $pernr;
$rfc = saprfc_open ($login);
if (! $rfc )
{
echo “RFC connection failed with error:”.saprfc_error();
exit;
}
$fce = saprfc_function_discover($rfc, “BAPI_EMPLOYEE_CHECKEXISTENCE”);
if (! $fce ) {
echo “Discovering interface of function module RFC_READ_REPORT failed”;
exit;
}
saprfc_import ($fce,”NUMBER”,$pernr);
$rc = saprfc_call_and_receive ($fce);
if ($rfc_rc != SAPRFC_OK)
{
if ($rfc == SAPRFC_EXCEPTION )
echo (“Exception raised: “.saprfc_exception($fce));
else
echo (“Call error: “.saprfc_error($fce));
exit;
}
$TRETURN = saprfc_export ($fce,”RETURN”);
IF ($TRETURN “”) {
echo $TRETURN;
}else{
$rfcfunction = “BAPI_EMPLOYEE_GETDATA”;
$resultstable = “ORG_ASSIGNMENT”;
$fce = saprfc_function_discover($rfc,$rfcfunction);
if (!$fce) {
echo “failed to discover rfc function”.saprfc_error($rfc);
exit(1);
}
$x = saprfc_import($fce,”EMPLOYEE_ID”,$pernr);
saprfc_table_init($fce,$resultstable);
$rfcresults =saprfc_call_and_receive($fce);
$results = array();
$numrows =saprfc_table_rows($fce,$resultstable);
echo $numrows;
echo “”;
for ( $i=1; $i$i$v2″;
}
}
}
saprfc_function_free($fce);
saprfc_close($rfc);
}else{
echo “”;
echo “”;
echo “ERP Staff No.
“;
echo “”;
echo “”;
}
?>
Thanks
Minaxi
June 19th, 2009 at 10:11 pm
Hi Could you please send me the code for the Stock Requirements list – php code.
Thanks in Advance.
Rgs
Jacob