PC SOFT

ONLINE HELP
FOR WINDEV, WEBDEV AND WINDEV MOBILE

  • Equivalence
  • Filter (syntaxes 2)
  • Exiting from FOR EACH loop
  • Influence of the mode for exiting from the loop on the automatic browse of data files
  • Running the next iteration
  • Modifying the key used for the automatic browse of data files or queries
WINDEV
WindowsLinuxUniversal Windows 10 AppJavaReports and QueriesUser code (UMC)
WEBDEV
WindowsLinuxPHPWEBDEV - Browser code
WINDEV Mobile
AndroidAndroid Widget iPhone/iPadApple WatchUniversal Windows 10 AppWindows Mobile
Others
Stored procedures
The FOR EACH statement is used to perform different types of HFSQL browse:
  • Full browse (according to a specified key or not)
  • Browse with filter (simple filter, filter on a key or filter on the search key). In this case, the filters accept the operators of HFilter.
The browse operations can be performed on a data file, a view, a query or a data source. The records locked in read/write are not read.
Notes:
  • If the key given to the FOR EACH statement is the key that was previously returned by HFilter, the filter will be respected.
  • The FOR ALL, FOR EACH statements are accepted. The FOR EACH statement will be used in this documentation but it can be replaced by FOR ALL.
Versions 17 and later
WINDEV MobileiPhone/iPad This feature is available for the iPhone/iPad applications.
New in version 17
WINDEV MobileiPhone/iPad This feature is available for the iPhone/iPad applications.
WINDEV MobileiPhone/iPad This feature is available for the iPhone/iPad applications.
Versions 18 and later
WINDEVWINDEV MobileUniversal Windows 10 App This feature is available in Windows Store apps mode.
WINDEV MobileAndroid Widget This feature is available in Android Widget mode.
New in version 18
WINDEVWINDEV MobileUniversal Windows 10 App This feature is available in Windows Store apps mode.
WINDEV MobileAndroid Widget This feature is available in Android Widget mode.
WINDEVWINDEV MobileUniversal Windows 10 App This feature is available in Windows Store apps mode.
WINDEV MobileAndroid Widget This feature is available in Android Widget mode.
Versions 21 and later
WINDEVWINDEV MobileUniversal Windows 10 App This feature is available in Universal Windows 10 App mode.
WINDEV MobileApple Watch This feature is available in Apple Watch mode.
New in version 21
WINDEVWINDEV MobileUniversal Windows 10 App This feature is available in Universal Windows 10 App mode.
WINDEV MobileApple Watch This feature is available in Apple Watch mode.
WINDEVWINDEV MobileUniversal Windows 10 App This feature is available in Universal Windows 10 App mode.
WINDEV MobileApple Watch This feature is available in Apple Watch mode.
Note: From version 19, HFSQL is the new name of HyperFileSQL.
Example
// Syntax 1
FOR EACH Customer
// Add customers into the List Box control
ListAdd(LIST_CustomerList, Customer.CustomerNum)
END
// Syntax 1
FOR EACH Customer on CustomerNum
// Add customers into the List Box control
ListAdd(LIST_CustomerList, Customer.CustomerNum)
END
// Syntax 2
// Browse with filter
FOR EACH Customer WHERE "CustomerCity = 'Montpellier'"
// Add customers into the List Box control
ListAdd(LIST_CustomerList, Customer.CustomerNum)
END

City = "Lyon"
FOR EACH Customer WHERE "CustomerCity = '"+City+"' and CustomerAge >= 21"
// Add customers into the List Box control
ListAdd(LIST_CustomerList, Customer.CustomerNum)
END
// Syntax 2
// Browse with filter on a specific key
FOR EACH Customer WHERE "CustomerCity = 'Montpellier'" on CustomerNum
// Add customers into the List Box control
ListAdd(LIST_CustomerList, Customer.CustomerNum)
END

City = "Lyon"
FOR EACH Customer WHERE "CustomerCity = '" + City + "' AND " + ...
 "CustomerAge >= 21" on CustomerNum
// Add customers into the List Box control
ListAdd(LIST_CustomerList, Customer.CustomerNum)
END
// Syntax 3
// Comparison according to a value
FOR EACH Customer WHERE CustomerName = "Doe"
// Add customers into the List Box control
ListAdd(LIST_CustomerList, Customer.CustomerNum)
END

