APPLY TO SELECTION

4D - Documentation   Français   English   German   4th Dimension 2004, Command Theme List   4th Dimension 2004, Command Alphabetical List   4th Dimension 2004, Constant Theme List   Back   Previous   Next

version 3


APPLY TO SELECTION ({table; }statement)

ParameterTypeDescription
tableTableTable for which to apply statement, or
Default table, if omitted
statementStatementOne line of code or a method

Description

APPLY TO SELECTION applies statement to each record in the current selection of table. The statement can be a statement or a method. If statement modifies a record of table, the modified record is saved. If statement does not modify a record, the record is not saved. If the current selection is empty, APPLY TO SELECTION has no effect. If the relation is automatic, the statement can contain a field from a related table.

APPLY TO SELECTION can be used to gather information from the selection of records (for example, a total), or to modify a selection (for example, changing the first letter of a field to uppercase). If this command is used within a transaction, all changes can be undone if the transaction is canceled.

4D Server: The server does not execute any of the commands that may be passed in statement. Every record in the selection will be sent back to the local workstation to be modified.

The progress thermometer is displayed while APPLY TO SELECTION is executing. To hide it, use MESSAGES OFF prior to the call to APPLY TO SELECTION. If the progress thermometer is displayed, the user can cancel the operation.

Examples

1. The following example changes all the names in the table [Employees] to uppercase:

   APPLY TO SELECTION([Employees];[Employees]Last Name:=Uppercase([Employees]Last Name))

2. If a record is locked during execution of APPLY TO SELECTION and that record is modified, the record will not be saved. Any locked records that are encountered are put in a set called LockedSet. After APPLY TO SELECTION has executed, test LockedSet to see if any records were locked. The following loop will execute until all records have been modified:

   Repeat 
      APPLY TO SELECTION([Employees];[Employees]Last Name:=Uppercase([Employees]Last Name)) 
      USE SET ("LockedSet")  ` Select only locked records 
   Until (Records in set ("LockedSet") = 0)  ` Done when there are no locked records

3. This example uses a method:

   ALL RECORDS ([Employees])
   APPLY TO SELECTION([Employees];M_Cap) 

System Variables or Sets

If the user clicks the Stop button in the progress thermometer, the OK system variable is set to 0. Otherwise, the OK system variable is set to 1.

See Also

EDIT FORMULA, Sets.


4D - Documentation   Français   English   German   4th Dimension 2004, Command Theme List   4th Dimension 2004, Command Alphabetical List   4th Dimension 2004, Constant Theme List   Back   Previous   Next