0

I want to use columns in a function and the columns may differ from time to time. So I want to pass the columns into the function when calling the function, what datatype can be used in the function.

The following is the code that i want to put into the function and compute_page is the column name:

if dw_report.Object.compute_page[ll_first_row] <> dw_report.Object.compute_page[ll_last_row] then

Also, I want to do the same thing but this time is set the column value. I tried to use SetItem(), SetText(), SetValue(), but none of the function can achieve the expected result except using dwcontrol.Object.columnname[i] to set the value.

Thanks

calvinyankf
  • 35
  • 2
  • 6

1 Answers1

2

Instead of using the .object notation to access the column, use the GetItemxxx(), eg:

if dw_report.getitemnumber(ll_first_row, "compute_page") <> dw_report.getitemnumber(ll_last_row, "compute_page") then

Just replace the "compute_page" litteral in the example by a string argument of your function.

Beware that the GetItemxx() call must match the actual column data type, so you need to check for the result of dw_report.describe(ls_your_column_name+".coltype") to call one of GetItemNumber(), GetItemString(), GetItemDecimal(), GetItemDate(), GetItemDatetime() or your application will crash.

Seki
  • 11,135
  • 7
  • 46
  • 70
  • 1
    You'll also find the GetItemXXX() faster and more memory efficient than the .object. notation. It won't be a big deal if the script is called just once, but in a loop over a large data set, you'll notice the difference. – Terry Feb 21 '14 at 13:36
  • I Totally agree with @Terry, it seems that the `.object` notation is using an OLE layer to access the datawindow internals and tends to slow down the data process. – Seki Feb 21 '14 at 13:42
  • Thank you very much, but another similar question: – calvinyankf Feb 24 '14 at 01:58
  • I want to set a value to a column in the same function, but it does not take effect when using SetItem(), SetColumn(), SetValue(). However, using the .object. notation is success. Any idea?? Thanks – calvinyankf Feb 24 '14 at 02:00
  • @calvinyankf: do you get any return code or sql error message that could give some clue? – Seki Feb 25 '14 at 07:59
  • The problem was solved since the column and the value inside the SetItem() function are of different type. Thanks – calvinyankf Feb 26 '14 at 01:36