// Comparison according to a value
FOR EACH Orders WHERE OrderDate = "20031231"
// Add orders into the List Box control
ListAdd(LIST_OrderList, Order.OrderNum)
END
// Syntax 3
// Comparison according to a set of values
FOR EACH Orders WHERE OrderDate = "20030101" TO "20031231"
// Add orders into the List Box control
ListAdd(LIST_OrderList, Order.OrderNum)
END

// Comparison according to a set of values
FOR EACH Orders WHERE "20030101" <= OrderDate <= "20031231"
// Add orders into the List Box control
ListAdd(LIST_OrderList, Order.OrderNum)
END
// Syntax 4
// Browse with filter on a specific key
FOR EACH Customer WHERE CityCustomer [= "Mont" FromEnd
// Add customers into the List Box control
ListAdd(LIST_CustomerList, Customer.CustomerNum)
END
// Syntax 5
// Browse with filter on a composite key
FOR EACH ContactFile WHERE CCState = ["Prospect", 69]
// Add contacts into the List Box control
ListAdd(LIST_ContactList, ContactFile.ContactNum)
END

// Browse with filter on a composite key
FOR EACH ContactFile WHERE CZipCode [= ["Prospect", 69]
// Add contacts into the List Box control
ListAdd(LIST_ContactList, ContactFile.ContactNum)
END
Syntax

1 - Full browse Hide the details

1. Full browse according to the best search key

Caution: Modifying the file in the analysis (adding a key item for example) can modify the search key used.

FOR EACH <File> [<Direction>]
...
END

2. Full browse according to the key passed in parameter

FOR EACH <File> ON <Key Item> [<Direction>]
...
END
<FOR EACH>:
Marks the beginning of the statement block.
<File>:
Name of the HFSQL data file, view or query to browse.
<ON>:
Defines the type of browse.
<Key Item>:
Name of the key item used to browse the HFSQL data file (view or query).
<Direction>:
Optional indicator for the browse direction:
FromBeginning
(default value)
Browses the data file from the first element to the last one.
FromEndBrowses the data file from the last element to the first one.
<END>:
Marks the end of the statement block.

2 - Browse with filter Hide the details

1. Browse with filter (the best search key is automatically defined)

Caution: Modifying the file in the analysis (adding a key item for example) can modify the search key used.

FOR EACH <File> WHERE "<1st Condition>
               [AND/OR/NOT <2nd Condition>
               [AND/OR/NOT...<Nth Condition>]]" [<Direction>]
...
END

2. Browse with filter according to the specified key

FOR EACH <File> WHERE "<1st Condition>
               [AND/OR/NOT <2nd Condition>
               [AND/OR/NOT...<Nth Condition>]]" [<Direction>]
...
ON <Key Item>
END
<FOR EACH>:
Marks the beginning of the statement block.
<File>:
Name of the HFSQL data file, view or query to browse.
<WITH>:
Defines the type of browse.
<Nth Condition>:
Nth condition of the filter for the HFSQL browse. See notes for more details.
<AND/OR/NOT>:
Optional logical operators used to combine the different filter conditions.
<Direction>:
Optional indicator for the browse direction:
FromBeginning
(default value)
Browses the data file from the first element to the last one.
FromEndBrowses the data file from the last element to the first one.
<Key Item>:
Item corresponding to a key of the data file. The filter will be performed on this key.
<END>:
Marks the end of the statement block.

3 - Browse with selection filter on the search key Hide the details

1. Comparison filter according to a value

FOR EACH <File> ON <Key Item> [ = / <= / >= ] <Value> [<Direction>]
...
END

2. Comparison filter according to an interval of values

FOR EACH <File> WHERE <Key Item> = <Minimum Value> TO <Maximum Value> [<Direction>]
...
END

FOR EACH <File> WHERE <Minimum Value> <= <Key Item> <= <Maximum Value> [<Direction>]
...
END
<FOR EACH>:
Marks the beginning of the statement block.
<File>:
Name of the HFSQL data file, view or query to browse.
<WITH>:
Defines the type of browse.
<Key Item>:
Key item of the data file to browse.
<Value>:
Comparison value of the key item.
<Minimum Value>, <Maximum Value>:
Comparison value of the key item.
<Direction>:
Optional indicator for the browse direction:
FromBeginning
(default value)
Browses the data file from the first element to the last one.
FromEndBrowses the data file from the last element to the first one.
<END>:
Marks the end of the statement block.

4 - Browse with "Start with" generic search, ascending or descending Hide the details

FOR EACH <File> WHERE <Key Item> [= <Beginning of Sought Value> [<Direction>]
...
END
<FOR EACH>:
Marks the beginning of the statement block.
<File>:
Name of the HFSQL data file, view or query to browse.
<WITH>:
Defines the type of browse.
<Key Item>:
Key item of the data file to browse.
<Beginning of sought value>:
Comparison value of the key item.
<Direction>:
Optional indicator for the browse direction:
FromBeginning
(default value)
Browses the data file from the first element to the last one.
FromEndBrowses the data file from the last element to the first one.
<END>:
Marks the end of the statement block.

5 - Browse with filter on a composite key Hide the details

1. Exact-match search

FOR EACH <File> WHERE <Composite Key> = [<Value of Component 1>, ..., <Value of Component N>] [<Direction>]
...
END

2. Generic search ("Starts with")

FOR EACH <File> WHERE <Composite Key> [= [<Value of Component 1>, ..., <Value of Component N>] [<Direction>]

...
END
<FOR EACH>:
Marks the beginning of the statement block.
<File>:
Name of the HFSQL data file or view to browse.
<WITH>:
Defines the type of browse.
<Composite key>:
Composite key of the data file to browse.
<Value of Component N>:
Value of the component.
<Direction>:
Optional indicator for the browse direction:
FromBeginning
(default value)
Browses the data file from the first element to the last one.
FromEndBrowses the data file from the last element to the first one.
<END>:
Marks the end of the statement block.
Remarks

Equivalence

  • FOR EACH <File> WHERE <Item> = <Value> is equivalent to a browse performed on the data file by HReadSeek. This browse takes the filters previously defined on the data file into account.
  • The syntax FOR EACH <File> WHERE <Condition> is used to define a filter and to browse the data file. This browse ignores the filters that were defined beforehand.
  • When using queries, the "FOR EACH" syntax may be slower than the "WHILE NOT HOut" syntax. Indeed, when using FOR EACH, an operation for saving/restoring context is automatically performed (equivalent to HSavePosition/HRestorePosition).

Filter (syntaxes 2)

The general syntax of a filter has the following format:
"<Item Name> <Operators> <Item Value>"
For example:
"CustomerName > 'Doe' and ZipCode = 75 or CustomerAge >= 32"
The supported operators depend on the type of the items used in the condition:
<>DifferentValid for all types
>Greater thanValid for all types
>=Greater than or equal toValid for all types
<Less thanValid for all types
<=Less than or equal toValid for all types
=Strictly equal toValid for all types
~=Almost equal toValid for the "string" types only
]ContainsValid for the "string" types only
]=Starts withValid for the "string" types only
Notes:
  • The constant strings must be enclosed in simple quotes. For example: "CustomerName = '"+Customer+"'"
  • <Item Name> must only contain letters, digits and underscore characters ("_"). If <Item name> contains other characters (quote, ...), the name of the item must be enclosed in double quotes. For example: "e_mail@"]'fr'
  • Comparisons between strings are performed according to the ASCII value of the characters and not according to the lexicographic value ('a' > 'Z).
  • The binary memos and the composite keys cannot be part of an <Item Value>.
  • If <Item Value> contains a simple quote (or a double quote), this simple quote (or double quote) must be preceded by a backslash character.

Exiting from FOR EACH loop

Several statements are available:
  • RETURN: Exit from the FOR EACH loop and exit from the current process (or procedure).
  • RESULT: Return a status report to the calling process. Exit from the FOR EACH loop and exit from the current process (or procedure).
  • BREAK: Exits from the FOR EACH loop and runs the rest of the current process.
Close is used to exit from the FOR EACH loop and to close the current window.
Caution: RETURN and RESULT cannot be used in the same process.

Influence of the mode for exiting from the loop on the automatic browse of data files

  • If the browse ends automatically:
    • The position in the data file before the browse is restored.
    • The possible filter required for the browse is disabled.
  • If the browse is interrupted (BREAK, RETURN, RESULT, Close, ...):
    • The position in the data file before the browse is not restored.
    • The possible filter required for the browse is not disabled. It must be disabled manually (HDeactivateFilter).

Running the next iteration

To directly run the next iteration without ending the code of the current iteration, use the Continue statement:
// Browse FileName in the order of KeyItem
FOR EACH FileName on KeyItem
...
IF Condition = True THEN CONTINUE   // Return to the FOR EACH keyword
// and go to the next record
...
END

Modifying the key used for the automatic browse of data files or queries

If the value of the search item is modified when browsing a data file (or a query), some records may be browsed several times.
Indeed, the modification of the search item updates the index key of the file. This modification is taken into account during the automatic reading of the next records.
This remark is also valid for the automatic browse of a sorted query (ORDER BY) without search key.
// Browse FileName on KeyItem
FOR EACH FileName on KeyItem
...
IF Condition = True THEN
// Modify the value of the search key
FileName.KeyItem = "New value"
HModify(FileName)

END
// If the new value of the search key
// positions on the record after in the browse order
// the record will be read again during the browse.
...
END
Minimum required version
  • Version 9
This page is also available for…
Comments
NA AULA DE HOJE VOU MOSTRAR FOR EACH On
PROCEDURE duplica_nota_003_item(_id_numero_nota,_id_numero_nota_anterior)

FOR EACH nota_fiscal_iten WHERE "nota_fiscal_iten.Id_nota_fiscal="+_id_numero_nota_anterior on nota_fiscal_iten.sequencia_digitacao FromBeginning
nota_fiscal_iten.Id_nota_fiscal=_id_numero_nota
HAdd(nota_fiscal_iten)
END

// BLOG COM VIDEO E EXEMPLO

http://windevdesenvolvimento.blogspot.com.br/2017/07/aula-1197-windev-064-tabela-for-each-on.html

https://www.youtube.com/watch?v=sNtAKHGXHac




De matos
Jul. 05 2017
I'll show you how to read a table

Nessa aula de hoje
Vou mostrar como ler uma tabela
e pegar a descrição e jogar para dentro
de uma string

In this class today
I'll show you how to read a table
And pick up the description and play inside
Of a string

//Blog com video e exemplo


https://forum.pcsoft.fr/pt-BR/pcsoft.br.windev/2233-aula-1105-windev-tabela-53-ler-tabelapegar-descricaocolocar/read.awp

http://windevdesenvolvimento.blogspot.com.br/2017/03/aula-1105-windev-tabela-53-ler.html

https://www.youtube.com/watch?v=CL5SsK_t8Wk
De matos
Mar. 29 2017
I'll show you how to get an edt text/And separate each row with cr
Nessa aula de hoje
vou mostrar como pegar um edt texto
e separar cada linha com cr
e adicionar numa tabela

In this class today
I'll show you how to get an edt text
And separate each row with cr
And add in a table

// Comandos

TableDeleteAll(TABLE_Texto)
// Limpando dados da tabela antes de preenche-la
// Clearing Table Data Before Filling It

FOR EACH STRING s_LINHA OF EDT_Texto SEPARATED BY CR
// Vou percorrer a string edt texto separando por Enter=Cr
// I'll go through the edt text string separating by Enter = Cr

TableAddLine(TABLE_Texto,s_LINHA)
// Estou adicionando a tabela, a linha encontrada
// I am adding the table, the row found

END

// Blog com video e exemplo

http://windevdesenvolvimento.blogspot.com.br/2017/03/aula-1104-windev-string-37-separar.html

https://www.youtube.com/watch?v=JOYmP_8OEUE

De matos
Mar. 28 2017
Exemplo For Each
n_id_nota_fiscal is int=TABLE_nota_fiscal.COL_Id_nota_fiscal
Trace("Da Data Menor Vencimento Para Maior")
FOR EACH duplicata_receber WHERE "duplicata_receber.Id_nota_fiscal="+n_id_nota_fiscal on duplicata_receber.id_duplicata_receber
d_data_vencimento is Date=duplicata_receber.data_vencimento
Trace("Data Vencimento: "+d_data_vencimento..Day+"/"+d_data_vencimento..Month+"/"+d_data_vencimento..Year)
END

Trace("Da Data Maior Vencimento Para Menor")

FOR EACH duplicata_receber WHERE "duplicata_receber.Id_nota_fiscal="+n_id_nota_fiscal on duplicata_receber.id_duplicata_receber FromEnd
d_data_vencimento is Date=duplicata_receber.data_vencimento
Trace("Data Vencimento: "+d_data_vencimento..Day+"/"+d_data_vencimento..Month+"/"+d_data_vencimento..Year)

END

//Blog com Video e Exemplo
http://windevdesenvolvimento.blogspot.com.br/2016/11/aula-960-curso-windev-tabela-033-tabela.html
https://www.youtube.com/watch?v=rWDoezouwJg


De matos
Dec. 04 2016