Syntax
FLAG expression variable
Parameters
Flag can be abbreviated as FL or FG.
expression
The source value.
variable
The persistent variable to modify.
The following table lists valid primitive types of the source value, and valid corresponding primitive types of the persistent variable.
Source Value | Persistent Variable |
---|---|
String, Wide | String, Wide |
Number, Date | String (refer to note below), Number, Date |
Kanji | Kanji |
Glb.Zeros | String, Number, Date, Kanji, National |
Glb.Spaces | Glb.High, Glb.Low, String, Kanji, National |
Note: Signed number-primitive source values cannot be assigned to string-primitive persistent variables.
Description
The Flag logic command directly modifies a scalar or array variable in the database.
Note: A Flag logic statement causes a database update, regardless of the value of Glb.Error (unlike an Store method call), or ispec automatic update at the end of the Main method).
Restrictions
The Flag logic command can not be used:
To change the value of the key of a component.
In Edit methods of copy ispecs and copy events.
To store a non-numeric character in a number-primitive variable.
To move a number value to a national string-primitive variable, or vice versa.
To move the value of an attribute to another attribute in the same persistent class. Use a local variable as intermediate storage.
Before using Flag
Before invoking a Flag logic statement, the record to be changed should be retrieved. When the Flag logic statement is invoked, the record retrieved again from the database, to reduce the chance of data corruption. Since the record in memory is overwritten, hold required values in local variables until after the execution of any Flag logic statements.
Grouping Flags
Consecutive Flag logic statements are grouped together, so that the database record changes are combined and written to the database in one operation. When Flag logic statements are separated by other logic statements, multiple database update operations result, possibly causing performance degradation.
Record locking
The first Flag logic statement locks the record being flagged, prior to storing it. The record is not freed until end-of-transaction.
Data truncation
If a national string value is input to a national string-primitive variable, the value is moved character-by-character, and truncated to the length of the variable.
If a national string value is input to a string-primitive variable, the value is moved byte-by-byte, and truncated to the length of the variable. This truncation might occur after the first byte of a double-byte character, resulting in an invalid character.
Examples
Example 1
Determine Every Invoice (Customer, Invoice_No) : When an invoice is printed, Flag 1 Event.Printed : a flag is set (the Event : class's Printed attribute). : Logic to print the invoice End
Example 2
This example stores a local array variable in the database.
Flag 123456 FirUp.Telex : Literal to variable Flag SD_Array FirUp.Address : Array to variable
Example 3
If an instance, with a database record loaded, is assigned to a second instance, the second instance is not attached to the database record, and therefore you cannot invoke a Flag logic statement on the second instance. If you attempt to invoke a Flag logic statement with the second instance you can get unpredictable results on different platforms, such as Windows and MCP.
To invoke a Flag logic statement on the second instance, you must explicitly re-read the record into the second instance before invoking the Flag logic statement.
The logic in the following example is incorrect because the instance “AnotherCUST” is not attached to the record that was previously read into the instance “CUST”, and therefore the Flag logic statement does not succeed:
Lookup “1” CUST AnotherCUST := CUST Flag 123 AnotherCUST.Attr5
The logic can be corrected by calling the Load() method to explicitly re-read the record into the instance AnotherCUST:
Lookup “1” CUST AnotherCUST := CUST AnotherCUST.Load() Flag 123 AnotherCUST.Attr5