cancel
Showing results for 
Search instead for 
Did you mean: 

Delete a record from SAP using SAPRFC

Former Member
0 Kudos

Hello experts,

I am trying to delete a record from SAP using SAPRFC.

I tried this but I doesn't work

Thanks a lot for you help

require_once("../saprfc/saprfc.php");
require_once("./loginsap.php");

$fce = saprfc_function_discover($rfc, "BAPI_PRODORDCONF_CREATE_TT");
if ($fce) echo "OK fce<br>";
$function = saprfc_table_remove ($fce,"Timetickets", array(
	"conf_no"=>"1067124",
	"conf_cnt"=>"1"
	));	
saprfc_call_and_receive($fce);
$odetailreturn = saprfc_table_read($fce, "DETAIL_RETURN", 1);

if($odetailreturn['TYPE'] == "I") {
	 $function = saprfc_function_discover $rfc, "BAPI_TRANSACTION_COMMIT");
	saprfc_call_and_receive($function); 
}

Accepted Solutions (1)

Accepted Solutions (1)

former_member583013
Active Contributor
0 Kudos

Ok...I don't access to my system right now...But it should be something like this...


require_once("../saprfc/saprfc.php");
require_once("./loginsap.php");

$fce = saprfc_function_discover($rfc, "BAPI_PRODORDCONF_CREATE_TT");
if ($fce) echo "OK fce<br>";
saprfc_table_init ($this->fce,"DETAIL_RETURN");
saprfc_import ($this->fce,"Timetickets", array(
	"conf_no"=>"1067124",
	"conf_cnt"=>"1"
	));

$rfc_rc = saprfc_call_and_receive (fce);
$odetailreturn = saprfc_table_rows (fce,"DETAIL_RETURN");

$odetailreturn = saprfc_table_read (fce,"DETAIL_RETURN",1);

if($odetailreturn['TYPE'] == "I") {
	 $function = saprfc_function_discover $rfc, "BAPI_TRANSACTION_COMMIT");
	saprfc_call_and_receive($function); 
}

You can check this blog...

[Tasting the mix of PHP and SAP|https://weblogs.sdn.sap.com/pub/wlg/3170]

It was the first I wrote on SCN...And the most simple so far -;) Good for newcomers -:D

Greetings,

Blag.

Former Member
0 Kudos

Thanks a lot for your help.

I am looking to REMOVE à record from an sap table (Timetickets). I found the function saprfc_table_remove but I don't know how to use it... I tried with several cases but it doesn't work...

If you have an example of a program it will be so cool.

Thanks

former_member583013
Active Contributor
0 Kudos

I have never used saprfc_table_remove...But according to documentation Remove a line of an internal table So, it's not going to help you to delete a record from the database...

What I would do is to create an RFC Function Module to delete record from that table...So you would need to pass the keys and delete the record...

Maybe this could help you out...It's an SM30 emulator...

[Tasting the mix of PHP and SAP - Volume 2|https://www.sdn.sap.com/irj/sdn/weblogs?blog=/pub/wlg/3254] [original link is broken] [original link is broken] [original link is broken];

Greetings,

Blag.

Former Member
0 Kudos

Thanks a lot for your help...

I tried with your code but I'm still having problems

Can you give me an exemple of a function that delete a record from a table.

Tha table is Timetickets

I must give the parameters conf_no and conf_cnt to the function id order to delete the line conf_no/conf_cnt

Best regards

Zakaria

Former Member
0 Kudos

Normally, to cancel a line from a table, I must call the bapi BAPI_PRODORDCONF_CANCEL

I tried with this code, no error, but no line canceled 😐

Thanks again for your help

require_once("../saprfc/saprfc.php");
require_once("./loginsap.php");
require_once("../saprfc/sapclasses/sap.php");

$fce = saprfc_function_discover($rfc, "BAPI_PRODORDCONF_CANCEL");
saprfc_import ($fce,array("CONF_NO", "CONF_COUNT"), array ("1067124","1"));
saprfc_call_and_receive($fce);
$function = saprfc_function_discover($rfc, "BAPI_TRANSACTION_COMMIT");
saprfc_call_and_receive($function);

former_member583013
Active Contributor
0 Kudos

According to the BAPI, it should be...


require_once("../saprfc/saprfc.php");
require_once("./loginsap.php");
require_once("../saprfc/sapclasses/sap.php");
 
$fce = saprfc_function_discover($rfc, "BAPI_PRODORDCONF_CANCEL");
saprfc_import ($fce,array("CONFIRMATION", "CONFIRMATIONCOUNTER"), array ("1067124","1"));
saprfc_call_and_receive($fce);
$function = saprfc_function_discover($rfc, "BAPI_TRANSACTION_COMMIT");
saprfc_call_and_receive($function);

AFAIK, you must use the same names as in the BAPI -;) Hope this helps...

