- Syntax for one or all data items in a named column
- Syntax for selected data in a named column
- Syntax for a range of data in a named column
- Syntax for a single data item in a DataWindow
- Syntax for data in a block of rows and columns
- Syntax for data in a single row or all rows
- Syntax for all data from selected rows
This section describes in detail the syntaxes that were summarized in About DataWindow data expressions.
You can think of the syntaxes as grouped in three categories:
-
Expressions with a named column or computed field
-
Expressions with column numbers
-
Expressions that access whole rows
Description
A DataWindow data expression can access a single item in a column or computed field when you specify the control name and a row number. It accesses all the data in the column when you omit the row number.
Syntax
dwcontrol.Object.columnname {.buffer } {.datasource } { [ rownum ] }
Parameter |
Description |
---|---|
dwcontrol |
The name of the DataWindow control or child DataWindow in which you want to get or set data. |
columnname |
The name of a column or computed field in the DataWindow object in dwcontrol. If the column or computed field does not exist at runtime, an execution error occurs. |
buffer (optional) |
The name of the buffer from which you want to get or set data. Values are:
|
datasource (optional) |
The source of the data. Values are:
|
rownum (optional) |
The row number of the desired item. The row number must be enclosed in brackets. To access all the data in the column, omit rownum. When buffer or datasource is not optional When rownum is omitted, you must specify at least one of the other elements in the expression: either buffer or datasource. |
Return value
The expression has a datatype of Any. The expression returns a single value (for a specific row number) or an array of values (when rownum is omitted). Each value has a datatype of columnname.
Usage
Is the expression a DWObject or data?
When you want to access all the data in the column, remember to specify at least one of the other optional parameters. Otherwise, the expression you specify refers to the column control, not its data. This expression refers to the DWObject empname, not the data in the column:
dw_1.Object.empname
In contrast, these expressions all refer to data in the empname column:
dw_1.Object.empname.Primary // All rows dw_1.Object.empname[5] // Row 5
Row numbers for computed fields
When you refer to a control in a band other than the detail band (usually a computed field) you still specify a row number. For the header, footer, or summary, specify a row number of 1. For the group header or trailer, specify the group number:
dw_1.Object.avg_cf[1]
If you specify nothing after the computed field name, you refer to the computed field DWObject, not the data. For a computed field that occurs more than once, you can get all values by specifying buffer or datasource instead of rownum, just as for columns.
When the expression is an array
When the expression returns an array (because there is no row number), you must assign the result to an array, even if you know there is only one row in the result.
This expression returns an array, even if there is only one row in the DataWindow control:
dw_1.Object.empname.Primary
This expression returns a single value:
dw_1.Object.empname[22]
Examples
Because the default setting is current values in the primary buffer, the following expressions are equivalent -- both get the value in row 1 for the emp_name column:
dw_1.Object.emp_name[1] dw_1.Object.emp_name.Primary.Current[1]
This statement sets the emp_name value in row 1 to Wilson:
dw_1.Object.emp_name[1] = "Wilson"
This statement gets values for all the emp_name values that have been retrieved and assigns them to an array of strings:
string ls_namearray[] ls_namearray = dw_1.Object.emp_name.Current
This statement gets current values of emp_name from all rows in the filter buffer:
string ls_namearray[] ls_namearray = dw_1.Object.emp_name.Filter
This statement gets original values of emp_name from all rows in the filter buffer:
string ls_namearray[] ls_namearray = dw_1.Object.emp_name.Filter.Original
This statement gets the current value of emp_name from row 14 in the delete buffer:
string ls_name ls_name = dw_1.Object.emp_name.Delete[14]
This statement gets the original value of emp_name from row 14 in the delete buffer:
string ls_name ls_name = dw_1.Object.emp_name.Delete.Original[14]
This statement gets all the values of the computed field review_date:
string ld_review[] ld_review = dw_1.Object.review_date.Original
Description
A DataWindow data expression uses the Selected property to access values in a named column or computed field for the currently selected rows. Selected data is always in the primary buffer.
Syntax
dwcontrol.Object.columnname {.Primary } {.datasource }.Selected
Parameter |
Description |
---|---|
dwcontrol |
The name of the DataWindow control or child DataWindow in which you want to get or set data. |
columnname |
The name of a column or computed field in the DataWindow object in dwcontrol. If the column or computed field does not exist at runtime, an execution error occurs. |
datasource (optional) |
The source of the data. Values are:
|
Return value
The datatype of the expression is Any. The expression returns an array of values with the datatype of columnname.
Usage
When you specify selected values, the expression always returns an array and you must assign the result to an array, even if you know there is only one row selected.
For selected rows, the primary buffer is the only applicable buffer. For consistency, you can include Primary in this syntax but it is not necessary.
Examples
Because the primary buffer is the only applicable buffer for selected data and current data is the default, these expressions are all equivalent. They access values in the emp_name column for selected rows:
dw_1.Object.emp_name.Selected dw_1.Object.emp_name.Primary.Selected dw_1.Object.emp_name.Current.Selected dw_1.Object.emp_name.Primary.Current.Selected
These expressions both access original values for selected rows:
dw_1.Object.emp_name.Original.Selected dw_1.Object.emp_name.Primary.Original.Selected
This example sets the emp_name value in the first selected row to an empty string. The rest of the selected rows are set to a default value, which can be an empty string:
string ls_empty[] ls_empty[1] = "" dw_1.Object.emp_lname.Selected = ls_empty
This statement gets the original emp_name values in selected rows and assigns them to an array of strings:
string ls_namearray[] ls_namearray = dw_1.Object.emp_name.Original.Selected
Description
A DataWindow data expression accesses values in a named column or computed field for a range of rows when you specify the starting and ending row numbers.
Syntax
dwcontrol.Object.columnname {.buffer } {.datasource } [ startrownum, endrownum ]
Parameter |
Description |
---|---|
dwcontrol |
The name of the DataWindow control or child DataWindow in which you want to get or set data. |
columnname |
The name of a column or computed field in the DataWindow object in dwcontrol. If the column or computed field does not exist at runtime, an execution error occurs. |
buffer (optional) |
The name of the buffer from which you want to get or set data. Values are:
|
datasource (optional) |
The source of the data. Values are:
|
startrownum |
The number of the first row in the desired range of rows. |
endrownum |
The number of the last row in the desired range of rows. The row numbers must be enclosed in brackets and separated by commas. |
Return value
The datatype of the expression is Any. The expression returns an array of values with an array element for each row in the range. Each value's datatype is the datatype of columnname.
Usage
When you specify a range, the expression always returns an array and you must assign the result to an array, even if you know there is only one value in the result. For example, this expression returns an array of one value:
dw_1.Object.empname[22,22]
Examples
Because the primary buffer and current data are the default, these expressions are all equivalent:
dw_1.Object.emp_name[11,20] dw_1.Object.emp_name.Primary[11,20] dw_1.Object.emp_name.Current[11,20] dw_1.Object.emp_name.Primary.Current[11,20]
This example resets the emp_name value in rows 11 through 20 to an empty string. Rows 12 to 20 are set to a default value, which may be an empty string:
string ls_empty[] ls_empty[1] = "" dw_1.Object.emp_name[11,20] = & {"","","","","","","","","",""}
This statement gets the original emp_name values in rows 11 to 20 and assigns them to elements 1 to 10 in an array of strings:
string ls_namearray[] ls_namearray = dw_1.Object.emp_name.Original[11,20]
This statement gets current values of emp_name from rows 5 to 8 in the Filter buffer and assigns them to elements 1 to 4 in an array of strings:
string ls_namearray[] ls_namearray = dw_1.Object.emp_name.Filter[5,8]
This statement gets original values of emp_name instead of current values, as shown in the previous example:
string ls_namearray[] ls_namearray = & dw_1.Object.emp_name.Filter.Original[5,8]
This statement gets current values of emp_name from rows 50 to 200 in the delete buffer and assigns them to elements 1 to 151 in an array of strings:
string ls_namearray[] ls_namearray = dw_1.Object.emp_name.Delete[50,200]
This statement gets original values of emp_name instead of current values, as shown in the previous example:
string ls_namearray[] ls_namearray = & dw_1.Object.emp_name.Delete.Original[50,200]
Description
A DataWindow data expression accesses a single data item when you specify its row and column number.
Syntax
dwcontrol.Object.Data {.buffer } {.datasource } [ rownum, colnum ]
Parameter |
Description |
---|---|
dwcontrol |
The name of the DataWindow control or child DataWindow in which you want to get or set data. |
buffer (optional) |
The name of the buffer from which you want to get or set data. Values are:
|
datasource (optional) |
The source of the data. Values are:
|
rownum |
The row number of the desired item. |
colnum |
The column number of the desired item. The row and column numbers must be enclosed in brackets and separated by commas. |
Return value
The datatype of the expression is Any. The expression returns a single item in the DataWindow control. Its datatype is the datatype of the column.
Examples
These expressions both refer to a single item in row 1, column 2. The expressions access current data in the primary buffer:
dw_1.Object.Data[1,2] dw_1.Object.Data.Primary.Current[1,2]
This statement changes the value of the original data to 0 for the item in row 1, column 2 in the Filter buffer. Column 2 holds numeric data:
dw_1.Object.Data.Filter.Original[1,2] = 0
Description
A DataWindow data expression accesses data in a range of rows and columns when you specify the starting and ending row and column numbers.
Syntax
dwcontrol.Object.Data {.buffer } {.datasource } [ startrownum, startcolnum, endrownum, endcolnum ]
Parameter |
Description |
---|---|
dwcontrol |
The name of the DataWindow control or child DataWindow in which you want to get or set data. |
buffer (optional) |
The name of the buffer from which you want to get or set data. Values are:
|
datasource (optional) |
The source of the data. Values are:
|
startrownum |
The number of the first row in the desired range of rows. |
startcolnum |
The number for the first column in the range. |
endrownum |
The number of the last row in the range. |
endcolnum |
The number for the last column in the range. The row and column numbers must be enclosed in brackets and separated by commas. |
Return value
The datatype of the expression is Any. The expression returns an array of structures or user objects. There is one structure element or user object instance variable for each column in the designated range. The datatype of each element matches the datatype of the corresponding column. There is one structure or user object in the array for each row in the range of rows.
Usage
When you specify a block, the expression always returns an array and you must assign the result to an array, even if you know there is only one structure in the result.
This expression returns an array of one structure from row 22:
dw_1.Object.data[22,1,22,4]
This expression returns an array of one value from row 22, column 1:
dw_1.Object.data[22,1,22,1]
Examples
These statements both refer to data in the first ten rows and first four columns of the DataWindow object in the control dw_1. The primary buffer and current data are the default:
dw_1.Object.Data[1,1,10,4] dw_1.Object.Data.Primary.Current[1,1,10,4]
This example gets employee IDs and last names for all the rows in the delete buffer. The IDs and names are the first two columns. It saves the information in a structure, called str_namelist, of two elements: an integer called id and a string called lastname. The structure was defined previously in the Structure painter. The list of IDs and names is then saved in the file DELETED.TXT:
integer li_fileNum long ll_deletedrows str_namelist lstr_namelist[] ll_deletedrows = dw_1.DeletedCount() lstr_namelist = & dw_1.Object.Data.Delete[1,1, ll_deletedrows,2] li_fileNum = FileOpen("C:\HR\DELETED.TXT", & LineMode!, Write!) FOR ll_count = 1 to UpperBound(lstr_namelist) FileWrite(li_fileNum, & String(lstr_namelist.id) + & " " + & lstr_namelist.lastname + & "~r~n") NEXT FileClose(li_fileNum)
Using the structure from the previous example that holds IDs and last names, this example sets all the IDs and last names in the DataWindow control to null:
long ll_n str_namelist lstr_namelist[] SetNull(lstr_namelist[1].id) SetNull(lstr_namelist[1].lastname) FOR ll_n = 2 to dw_1.RowCount() lstr_namelist[ll_n] = lstr_namelist[1] NEXT dw_1.Object.Data[1,1, dw_1.RowCount(),2] = lstr_data
Description
A DataWindow data expression accesses a single row when you specify the row number. It accesses all the data in the DataWindow control when you omit the row number.
Syntax
dwcontrol.Object.Data {.buffer } {.datasource } { [ rownum ] }
Parameter |
Description |
---|---|
dwcontrol |
The name of the DataWindow control or child DataWindow in which you want to get or set data. |
buffer (optional) |
The name of the buffer from which you want to get or set data. Values are:
|
datasource (optional) |
The source of the data. Values are:
|
rownum (optional) |
The number of the row you want to access. To access data for all rows, omit rownum. The row number must be enclosed in brackets. |
Return value
The datatype of the expression is Any. The expression returns one structure or user object (for a single row) or an array of them (for all rows). There is one structure element or instance variable for each column in the DataWindow object. The datatype of each element matches the datatype of the corresponding column.
Usage
When you omit the row number, the expression always returns an array, and you must assign the result to an array, even if you know there is only one row in the DataWindow control.
Examples
These statements both access current data for row 5 in the primary buffer in the DataWindow object contained in the DataWindow control dw_1:
dw_1.Object.Data[5] dw_1.Object.Data.Primary.Current[5]
This example assigns all the data in dw_1 to the Any variable la_dwdata. The value assigned to la_dwdata is an array of data structures whose members match the column datatypes:
any la_dwdata la_dwdata = dw_1.Object.Data
This example assigns all the data in the delete buffer for dw_1 to the Any variable la_dwdata:
any la_dwdata la_dwdata = dw_1.Object.Data.Delete
This example replaces all the data in the nested report in row 2 with data from dw_2. The columns in the DataWindow object in dw_2 must match the columns in the DataWindow object for the nested report:
dw_1.Object.NestRep[2].Object.Data = & dw_2.Object.Data
Description
A DataWindow data expression accesses all the data in the currently selected rows when you specify the Data and Selected properties. Selected rows are always in the primary buffer.
Syntax
dwcontrol.Object.Data {.Primary } {.datasource }.Selected
Parameter |
Description |
---|---|
dwcontrol |
The name of the DataWindow control or child DataWindow in which you want to get or set data. |
datasource (optional) |
The source of the data. Values are:
|
Return values
The datatype of the expression is Any. The expression returns an array of structures or user objects. There is one structure element or instance variable for each column in the DataWindow object. The datatype of each element matches the datatype of the corresponding column.
Usage
When you specify selected rows, the expression always returns an array, and you must assign the result to an array even if you know there is only one row selected.
Examples
Because the primary buffer is the only applicable buffer for selected data and current data is the default, these expressions are all equivalent. They access data in the selected rows:
dw_1.Object.Data.Selected dw_1.Object.Data.Primary.Selected dw_1.Object.Data.Current.Selected dw_1.Object.Data.Primary.Current.Selected
Both these expressions access original values for selected rows:
dw_1.Object.Data.Original.Selected dw_1.Object.Data.Primary.Original.Selected
This example takes the values in the selected rows in dw_2 and populates a DropDownDataWindow in dw_1 with the values, replacing existing data in the DropDownDataWindow. The column with the DropDownDataWindow is called useroptions. The columns of the DataWindow object in dw_2 must match the columns of the DataWindow object for the DropDownDataWindow:
dw_1.Object.useroptions.Object.Data = & dw_2.Object.Data.Selected