2013-02-28 18 views
1

我有一個.net應用程序,其中包含requestDetails.cs,SAPconnect.cs,login.aspx.cs,request.aspx.cs。 request.aspx頁面包含諸如員工ID,姓名等字段。我想將request.aspx文件的員工ID字段連接到SAP表字段。我使用SAP .NET連接器。我爲每個文件編碼如下。使用SAP表字段連接.apsx字段

SAPconnect.cs

public class SAPsystemconnect:IDestinationConfiguration 
{ 
    public RfcConfigParameters GetParameters(string destinationName) 
    { 
     RfcConfigParameters parms = new RfcConfigParameters(); 
     if ("DEV".Equals(destinationName)) 
     { 

      parms.Add(RfcConfigParameters.AppServerHost, "ECC6"); 
      parms.Add(RfcConfigParameters.SystemNumber, "04"); 
      parms.Add(RfcConfigParameters.User, "sapuser"); 
      parms.Add(RfcConfigParameters.Password, "newmaars1"); 
      parms.Add(RfcConfigParameters.Client, "800"); 
      parms.Add(RfcConfigParameters.Language, "EN"); 
      parms.Add(RfcConfigParameters.PoolSize, "5"); 
      parms.Add(RfcConfigParameters.MaxPoolSize, "10"); 
      parms.Add(RfcConfigParameters.IdleTimeout, "600"); 

     } 
     return parms; 
    } 

    public bool ChangeEventsSupported() 
    { 
     //throw new NotImplementedException(); 
     return false; 
    } 

    public event RfcDestinationManager.ConfigurationChangeHandler ConfigurationChanged; 



} 

login.aspx.cs

protected void logon_Click(object sender, EventArgs e) 
    { 

     SAPsystemconnect sapconn = new SAPsystemconnect(); 
     RfcDestinationManager.RegisterDestinationConfiguration(sapconn); 
     RfcDestination rfcDest = null; 
     rfcDest = RfcDestinationManager.GetDestination("DEV"); 

     RequestDetails reqobj = new RequestDetails(); 
     reqobj.GetRequestDetails(rfcDest); 


     // RfcDestinationManager.UnregisterDestinationConfiguration(sapconn); 
     Response.Redirect("request.aspx"); 


      System.Environment.Exit(0); 
    } 

requestdetails.cs

public class RequestDetails 
{ 
    public string empid; //personnel numner 
    public string name; //name of the employee 
    public string department; //department of employee 
    public string descr; //description of help 
    public string problem; //problem 
    public string solution; //solution for the problem 
    public string status; //status of help 
    public string findings; //proble found during verification ; 
    public string resolution; //resolutions for problem detected ; 
    public string recommend; //recommended action 
    public string remarks; //remarks for work done; 
    public string feedback; //user feedback for work done; 
    public int dococde; //description of document code 
    public int auth1; //personnel number; 
    public int auth2; //personnel numnber; 
    public string sapcheck; //checkbox 
    public string othercheck;//checkbox 
    public string priority; //priority of request(HIGH,MED,LOW) 
    public string saptrans; //transaction drop down 
    public string tranreq; //request/task 
    public string followtrans; //follow transaction type 
    public string followdoc; //follow transaction doc number 



    public void GetRequestDetails(RfcDestination destination) 
    { 
     try 
     { 

      RfcRepository repo = destination.Repository; 
      IRfcFunction createRequest = repo.CreateFunction("ZSAVE"); 
      createRequest.Invoke(destination); 
      IRfcTable helpreqtab = createRequest.GetTable("ZHELP_REQTAB"); 
      RequestDetails reqobj = new RequestDetails(); 

      reqobj.empid = helpreqtab.GetString("ZREQ_EMPID"); 



     } 
     catch (RfcCommunicationException e) 
     { 

     } 
     catch (RfcLogonException e) 
     { 
      // user could not logon... 
     } 
     catch (RfcAbapRuntimeException e) 
     { 
      // serious problem on ABAP system side... 
     } 
     catch (RfcAbapBaseException e) 
     { 
      // The function module returned an ABAP exception, an ABAP message 
      // or an ABAP class-based exception... 
     } 
    } 
} 

,但我越來越喜歡這個

Element ZHELP_REQTAB of container metadata ZSAVE unknown 
錯誤0

我想將數據保存到SAP表zhelp_reqtab,任何人都可以告訴我哪裏出錯了?

回答

0

我意識到這是一個非常古老的帖子,但我登陸它尋找我自己的一些東西。 SAP .Net Connector 3.0有時可能很難找到信息,所以當我找到機會共享我嘗試這樣做的知識時。基本上你的錯誤信息是說它找不到名爲ZHELP_REQTAB的表,你確定這是返回的表的完全名稱。它可能是一個結構而不是表格?我會去SAP中的事務SE37並顯示該BAPI,從那裏您可以看到導出表和結構並獲取這些對象的真實名稱。一旦你有了這個方法來訪問那些其實很簡單的東西。請記住,IRfcTable基本上是IrfcStructures的列表,同時IRfcTables實現IEnumerable,因此您可以使用LINQ操作,或者如果您願意,可以使用Foreach語句來迭代。同時確保BAPI爲錯誤消息生成一個標準的返回表,您首先查看它以確保沒有錯誤發生。如果bapi生成該表,那麼SAP內部發生的錯誤將在ABAP異常的範圍之外進行報告,而不會在您身邊引發異常。以下是訪問表數據的示例。

foreach (IRfcStructure str in helpreqtab) 
{ 
    //You can use get string if thefield type is string, you would use the proper Getmethod based on type of the field. 
    empid = str["empid field name in table"].GetString() 
} 

或者,如果它原來是一個簡單的結構,沒有環小號需要

empid = helpreqStruct["empid field name in table"].GetString()