‎2012 Feb 05 6:12 AM
Hello,
I am trying to retrive the data using RFC_READ_TABLE can any one help me with sample code in c#.net. I am creating a web application which needs to retrieve some information from the clients SAP System.
Please help.
Thanks,
Snehal
‎2012 Feb 06 4:13 PM
hi,
For integration between sap and non-sap system , you should use web services. Write a web service in sap system that retrieve data from sap tables. then call it in your c# web application.
to give an example;
write a remote function named ZWS_001 that imports a material parameter and exports the mara data of material. go to se80 create an web-service for this function module.
then go to your web application call your web service by giving the material number. that's it.
<removed by moderator>
Edited by: Thomas Zloch on Feb 6, 2012 8:26 PM
‎2012 Mar 09 5:43 AM
Hi,
Thanks for you reply.
What i am trying to do is call rfc_read_table with the help of Nco 3.0 And i need a sample of code to call a particular table from SAP and Display that Data into Grid in ASP.NET Application.
Can anyone help me on this, I am just starting and this thing has stuck me from a long time.
Thanks
Snehal
‎2012 Feb 06 4:28 PM
Hi Sneha,
Did you check with the available information.Make an RFC and try.
Regards,
Madhu.
‎2012 Feb 07 4:56 AM
Hi,
Check the bellow link for using the required FM in C#
http://www.mycsharp.de/wbb2/thread.php?postid=3496671
Regards,
Goutam Kolluru.
‎2012 Sep 01 11:32 PM
Following code should get you headed in the right direction:
//ABAP_APP_SERVER = your app server;
RfcDestination rfcDest = RfcDestinationManager.GetDestination(ABAP_APP_SERVER);
if (rfcDest != null)
{
try
{
RfcRepository repo = rfcDest.Repository;
IRfcFunction rfcFunct = repo.CreateFunction("RFC_READ_TABLE"); //RFC
// enter your parameters format: ("Param1", "Value1");
rfcFunct.SetValue("QUERY_TABLE", TableNameToQuery);
if (maxRowCount > 0)
rfcFunct.SetValue("ROWCOUNT", maxRowCount);
IRfcTable importProfiles = rfcFunct.GetTable("DATA");
rfcFunct.Invoke(rfcDest);
Thats it! then do something with the return: i.e.
Convert return to data grid format, then set the datagrid:
IRfcTableView i_rfc_view1 = (importProfiles asISupportTableView).DefaultView;
[dataGridViewNAME].DataSource = i_rfc_view1;
Note this function module returns a structure which is difficult to work with.
I would highly recommend background workers to keep a responsive gui. Do research on background tasks, (InvokeRequired)
The only time consuming part is creating the RFC thread safe view updates but I assure you its worth the effort.
‎2014 Mar 18 11:50 AM
This code is not working ...
I have checked the Data count, its 0...
Whether we should add datas to the DATA or it will be there normally?
‎2014 Mar 18 1:32 PM
Need some more specifics to be of assistance with your issue. Are you inquiring if the code is correct or the data in the test table from my screenshot (SFLIGHT) is not populated on your system?
If the former, can you be a little more specific and if possible, paste more details of the code you are working with.
If the latter, have you logged into the client and manually browsed the table (with se16 / se16n) to see if your table has data? search SCN for abap reports to populate the tables you need if no data is returned.
‎2014 Mar 18 1:48 PM
Yeah I have seen using GUI, the table which I want consists of 6,615 entries.
RfcRepository repo = rfcDest.Repository;
IRfcFunction customerList = repo.CreateFunction("RFC_READ_TABLE");
customerList.SetValue("QUERY_TABLE", txttableadd.Text.ToString());
customerList.SetValue("DELIMITER", ";");
customerList.SetValue("ROWCOUNT", "5");
customerList.SetValue("NO_DATA", "FALSE");
customerList.Invoke(rfcDest);
IRfcTable addressData = customerList.GetTable("FIELDS");
customerList.Invoke(rfcDest);
int j = addressData.RowCount;
for (int i = 0; i < j; i++)
{
listallcolumn.Items.Add(addressData[i].GetString("FIELDNAME"));
}
This code retrieved the column names perfectly, now I wanna get those values under some column names, in a datagridview or listbox...
I tried to use your code, but it shows data count as 0
‎2014 Mar 19 1:55 PM
Sorry man!!
Your code worked!!
Since I set the No_DATA: False
it didnt count the data rows now it's fine
Thanks a lot mate
‎2014 Mar 18 2:58 PM
Hi Snehal,
Try the below code.
//connection to RFC
RfcDestination prd = RfcDestinationManager.GetDestination("SE37");
RfcRepository repo = prd.Repository;
IRfcFunction fn = repo.CreateFunction("Z_TEST_INTERFACE_OUT");
string date = "05/10/2012";
DateTime dt = Convert.ToDateTime(date);
fn.SetValue("CREDAT", dt);
fn.SetValue("MESTYP", "LOIPRO");
fn.Invoke(prd);
IRfcTable it1 = fn.GetTable("IT_HEADER");
//string s1 = it1.GetValue("DOCNUM").ToString();
//Response.Write(it1.GetString(s1) + System.Environment.NewLine);
IRfcTableView view = (it1 as ISupportTableView).DefaultView;
this.GridView1.DataSource = view;
DataSet ds = new DataSet();
Response.Write("Header Data" + System.Environment.NewLine);
for (int index = 0; index < it1.RowCount; ++index)
{
string s1 = it1.GetValue("DOCNUM").ToString();
string s2 = it1.GetValue("AUFNR").ToString();
string s3 = it1.GetValue("GAMNG").ToString();
string s4 = it1.GetValue("GMEIN").ToString();
string s5 = it1.GetValue("MATNR").ToString();
Response.Write(s1 + System.Environment.NewLine);
Response.Write(s2 + System.Environment.NewLine);
Response.Write(s3 + System.Environment.NewLine);
Response.Write(s4 + System.Environment.NewLine);
Response.Write(s5 + System.Environment.NewLine);
}
IRfcTable it2 = fn.GetTable("IT_ITEM");
Response.Write("Item Data" + System.Environment.NewLine);
for (int index = 0; index < it2.RowCount; ++index)
{
string s11 = it2.GetValue("DOCNUM").ToString();
string s12 = it2.GetValue("VORNR").ToString();
string s13 = it2.GetValue("MATNR").ToString();
string s14 = it2.GetValue("MEINS").ToString();
string s15 = it2.GetValue("BDMNG").ToString();
string s16 = it2.GetValue("ARBPL").ToString();
Response.Write(s11 + System.Environment.NewLine);
Response.Write(s12 + System.Environment.NewLine);
Response.Write(s13 + System.Environment.NewLine);
Response.Write(s14 + System.Environment.NewLine);
Response.Write(s15 + System.Environment.NewLine);
Response.Write(s16 + System.Environment.NewLine);
}
Regards,
K.Srikanth Reddy.
‎2014 Mar 18 3:27 PM
I am not following your reply as the issue is using the RFC function module specifically.you also left your custom function module which he will not have: "Z_TEST_INTERFACE_OUT".
Jeswin-
I would use pipe delimited personnally, on the rfc: rfcFunct.SetValue("DELIMITER", "|");
when you process the code returned from the RFC_READ_TABLE after you have added the columns to your datatab, loop through and split at the delimiter after your loop add convert the row:
RfcElementMetadata metadata = functionRfcTable.GetElementMetadata(j);
lv_row = row.GetString(metadata.Name);
string lv_row_no_space = lv_row;
string[] split = lv_row.Split(new Char[] { '|' }); //ensure this delimiter matches what was added to rfc call
foreach (string lv_value in split)
{
if (lv_value.Trim() != "")
{
string result = lv_value.Replace(" ", ""); //"remove whitespaces
//add values to your datatab columns using result
}
}
‎2014 Mar 19 5:07 AM
Hi Robert,
Thankx for your reply, your code is correct
According to your code, its getting the values from these rows, like MANDT, 000000, 000003, C, Client and so on...
FIELD FIELDNAME=MANDT FIELD OFFSET=000000 FIELD LENGTH=000003 FIELD TYPE=C FIELD FIELDTEXT=Client
FIELD FIELDNAME=BNAME FIELD OFFSET=000004 FIELD LENGTH=000012 FIELD TYPE=C FIELD FIELDTEXT=User Name in User Master Record
FIELD FIELDNAME=PROFILE FIELD OFFSET=000017 FIELD LENGTH=000012 FIELD TYPE=C FIELD FIELDTEXT=Profile name
But I don't want the above values, I want the blow datas like 800, ARCHIEVE,IDES_ARCHIVE and so on next rows