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

View Entire Topic
0 Kudos

Thanks.