Accessing the items in a DataWindow
You can access data values in a DataWindow by using methods or
DataWindow data expressions. Both methods allow you to access data in
any buffer and to get original or current values.
The method you use depends on how much data you are accessing and
whether you know the names of the DataWindow columns when the script is
compiled.
For guidelines on deciding which method to use, see Accessing Data in Code in DataWindow Reference.
Using methods
There are several methods for manipulating data in a DataWindow
control.
These methods obtain the data in a specified row and column in a
specified buffer:
-
PowerBuilder
GetItemDate, GetItemDateTime, GetItemDecimal, GetItemNumber,
GetItemString, GetItemTime
This method sets the value of a specified row and column:
-
PowerBuilder
SetItem
For example, the following statement, using PowerBuilder syntax,
assigns the value from the empname column of the first row to the
variable ls_Name in the Primary buffer:
|
1 |
ls_Name = dw_1.GetItemString (1, "empname") |
This PowerBuilder statement sets the value of the empname column
in the first row to the string Waters:
|
1 |
dw_1.SetItem(1, "empname", "Waters") |
Uses
You call the GetItem methods to obtain the data that has been
accepted into a specific row and column. You can also use them to check
the data in a specific buffer before you update the database. You must
use the method appropriate for the column’s datatype.
For more information about the methods listed above, see Methods for the DataWindow Control in DataWindow Reference.
Using expressions
DataWindow data expressions refer to single items, columns, blocks
of data, selected data, or the whole DataWindow.
In PowerBuilder, you construct data expressions using dot
notation.
Expressions in
PowerBuilder
The Object property of the DataWindow control lets you specify
expressions that refer directly to the data of the DataWindow object in
the control. This direct data manipulation allows you to access small
and large amounts of data in a single statement, without calling
methods:
|
1 |
dw_1.Object.jobtitle[3] = "Programmer" |
The next statement sets the value of the first column in the first
row in the DataWindow to Smith:
|
1 |
dw_1.Object.Data[1,1] = "Smith" |
For complete instructions on how to construct DataWindow data
expressions, see Accessing Data in Code in DataWindow Reference.