4D v13.4

APPLY TO SELECTION

Home

 
4D v13.4
APPLY TO SELECTION

APPLY TO SELECTION 


 

APPLY TO SELECTION ( aTable ; statement ) 
Parameter Type   Description
aTable  Table in Table for which to apply statement
statement  Statement in One line of code or a method

APPLY TO SELECTION applies statement to each record in the current selection of aTable. The statement can be a statement or a method. If statement modifies a record of aTable, 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.

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

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

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

This example uses a method:

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

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.

 
PROPERTIES 

Product: 4D
Theme: Selection
Number: 70

The OK variable is changed by the commandDifferent in remote mode

 
INDEX

Alphabetical list of commands

 
HISTORY 

Modified: 4D v11 SQL

 
SEE ALSO 

EDIT FORMULA
Sets