Skip to Content
0

How to call RFC in loop efficiently

Aug 10, 2017 at 01:54 PM

94

avatar image

Hello guys!


I'm using the code below in C# with SAP .NetConnector to search some information of the production orders. My doubt is. How to make this more efficiently?

public static DataSet GetOrder()
{
if (!ECCDestinationConfig.conexaoSapInicializada)
{
ECCDestinationConfig cfg = new ECCDestinationConfig();
RfcDestinationManager.RegisterDestinationConfiguration(cfg);
}
RfcDestination SapRfcDestination = RfcDestinationManager.GetDestination("PS0");
RfcRepository SapRfcRepository = SapRfcDestination.Repository;

DataSet dsDados = new DataSet();
DataTable dtProdOrdGetDetailGeneral = new DataTable();

IRfcFunction bapiProdOrdGetList = SapRfcRepository.CreateFunction("BAPI_PRODORD_GET_LIST");

IRfcTable tabSelOrderNumberRange = bapiProdOrdGetList.GetTable("ORDER_NUMBER_RANGE");
tabSelOrderNumberRange.Append();
tabSelOrderNumberRange.SetValue("SIGN", "I");
tabSelOrderNumberRange.SetValue("OPTION", "BT");
tabSelOrderNumberRange.SetValue("LOW", "000000100000");
tabSelOrderNumberRange.SetValue("HIGH", "000000199999");

bapiProdOrdGetList.Invoke(SapRfcDestination);
DataTable dtProdOrdGetList = bapiProdOrdGetList.GetTable("ORDER_HEADER").ToDataTable("dtProdOrdGetList");

// expand the operations of this orders
foreach (DataRow rowTemp in dtProdOrdGetList.Rows)
{
string order = rowTemp["ORDER_NUMBER"].ToString();
dtProdOrdGetDetailGeneral.Merge(ExpandOperations(SapRfcDestination, SapRfcRepository, order));
}
dsDados.Tables.Add(dtProdOrdGetDetailGeneral);
dtListaOrdensFiltradas.Dispose();

return dsDados;
}

private static DataTable ExpandOperations(RfcDestination _SapRfcDestination, RfcRepository _SapRfcRepository, string _order)
{
IRfcFunction bapiProdOrdGetDetail = _SapRfcRepository.CreateFunction("BAPI_PRODORD_GET_DETAIL");
IRfcStructure structOrderObjects = bapiProdOrdGetDetail.GetStructure("ORDER_OBJECTS");
structOrderObjects.SetValue("OPERATIONS", "X");
DataTable dtProdOrdGetDetail = new DataTable();

bapiProdOrdGetDetail.SetValue("NUMBER", _order);
bapiProdOrdGetDetail.Invoke(_SapRfcDestination);
dtProdOrdGetDetail = bapiProdOrdGetDetail.GetTable("OPERATION").ToDataTable("x");

return dtProdOrdGetDetail;
}

10 |10000 characters needed characters left characters exceeded
* Please Login or Register to Answer, Follow or Comment.

2 Answers

Best Answer
avatar image
Former Member Aug 10, 2017 at 02:45 PM
0

I cannot comment on the efficiency of your C# code but functionally you will have to call the list bapi to get the production orders and then iterate over the result table to call the details bapi for every one of them if you want to stay in SAP standard. You could achieve a performance improvement by writing a custom wrapper function in ABAP that will do the second step on the backend and return to you the details for all identified orders. This would dramatically reduce the number of RFC calls and should under almost all circumstances yield better performance than individual RFC calls per order.

Share
10 |10000 characters needed characters left characters exceeded
Wesley Teles Apr 12 at 11:10 AM
0

Thanks.

Share
10 |10000 characters needed characters left characters exceeded