Fetch
Use this command, in conjunction with the Open Cursor and Close Cursor commands, to retrieve data from a DataTable object and store it in a variable.
This command can be useful when you want to move existing data from a DataTable object back to a hierarchical DataArea. If you want to move existing data from a hierarchical DataArea to a flat DataTable, use the Insert DataTableRow command.
You can use the LVS_FetchStatus system variable to verify the status of the Fetch command. The LVS_FetchStatus returns the following values based on the success of the Fetch command:
- 0—The Fetch command was successful, and a string is stored in the relevant variable.
- -1—The Fetch command was unsuccessful (the cursor moved past the result).
- -2—The Fetch command was unsuccessful (the result is marked as deleted or ignored).
For more information, see Using the LVS_FETCHSTATUS system variable.
Syntax
Fetch Row DATATABLEROW FROM MyCursor INTO MyString
where:
- Row is the row to fetch in relation to the cursor position and can be one of the following:
Value Description NEXT
Fetches the DataTable row immediately proceeding the cursor position.
PRIOR
Fetches the DataTable row immediately preceding the cursor position.
FIRST
Fetches the first DataTable row.
LAST
Fetches the last DataTable row.
- MyCursor is the name for the Cursor object.
- MyString is the string variable in which to store the retrieved data.
Syntax
// Loops through rows of DataTable
// If employee is Active status, then will add salary to nExemptTotal or nNonExemptTotal
// Variables to store Totals for Exempt and NonExempt employees
Create Variable nExemptTotal AS NUM
Create Variable nNonExemptTotal AS NUM
Create VARIABLE sMsg AS STRING
// Create DataTable
Create DATATABLE dtSalary using "Salary.lvdtd"
OPEN Cursor salaryCursor Select "ID, Name, Position, Salary, Category, Entity, Active" FROM dtSalary
Fetch FIRST DATATABLEROW from amounts into amountsRow
While $LVS_FetchStatus$ != -1
If $LVS_FetchStatus$ EQ 0
If ( ($MyTableRow[7]$) AND ("$MyTableRow[5]$" == "Non-Exempt"))
Set Variable nNonExemptTotal = $nNonExemptTotal$ + $MyTableRow[4]$
End If
If ( ($MyTableRow[7]$) AND ("$MyTableRow[5]$" == "Exempt"))
Set Variable nExemptTotal = $nExemptTotal$ + $MyTableRow[4]$
End If
End If
Fetch Next DataTableRow from salaryCursor Into MyTableRow
End While
Close Cursor salaryCursor
SET VARIABLE sMsg = "Total for Active Non-Exempt Employees: " + NUMTOSTR($nNonExemptTotal$)
Show Message $sMsg$
SET VARIABLE sMsg = "Total for Active Exempt Employees: " + NUMTOSTR($nExemptTotal$)
Show Message $sMsg$
//Transfer nonexempt and exempt totals to an existing dataArea
RUN MODEL transferTotals.lvmod on daTotSalary
See also