1

我有一个带有 requestDetails.cs,SAPconnect.cs,login.aspx.cs,request.aspx.cs 的 .net 应用程序。request.aspx 页面包含员工 ID、姓名等字段。我想将 request.aspx 文件的员工 ID 字段连接到 SAP 表字段。我使用 SAP .NET 连接器。我对每个文件的编码如下。

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;

}

登录.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);
}

请求详细信息.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...
        }
    }
}

但是我收到这样的错误:

容器元数据 ZSAVE 的元素 ZHELP_REQTAB 未知

我想将数据保存到 SAP 表中zhelp_reqtab。谁能告诉我我在哪里做错了?

4

1 回答 1

1

我意识到这是一个非常古老的帖子,但我在搜索我自己的一些东西时登陆了它。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()
于 2014-12-19T15:40:35.290 回答