on 06-17-2016 12:11 PM
Hello,
I am having huge problems with acquiring order cost data to my program in C#.
I run the "BAPI_PRODORD_COSTING" remote function module. I get an answer that Costing was executed. I also get all suborders from selected order, their texts and numbers.
IRfcFunction orderCosting = rfcRepo.CreateFunction("BAPI_PRODORD_COSTING");
IRfcTable orders = orderCosting.GetTable("ORDERS");
orders.Append();
codePO = codePO.PadLeft(12, '0'); //trailing zeros
orders.SetValue("ORDER_NUMBER", codePO);
orderCosting.Invoke(rfcDestination);
But regardless how much I try I can't get the actual costs.
I tried to get App log with "/SDF/GET_APP_LOG" and a log handle passed from previous function.
All I get is only some unclear data messages which does not correspond to actual cost data I'd expect.
Please help.
Thank you
Actually I need a RFC which implements KOB1 transaction.
It is also possible to get this information via CO03 -> Goto -> Cost -> Analysis OR also S_ALR_87013019.
But I cant find a way to this info with Remote Function module call.
Please help.
Thank you.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Done it by myself.
I read OBJNR (Object number) from AUFK table for AUFNR order number.
Than I passed OBJNR to COEP table and got all records for selected order.
At last I summarise records depending on the sign. Here is the function:
public static double costEstimate(string productionOrder)
{
RfcDestination rfcDestination;
double sumCost=0;
try
{
rfcDestination = RfcDestinationManager.GetDestination(destConfigName);
if (rfcDestination != null)
{
RfcRepository rfcRepo = rfcDestination.Repository; //create repository
productionOrder = productionOrder.PadLeft(12, '0'); //trailing zeros
#region READ_TABLE_AUFK
IRfcFunction readTable1 = rfcRepo.CreateFunction("BBP_RFC_READ_TABLE");
//IMPORTING
readTable1.SetValue("QUERY_TABLE", "AUFK");
readTable1.SetValue("ROWCOUNT", "1");
readTable1.SetValue("DELIMITER", ";");
//Desired fields in the answer
IRfcTable fieldsTable = readTable1.GetTable("FIELDS");
fieldsTable.Append();
fieldsTable.SetValue("FIELDNAME", "OBJNR");
//"SQL" like clauses
var options1 = readTable1.GetTable("OPTIONS");
options1.Append();
options1.SetValue("TEXT", "AUFNR EQ '" + productionOrder + "'");
//INVOKE
readTable1.Invoke(rfcDestination);
//EXPORTING
var data = readTable1.GetTable("DATA");
string OBJNR = data[0].GetString("WA"); // <-here is the object number we were searching for
#endregion READ_TABLE_AUFK
#region READ_TABLE_COEP
IRfcFunction readTable2 = rfcRepo.CreateFunction("BBP_RFC_READ_TABLE");
//IMPORTING
readTable2.SetValue("QUERY_TABLE", "COEP");
readTable2.SetValue("DELIMITER", ";");
//"SQL" like clauses
var options2 = readTable2.GetTable("OPTIONS");
options2.Append();
options2.SetValue("TEXT", "OBJNR EQ '" + OBJNR + "'");
//Desired fields in the answer
var flds = readTable2.GetTable("FIELDS");
flds.Append();
flds.SetValue("FIELDNAME", "WOGBTR"); //Total Value in Object Currency
flds.Append();
flds.SetValue("FIELDNAME", "TIMESTMP");//Timestamp
//INVOKE
readTable2.Invoke(rfcDestination);
//EXPORTING
var d = readTable2.GetTable("DATA");
#endregion READ_TABLE_COEP
#region SUMM_COMPONENTS
foreach (var v in d)
{
string[] answers = v.GetString("WA").Split(';'); //split by previously selected delimiter
double currentElementCost = double.Parse(answers[0].Substring(0, 14).Replace('.', ',')); //parse answer from string to double, replace . with , for correct parsing
bool add = answers[0].Substring(14, 1) == "-" ? false : true; //check the sign, if ' ' add, if '-' subtract
if (add) sumCost += currentElementCost;
else sumCost -= currentElementCost;
}
#endregion SUMM_COMPONENTS
}
}
catch (Exception ex)
{
Debug.WriteLine(ex.Message);
}
return sumCost;
}
I hope it helps anyone.
More information about COEP here.
User | Count |
---|---|
85 | |
10 | |
10 | |
10 | |
7 | |
6 | |
6 | |
5 | |
4 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.