Peek - script function
Peek() finds the value of a field in a table for a row that has already been loaded or that exists in internal memory. The row number can be specified, as can the table.
Syntax:
Peek(
field_name
[, row_no[, table_name ] ])
Return data type: dual
Arguments:
Argument | Description |
---|---|
field_name | Name of the field for which the return value is required.Input value must be given as a string (for example, quoted literals). |
row_no |
The row in the table that specifies the field required. Can be an expression, but must resolve to an integer. If no |
table_name | A table label without the ending colon. If
no |
Limitations:
In the first record
of an internal table, the function returns
Example:
Add the example script to your app and run it. Then add, at least, the fields listed in the results column to a sheet in your app to see the result.
EmployeeDates:
Load * Inline [
EmployeeCode|StartDate|EndDate
101|02/11/2010|23/06/2012
102|01/11/2011|30/11/2013
103|02/01/2012|
104|02/01/2012|31/03/2012
105|01/04/2012|31/01/2013
106|02/11/2013|
] (delimiter is '|');
FirstEmployee:
Load EmployeeCode, Peek('EmployeeCode',0) As EmpCode
Resident EmployeeDates;
Substituting the value of the argument row_no returns the values of other rows in the table, as follows:
Peek('EmployeeCode',2) returns the third value in the table:
However, note that without specifying the table as the third argument table_no, the function references the current (in this case, internal) table. The result of Peek('EmployeeCode',-2) is multiple values:
Employee code | EmpCode |
---|---|
101 |
- |
102 | - |
103 | 101 |
104 | 102 |
105 | 103 |
106 | 104 |
Example:
FirstEmployee:
Load EmployeeCode, Peek('EmployeeCode',-2,'EmployeeDates') As EmpCode
Resident EmployeeDates;
By specifying the argument table_no as 'EmployeeDates', the function returns the second-to-last value of
Example:
The Peek() function can be used to reference data that is not yet loaded.
Add the example script to your app and run it. Then add, at least, the fields listed in the results column to a sheet in your app to see the result.
T1:
LOAD * inline [
ID|Value
1|3
1|4
1|6
3|7
3|8
2|1
2|11
5|2
5|78
5|13
] (delimiter is '|');
T2:
LOAD
*,
IF(ID=Peek('ID'), Peek('List')&','&Value,Value) AS List
RESIDENT T1
ORDER BY ID ASC;
DROP TABLE T1;
Create a table in a sheet in your app with ID, List, and Value as the dimensions.
ID | List | Value |
---|---|---|
1 | 6 | 6 |
1 | 6,3 | 3 |
1 | 6,3,4 | 4 |
2 | 11 | 11 |
2 | 11,10 | 10 |
2 | 11,10,1 | 1 |
3 | 8 | 8 |
3 | 8,7 | 7 |
5 | 13 | 13 |
5 | 13,2 | 2 |
5 | 13,2,78 | 78 |
The IF() statement is built from the temporary table
Peek('ID') references the field
Peek('List') references the field
The statement is evaluated as follows:
If the current value of
If
Example:
Creates an accumulation of B in