SAP connector 3.0 .NET set value on table structure
-
27-06-2021 - |
Question
I'm trying to get data from SAP via SAP Connector 3.0 on a MVC3 application.
There is no problems with the connection.
My problem is when I try to set values on a structure from a table it says
"TABLE [STRUCTURE ZHRS_ABSENCES]: cannot set value (array storing element values is null)"
My code is the following:
//create function
IRfcFunction function = conex.Repository
.CreateFunction("Z_HR_PORTAL_GET_EMPLOYEE_DATA");
//get table from function
IRfcTable absenceHoli = function.GetTable("P_ABSENCES");
//setting value to structure
absenceHoli.SetValue(0, "0000483"); //this is where the error occurs
Solution
I'm not sure about the connector you're using, but there's a similar common misunderstanding when using JCo. A table parameter can hold multiple lines. You'll usually have to append a line to the table. This will probably return some kind of structure that you'll be able to fill. Also check this answer.
OTHER TIPS
I think you just need to Append a new row before trying to call SetValue
e.g.
absenceHoli.Append();
absenceHoli.SetValue("ColumnName", "0000483"); // Add further SetValue statements for further columns
You can get the column names by putting a breakpoint on after you're got the Table Structure and examining it, which is probably nicer than just specifying column indexes.
In my case I needed to use Insert
:
absenceHoli.Insert();
absenceHoli.SetValue(..., ...);