AYUDA EN LÍNEA
 WINDEVWEBDEV Y WINDEV MOBILE

Este contenido se ha traducido automáticamente.  Haga clic aquí  para ver la versión en inglés.
Ayuda / ¿Cómo proceder? / Gestión de la base de datos
  • Overview
  • Method 1: Path functions
  • Code example
  • Method 2: Instruction FOR EVERYTHING
  • Code example
  • Method 3: HFilter function
  • Example
  • Method 4: Using SQL queries
  • Example
WINDEV
WindowsLinuxJavaReportes y ConsultasCódigo de Usuario (UMC)
WEBDEV
WindowsLinuxPHPWEBDEV - Código Navegador
WINDEV Mobile
AndroidWidget Android iPhone/iPadIOS WidgetApple WatchMac Catalyst
Otros
Procedimientos almacenados
Overview
There are multiple methods to loop though a data file using filters:
Method 1: Path functions
This method uses the following WLanguage functions to loop through data files:
HReadSeek is used to access the first record corresponding to the value of the minimum bound for the search key.
HReadNext reads the next record that matches the search.
HFound checks whether there is a record that matches the search value.

Code example

// Browse the records in the Customer data file whose city is MONTPELLIER. 
HReadSeek(CUSTOMER, City, "PARIS")
WHILE HFound(CUSTOMER)
	// Process the CUSTOMER record
	// ...
	HReadNext(CUSTOMER, City)
END
Method 2: Instruction FOR EVERYTHING
The FOR EACH statement loops through the records of a data file. In our case, this statement will be used to read the records found in a data file according to a filter.
The FOR EACH statement expects the following parameters:
  • the name of the data file to loop through.
  • the name of the index (or key) used to sort the records.
  • the filtering value.
The first record and the next record are read by the FOR EACH statement. There is no need to use the HReadXXX functions.

Code example

// Browse the records in the Customer data file whose city is MONTPELLIER. 
FOR EACH CUSTOMER where CITY = "PARIS"
	// Process the CUSTOMER record
END
Method 3: HFilter function
  1. Use HFilter to apply a filter on the records of the data file.
  2. Loop through the filtered data file using the standard read functions.
  3. At the end of the operation, disable the filter with HDeactivateFilter.

Example

Find orders whose date is between 02/01/2017 and 02/28/2017.
// Apply the filter
HFilter(ORDER, ORDERDATE, "20170201", "20170228")
// Browse the data file
FOR EACH ORDER
	// Process the order read
END
// Disable filter
HDeactivateFilter(ORDER)
Note: The HFilter function is more flexible than the previous methods. It can also be used to manage more filter capabilities. For more details, see the online help about HFilter.
Method 4: Using SQL queries
To loop through the data file using a filter via a query:
  1. Create the query. The query is used to filter the requested records.
    Reminder: A SQL query can be performed:
    • in the query editor.
    • programmatically.
    For more details on how to create a query, see Creating a query.
  2. Execute the query (HExecuteQuery or HExecuteSQLQuery).
  3. Read the query result by looping through the data file.
  4. Free the query (HFreeQuery).

Example

HExecuteQuery(QRY_CustomerList)
FOR EACH QRY_CustomerList
// Process the customer read in the query
END
HFreeQuery(QRY_CustomerList)
Versión mínima requerida
  • Versión 9
Esta página también está disponible para…
Comentarios
Haga clic en [Agregar] para publicar un comentario

Última modificación: 03/04/2025

Señalar un error o enviar una sugerencia | Ayuda local