Professional Documents
Culture Documents
INDICE
...
END
<FOR EACH STRING>:
Marks the beginning of statement block.
<Sub-string>:
String variable containing the text of the sub-string. There is no need to declare this variable.
<Position>:
Integer variable containing the position of the sub-string in the string. There is no need to declare
this variable.
<Counter>:
Integer variable containing the number of iterations. There is no need to declare this variable.
<Initial string>:
String containing the full text. The sub-strings are not browsed if this string is empty.
<Separator>:
Optional string containing the separator of sub-strings (TAB by default).
To specify several separators, use the following syntax:
[<Separator1> , ..., <Separator N>]
For example: [TAB, CR]
<Direction>:
Optional indicator for the browse direction:
FromBeginning Browse the string from the first character to the last one.
(default value)
FromEnd Browse the string from the last character to the first one.
Browsing the occurrences of a string inside another string Hide the details
FOR EACH POSITION <Position> OF <Search> IN <Initial String> [<Direction>]
...
END
<FOR EACH POSITION>:
Marks the beginning of statement block.
<Position>:
Integer variable containing the current position. There is no need to declare this variable.
<Search>:
Sought string.
<Initial string>:
String containing the full text.
<Direction>:
Optional indicator for the browse direction:
FromBeginning Browse the string from the first character to the last one.
(default value)
FOR ALL / FOR EACH
FromEnd Browse the string from the last character to the first one.
Browsing the occurrences of a string inside another string Hide the details
FOR EACH POSITION <Position> OF <Search> IN <Initial String> WITH <Options>
...
END
<FOR EACH POSITION>:
Marks the beginning of statement block.
<Position>:
Integer variable containing the current position. There is no need to declare this variable.
<Search>:
Sought string.
<Initial string>:
String containing the full text.
<Options>:
Indicator for the selected options (can be combined):
FromBeginning Browse the string from the first character to the last one.
(default value)
FromEnd Browse the string from the last character to the first one.
Remarks
Syntax 1: Browsing the sub-strings separated by a separator
Browses all the sub-strings of <Initial String> separated by <Separator>. The browse is not
performed if <Initial String> is an empty string.
For each iteration:
• <Sub-string> is filled with the current sub-string.
• <Position> contains the position of the sub-string inside the string.
• <Counter> contains the number of iterations performed.
The behavior is undefined if the initial string or the separator is modified during the browse.
Remark: If <Initial String> ends with the separator, <Sub-string> returns an empty string at the
end. Otherwise, <Sub-string> corresponds to the last checked-out element.
Syntax 2 and 3: Browsing the occurrences of a string inside another one
Browses all the positions of <Search> in <Initial String>.
For each iteration, the <Position> variable is assigned with the position of the current sub-string.
The behavior is undefined if the initial string or the sought string is modified during the browse.
FOR EACH STRING, FOR EACH POSITION and UNICODE
<Sub-string>, <Initial String>, <Separator> and <Search> can correspond to:
• ANSI strings.
• UNICODE strings.
However, the ANSI strings and the UNICODE strings cannot be used in the same syntax.
See Managing the UNICODE format for more details.
FOR ALL / FOR EACH
<cc>
</cc>
</bb>
<bb>
<cc>
</cc>
</bb>
</aa>
// Browse on a level
// Reader is the variable corresponding to the XML file
FOR EACH Reader
// Read the start aa and end aa tags
FOR EACH Reader
// Read the start bb, end bb, start bb, end bb tags
FOR EACH Reader
// Read Text1 and the start cc, end cc
// start cc, end cc tags
END
END
END
// Reader is the variable corresponding to the XML file
FOR EACH Reader IN DEPTH
// get tags start aa, start bb, text1,
// start cc, end cc, end bb, start bb,
// start cc, end cc, end bb, end aa tags
END
Syntax
Browsing the elements of XML file on a level Hide the details
FOR EACH <XML Reader>
FOR EACH <XML Reader>
...
END
END
<FOR EACH>:
Marks the beginning of statement block.
Used to browse the children of current level.
<XML Reader>:
xmlReader variable corresponding to the XML file to browse.
Inside the loop, the xmlReader variable points to the current XML element.
FOR ALL / FOR EACH
Remark: You have the ability to nest browses on the XML reader.
Browse on a level with copy Hide the details
FOR EACH <Element> OF <XML Reader>
FOR EACH <Element A> OF <Element>
...
END
END
<FOR EACH>:
Marks the beginning of statement block.
Used to browse the children of current level.
<Element>:
Inside the loop, <Element> points to the current XML element. It can be used to perform a new FOR
EACH loop to browse its children.
<XML Reader>:
xmlReader variable corresponding to the XML file to browse.
Browse in depth Hide the details
FOR EACH <XML Reader> IN DEPTH
...
END
// Browse the arrCustomers array and only process the customers
// whose city is equal to "MONTPELLIER".
stCustomer is Structure
Name is string
FirstName is string
City is string
END
arrCustomers is array of stCustomer
FOR EACH stACustomer OF arrCustomers WHERE City = "MONTPELLIER"
// Process
END
Syntax
Browsing the array elements Hide the details
FOR EACH [ELEMENT] <Variable> [, <Key> [, <Counter>]] OF <Array> [WHERE
<Condition>] [<Direction>]
...
END
<FOR EACH [ELEMENT]>:
Marks the beginning of statement block. The ELEMENT keyword is optional.
<Variable>:
Variable whose type is identical to the type of the array elements. For the arrays of classes, the
variable must be a Dynamic Class variable. There is no need to declare this variable.
<Key>:
Key of element browsed. This key depends on the element browsed:
• One-dimensional array: subscript of the element in the array.
• Two-dimensional array (or n-dimensional array): counter that starts from 1
There is no need to declare this variable.
<Counter>:
FOR ALL / FOR EACH
Integer variable containing the number of iterations. There is no need to declare this variable.
<Array>:
Array to browse.
<Condition>:
FromBeginning Browse the array from the first element to the last one.
(default value)
FromEnd Browse the array from the last element to the first one.
FromBeginning Browse the array from the first element to the last one.
(default value)
FromEnd Browse the array from the last element to the first one.
Remarks
Syntax 1: Browsing the array elements
For each iteration, <Variable> directly refers to the current element in the array. If the value of
<Variable> is modified, the current element in the array is modified.
When exiting from the loop (standard exit or via the BREAK statement), the value of the last
element read is assigned to <Variable> but <Variable> does not directly refer to the array element
anymore.
All types of arrays are available: automatic, fixed, dynamic.
The arrays can have several dimensions.
The behavior is undefined if the number of elements is modified in the browse loop.
Syntax 2: Browsing the values of array elements
FOR ALL / FOR EACH
For each iteration, the value of the element browsed is assigned to the <Value> variable. If the value
of <Value> is modified, the current element in the array is not modified.
All types of arrays are available: automatic, fixed, dynamic.
The arrays can have several dimensions.
The behavior is undefined if the number of elements is modified in the browse loop.
FOR ALL / FOR EACH
FromBeginning Browse the array in the order of additions into the array.
(default value)
FromEnd Browse the array in the reverse order of additions into the
array.
Browsing the values of the "Key" elements found in the array Hide the details
FOR EACH [ELEMENT] <Variable> OF <Array> = <Key> [WHERE <Condition>]
[<Direction>]
...
END
<FOR EACH ELEMENT>:
Marks the beginning of statement block. The ELEMENT keyword is optional.
<Variable>:
Variable whose type is identical to the type of the array elements. For the arrays of classes, the
variable must be a Dynamic Class variable. There is no need to declare this variable.
Remark: This variable is a reference to the array value. A modification of this variable in FOR EACH
will also modify the value in the associative array.
<Array>:
Array to browse.
<Key>:
Value of the key for which the array elements must be browsed. For an associative array without
duplicates, 0 or 1 element will be browsed. For an associative array with duplicates, 0 or N
elements will be browsed.
<Condition>:
FromBeginning Browse the array in the order of additions into the array.
(default value)
FromEnd Browse the array in the reverse order of additions into the
array.
Remarks
FOR ALL / FOR EACH
Remark: 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.
Example
// Declaration code
// Declare a combination
CombinationType is Combination
CreateFile
ReadFile
WriteFile
DeleteFile
END
// Syntax 1: Browse the combination options
FOR EACH eOption OF CombinationType
Trace(eOption..Name)
END
// Assign the variable
FileAction = ReadFile + WriteFile
// Syntax 2: Browse the active options
FOR EACH eOption OF FileAction
Trace(eOption..Name)
END
Syntax
Simplified syntax Hide the details
FOR EACH <MyOption> OF <Combination>
...
END
<FOR EACH>:
Marks the beginning of statement block.
<MyOption>:
Option Description variable corresponding to the combination option. There is no need to declare
this variable.
<Combination>:
• Combination containing the values to browse.
• Combination variable containing the options to browse. All the options (active or inactive)
are browsed.
Browsing the active options of a Combination variable Hide the details
FOR EACH <MyOption> OF <Combination>
...
END
<FOR EACH>:
Marks the beginning of statement block.
<MyOption>:
Option Description variable corresponding to the combination option. There is no need to declare
this variable.
<Combination>:
Combination variable containing the options to browse. Only the active options are browsed.
The statement FOR EACH is used to perform different types of browse on the controls (List Box,
Table or Looper controls):
• Browsing the control elements.
• Browsing the values of the selected elements.
• Browsing the subscripts of the selected elements.
Remark: The FOR ALL, FOR EACH statements are accepted. In this documentation, we will be
using the FOR EACHstatement but it can be replaced by FOR ALL.
Limitation: This statement cannot be used on the Combo Box controls.
The FOR EACH statement can also be used to browse the .Net objects that implement the
IEnumerable interface.
Example
// For each user selected in TABLE_User
FOR EACH SELECTED ROW OF TABLE_User
// Send an email
Proc_SendMessage(COL_Name, COL_Email)
END
Syntax
Browsing the control elements (Table, List Box and Looper) Hide the details
FOR EACH ROW [<Subscript> [, <Counter>]] OF <Control>
...
END
<FOR EACH ROW>:
Marks the beginning of statement block.
<Subscript>:
Optional Integer variable. For each iteration, contains the subscript of the current row.
<Counter>:
Optional Integer variable. This variable counts the number of iterations.
<Control>:
Control to browse: List Box, Table or Looper control.
...
END
<FOR EACH SELECTED ROW>:
Marks the beginning of statement block.
<Subscript>:
Integer variable. For each iteration, contains the subscript of the current selected row.
<Counter>:
Optional Integer variable. This variable counts the number of iterations (number of selected rows
for example).
<Control>:
Control to browse: List Box, Table or Looper control.
This syntax is used to browse all the rows, visible or not, of a List Box, Table or Looper control.
For each row browsed:
• <Control name> returns the subscript of the current row. <Subscript> can also be used to
find out the subscript of the current row.
• <Control name>[<Control name>] returns all the columns separated by TAB characters.
This syntax is equivalent to <Control name>[<Subscript>].
• <Column name> returns the column value for the row currently browsed.
The browse has no effect on the current selection.
The behavior is undefined if the number of control elements is modified during the browse.
Caution: Modifying the file in the analysis (adding a key item for example)
can modify the search key used.
<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).
<WITHOUTSAVEPOSITION>:
Optional keyword.
Disables the position save and restore during the browse. Indeed, FOR EACH automatically saves
the position at the beginning of the loop and restores this position in case of "normal" exit from the
loop (the position is not restored if the loop is interrupted by the keywords BREAK, RETURN or
RESULT).
These position save and restore operations can have a high impact (mainly in terms of time),
especially if the code using the instruction FOR EACH itself is called in a loop.
<Direction>:
Optional indicator for the browse direction:
FromBeginning Browses the data file from the first element to the last one.
(default value)
FromEnd Browses the data file from the last element to the first one.
<END>:
Marks the end of 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.
FromBeginning Browses the data file from the first element to the last one.
(default value)
FromEnd Browses 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 statement block.
3 - Browse with selection filter on the search key Hide the details
1. Comparison filter according to a value
FOR EACH <File> WHERE <Key item> = <Minimal value> TO <Maximum value>
[[WITHOUTSAVEPOSITION,] [<Direction>]]
...
END
FOR EACH <File> WHERE <Minimum value> <= <Key item> <= <Maximum value>
[[WIHTOUTSAVEPOSITION,] [<Direction>]]
...
END
<FOR EACH>:
Marks the beginning of statement block.
<File>:
Name of the HFSQL data file, view or query to browse.
<WITH>:
Defines the type of browse.
<Key item>:
FOR ALL / FOR EACH
FromBeginning Browses the data file from the first element to the last one.
(default value)
FromEnd Browses the data file from the last element to the first one.
<END>:
Marks the end of 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>
[[WITHOUTSAVEPOSITION,] [<Direction>]]
...
END
<FOR EACH>:
Marks the beginning of 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.
<WITHOUTSAVEPOSITION>:
Optional keyword.
Disables the position save and restore during the browse. Indeed, FOR EACH automatically saves
the position at the beginning of the loop and restores this position in case of "normal" exit from the
loop (the position is not restored if the loop is interrupted by the keywords BREAK, RETURN or
RESULT).
These position save and restore operations can have a high impact (mainly in terms of time),
especially if the code using the instruction FOR EACH itself is called in a loop.
<Direction>:
Optional indicator for the browse direction:
FOR ALL / FOR EACH
FromBeginning Browses the data file from the first element to the last one.
(default value)
FromEnd Browses the data file from the last element to the first one.
<END>:
Marks the end of 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>] [[WITHOUTSAVEPOSITION,] [<Direction>]]
...
END
FOR EACH <File> WHERE <Composite key> [= [<Value of component 1>, ..., <Value
of component N>] [[WITHOUTSAVEPOSITION,] [<Direction>]]
...
END
<FOR EACH>:
Marks the beginning of 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.
<WITHOUTSAVEPOSITION>:
Optional keyword.
Disables the position save and restore during the browse. Indeed, FOR EACH automatically saves
the position at the beginning of the loop and restores this position in case of "normal" exit from the
loop (the position is not restored if the loop is interrupted by the keywords BREAK, RETURN or
RESULT).
These position save and restore operations can have a high impact (mainly in terms of time),
especially if the code using the instruction FOR EACH itself is called in a loop.
<Direction>:
Optional indicator for the browse direction:
FromBeginning Browses the data file from the first element to the last one.
(default value)
FromEnd Browses the data file from the last element to the first one.
<END>:
Marks the end of statement block.
Remarks
FOR ALL / FOR EACH
Equivalence
• The syntax 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 items used in the condition:
• 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).
If the keyword WIHTOUTSAVEPOSITION has been used, the position save and restore operations
performed during the browse are disabled. Indeed, FOR EACH automatically saves the position at
the beginning of the loop and restores this position in case of "normal" exit from the loop (the
position is not restored if the loop is interrupted by the keywords BREAK, RETURN or RESULT).
These position save and restore operations can have a high impact (mainly in terms of time),
especially if the code using the instruction FOR EACH itself is called in a loop.
Running the next iteration
To directly run the next iteration without ending the code of the next iteration, use the
statement Continue:
// 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, modifying the browse item updates the file index key. 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