You can try this.. I'm using these DLLs for this which comes with SAP Connector
你可以尝试这个..我正在使用SAP Connector附带的这些DLL
- rscp4n.dll
- sapnco.dll
- sapnco_utils.dll
If you need to call an SAP transaction using these connection details you can try this..
如果您需要使用这些连接详细信息调用SAP事务,可以尝试这样做..
public void ExecuteTransaction(string tCode, string input)
{
int sub = 0;
try
{
tCode = "YOUR Transaction Code";
RfcConfigParameters rfc = new RfcConfigParameters();
rfc.Add(RfcConfigParameters.Name, "BOXName");
rfc.Add(RfcConfigParameters.AppServerHost, "HOST");
rfc.Add(RfcConfigParameters.SAPRouter, "YOUR ROUTER STRING");
rfc.Add(RfcConfigParameters.Client, "CLIENT");
rfc.Add(RfcConfigParameters.UseSAPGui, "1");
rfc.Add(RfcConfigParameters.User, "SAP USERNAME");
rfc.Add(RfcConfigParameters.Password, "PW");
rfc.Add(RfcConfigParameters.SystemNumber, "SYS NUMBER");
rfc.Add(RfcConfigParameters.Language, "EN");
rfc.Add(RfcConfigParameters.PoolSize, "5");
//rfc.Add(RfcConfigParameters.IdleCheckTime, "0");
RfcDestination rfcDest = RfcDestinationManager.GetDestination(rfc);
//rfcDest.Ping();
RfcRepository rfcRep = rfcDest.Repository;
IRfcFunction funcArtikel = rfcRep.CreateFunction("ABAP4_CALL_TRANSACTION");
//IRfcTable itab = funcArtikel.GetTable("SPAGPA_TAB");
funcArtikel.SetValue("TCODE", tCode);
funcArtikel.SetValue("MODE_VAL", "A");
funcArtikel.SetValue("UPDATE_VAL", "A");
funcArtikel.SetValue("SKIP_SCREEN", "X");
//itab.Append();
//itab.SetValue("PARID", "PARAMETER NAME");
//itab.SetValue("PARVAL", VALUE);
//funcArtikel.SetValue("SPAGPA_TAB", itab);
funcArtikel.Invoke(rfcDest);
}
catch (Exception ex)
{
lblError.Text = ex.ToString();
//throw ex;
}
}
And here I've commented some code because it is used to get some values ( set of data ) from SAP using RFC Table if you need you can enable them also.
在这里我评论了一些代码,因为它用于从SAP使用RFC表获取一些值(数据集),如果需要,也可以启用它们。
And don't change the following code set. It is the default SAP transaction for the RFC calls.You can change whatever the TCODE you need.
并且不要更改以下代码集。它是RFC调用的默认SAP事务。您可以更改所需的TCODE。
IRfcFunction funcArtikel = rfcRep.CreateFunction("ABAP4_CALL_TRANSACTION");
//IRfcTable itab = funcArtikel.GetTable("SPAGPA_TAB");
funcArtikel.SetValue("TCODE", tCode);
funcArtikel.SetValue("MODE_VAL", "A");
funcArtikel.SetValue("UPDATE_VAL", "A");
funcArtikel.SetValue("SKIP_SCREEN", "X");
And if you retrieving some data using IrfcTable you may need to convert IRfcTable to DataTable for that you can use this..
如果你使用IrfcTable检索一些数据,你可能需要将IRfcTable转换为DataTable,你可以使用它。
public static class IRfcTableExtentions
{
///
/// Converts SAP table to .NET DataTable table
///
/// The SAP table to convert.
///
public static DataTable ToDataTable(this IRfcTable sapTable, string name)
{
DataTable adoTable = new DataTable(name);
//... Create ADO.Net table.
for (int liElement = 0; liElement