Skip to Content

How to call RFC in loop efficiently

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();
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.SetValue("SIGN", "I");
tabSelOrderNumberRange.SetValue("OPTION", "BT");
tabSelOrderNumberRange.SetValue("LOW", "000000100000");
tabSelOrderNumberRange.SetValue("HIGH", "000000199999");

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

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);
dtProdOrdGetDetail = bapiProdOrdGetDetail.GetTable("OPERATION").ToDataTable("x");

return dtProdOrdGetDetail;

Add comment
10|10000 characters needed characters exceeded

  • Follow
  • Get RSS Feed

2 Answers

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

    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.

    Add comment
    10|10000 characters needed characters exceeded

  • Apr 12, 2018 at 11:10 AM


    Add comment
    10|10000 characters needed characters exceeded