Greetings,

Blag.

Former Member
0 Kudos

No error but no line is cancelled on SAP 😐

former_member583013
Active Contributor
0 Kudos

Ok...This is ging to hard as I don't have a PHP installation at work...

You passing this...


saprfc_import ($fce,array("CONF_NO", "CONF_COUNT"), array ("1067124","1"));

But according to BAPI....

CONFIRMATION --> NUMC (10)

CONFIRMATIONCOUNTER --> NUMC (8)

Have you tried with this???


saprfc_import ($fce,array("CONF_NO", "CONF_COUNT"), array ("0001067124","00000001"));

Sometimes you need to fill the params with leading zeros...

Greetings,

Blag.

Answers (2)

Answers (2)

Former Member
0 Kudos

With SAPRFC to remove item with @saprfc_table_remove it's wouldn't work.

*You should use the @saprfctable_append.*_

require_once("../saprfc/saprfc.php");

require_once("./loginsap.php");

/**

  • your code

*/

$fce = saprfc_function_discover($rfc, "BAPI_PRODORDCONF_CREATE_TT");

if ($fce) echo "OK fce<br>";

$function = saprfc_table_remove ($fce,"Timetickets", array(

"conf_no"=>"1067124",

"conf_cnt"=>"1"

));

saprfc_call_and_receive($fce);

$odetailreturn = saprfc_table_read($fce, "DETAIL_RETURN", 1);

if($odetailreturn['TYPE'] == "I") {

$function = saprfc_function_discover $rfc, "BAPI_TRANSACTION_COMMIT");

saprfc_call_and_receive($function);

}

/**

  • try this

*/

$fce = @saprfc_function_discover($rfc, "BAPI_PRODORDCONF_CREATE_TT");

if ($fce) echo "OK fce<br>";

$init = @saprfc_table_init ($fce,"Timetickets");

// with zero BAPI is gonna remove it.

$data = array(

* "conf_no"=>"1067124",*

* "conf_cnt"=>"0"*

* );*

$export = @saprfc_table_append($fce,"Timetickets",$data);

$init = @saprfc_table_init ($fce,"DETAIL_RETURN");

$result = @saprfc_call_and_receive($fce);

// row the tables

$rows = @saprfc_table_rows ($fc,"Timetickets");

for ($i=1;$i<=$rows;$i++){

$data[] = @saprfc_table_read ($fc,"Timetickets",$i);

}

//var_dump($data); exit;

$messages = @saprfc_table_rows ($fc,"DETAIL_RETURN");

for ($i=1;$i<=$messages ;$i++){

$data[] = @saprfc_table_read ($fc,"DETAIL_RETURN"$i);

}

Hope it's help.

Regards

Gede!

Edited by: Gede Suartana on Oct 17, 2008 10:54 AM

Former Member
0 Kudos

I tried with several ideas but it still doesn't work...

I really need a help to carry on my work...

Thanks