cancel
Showing results for 
Search instead for 
Did you mean: 

How to call RFC in loop efficiently

0 Kudos

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;
}

Accepted Solutions (1)

Accepted Solutions (1)

weberpat
Contributor

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.

Answers (1)

Answers (1)

0 Kudos

Thanks.