Reputation: 49
I have a .net application with requestDetails.cs,SAPconnect.cs,login.aspx.cs,request.aspx.cs . The request.aspx page contains fields like employee id ,name etc. I want to connect the employee id field of request.aspx file to the SAP table field . I use SAP .NET connector.My coding for each file is as follows .
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...
}
}
}
But am getting an error like this:
Element ZHELP_REQTAB of container metadata ZSAVE unknown
I want to save the data to the SAP table zhelp_reqtab
. Can any one tell me where I'm doing wrong?
Upvotes: 1
Views: 1048
Reputation: 1608
I realize this is a very old post, but I landed on it in searching of some things of my own. SAP .Net Connector 3.0 can at times be very difficult to find information on so when I find an opportunity to share knowledge I try to do so. Basically what your error message is saying is that it cannot find a table that is named ZHELP_REQTAB, are you sure that's the Exact name of the table that's being returned. Is it possible that its a Structure rather than a Table? I would go to transaction SE37 in SAP and display that BAPI, from there you can see the exporting tables and structures and get the true names of those objects. Once you have that squared away to access those its actually very simple. Keep in mind a IRfcTable is basically a list of IrfcStructures, Also IRfcTables Implement IEnumerable so you can operate against with LINQ or if you prefer you can use a Foreach statement to Iterate. Also Be sure if a BAPI Generates a Standard RETURN Table for Error messages that you look at it first to make sure no errors took place. If a bapi generates that table Errors that occur inside of SAP outside the bounds of an ABAP Exception would be reported there and not throw an exception on your side. Below is an example of accessing table data.
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()
}
Or if it turns out to be a simple structure no loop s required
empid = helpreqStruct["empid field name in table"].GetString()
Upvotes: 1