我正在尝试通过MVC3应用程序上的SAP Connector 3.0从SAP获取数据。
连接没有问题。
我的问题是,当我尝试从表中说的结构中设置值时
“表[STRUCTURE ZHRS_ABSENCES]:无法设置值(存储元素值的数组为null)”
我的代码如下:
//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
我不确定您使用的连接器,但是使用JCo时也有类似的常见误解。一个表参数可以容纳多行。通常,您必须在表格中添加一行。这可能会返回某种您可以填充的结构。 Also check this answer.
我认为您只需要在尝试调用SetValue之前追加一个新行
例如
absenceHoli.Append();
absenceHoli.SetValue("ColumnName", "0000483"); // Add further SetValue statements for further columns
[获得表结构后检查断点,可以得到列名,这可能比仅指定列索引更好。
就我而言,我需要使用Insert
:
absenceHoli.Insert();
absenceHoli.SetValue(..., ...);