How to fetch data from SAP system using sap .net connector?

前端 未结 1 1954
星月不相逢
星月不相逢 2020-12-16 06:40

I am developing an windows application, here I wanna extract data from sap system and show it in a datagridview... I have extracted the column names alone like name, city a

相关标签:
1条回答
  • 2020-12-16 07:09

    untested, but this is essentially how it works:

    first create the connection

    RfcDestination destination = mDestinationManager.GetDestination("MYDESTINATION");
    

    create the function

    IRfcFunction readTable = destination.Repository.CreateFunction("RFC_READ_TABLE");
    

    set parameters before invoking the function

    // we want to query table KNA1
    readTable.SetValue("QUERY_TABLE", "KNA1");
    // fields will be separated by semicolon
    readTable.SetValue("DELIMITER", ";");
    

    table parameters are created by retrieving the table from the function, using the Append() function to add a row and using SetValue() to set values for individual columns in that row

    // Parameter table FIELDS contains the columns you want to receive
    // here we query 2 fields, KUNNR and NAME1
    IRfcTable fieldsTable = readTable.GetTable("FIELDS");
    fieldsTable.Append();
    fieldsTable.SetValue("FIELDNAME", "KUNNR");
    fieldsTable.Append();
    fieldsTable.SetValue("FIELDNAME", "NAME1");
    
    // the table OPTIONS contains the WHERE condition(s) of your query
    // here a single condition, KUNNR is to be 0012345600
    // several conditions have to be concatenated in ABAP syntax, for instance with AND or OR
    IRfcTable optsTable = readTable.GetTable("OPTIONS");
    optsTable.Append();
    optsTable.SetValue("TEXT", "KUNNR = '0012345600'");
    

    call the function

    readTable.Invoke(destination);
    

    process the data

    IRfcTable dataTable = readTable.GetTable("DATA");
    
    foreach(var dataRow in dataTable)
    {
        string data = dataRow.GetValue("WA");
        string[] columns = data.Split(';');
    }
    
    0 讨论(0)
提交回复
热议问题