Browse columns and validation expressions
- Last Updated: May 8, 2024
- 3 minute read
- OpenEdge
- Version 13.0
- Documentation
This section discusses the relationship between validation expressions and browse columns.
To see an example of this relationship:
- Add the SalesRep field to the column list, with this
statement:
hColumn = hBrowse:ADD-LIKE-COLUMN(hTTBuf:BUFFER-FIELD("SalesRep")).Note: You will have to add a variable definition forhColumn.Run the procedure. You should see this error message:
The reason for this error is that in the Sports2020 database there is a validation expression defined on the Customer.SalesRep field, which the temp-table column has inherited. This validation uses a
CAN-FINDexpression to check to make sure that the value in the SalesRep field matches the SalesRep field in a record in the SalesRep table. The field SalesRep.SalesRep (it is some what confusing that the table name and field name are the same) is the primary key for this value. Customer.SalesRep is the foreign key. The AVM cannot process aCAN-FINDfor a dynamic browse column, so if you want to include such a column, you need to exclude the column validation. - To do this, add a statement to blank out the validate expression before you add the
column to the browse:
hTTBuf:BUFFER-FIELD("SalesRep"):VALIDATE-EXPRESSION = "". hColumn = hBrowse:ADD-LIKE-COLUMN(hTTBuf:BUFFER-FIELD("SalesRep")). - To see another variation, add a calculated column to the browse. This column will
hold the difference between the Customer CreditLimit and
Balance fields. It is a DECIMAL field with no extent and
a label of Available. Place the new column in position 4
within the list of browse columns:
hColumn = hBrowse:ADD-CALC-COLUMN("DECIMAL","ZZ,ZZZ,ZZ9.99",0,"Available",4). - To populate the field for each row in the query, you need to define a
ROW-DISPLAYtrigger for the browse. You can add the trigger as a separateON ROW-DISPLAY OF hBrowsestatement, or in aTRIGGERSblock at the end of theCREATE BROWSEstatement:CREATE BROWSE hBrowse . . . VISIBLE = YES TRIGGERS: ON ROW-DISPLAY hColumn:SCREEN-VALUE = STRING(hTTBuf:BUFFER-FIELD("CreditLimit"):BUFFER-VALUE - hTTBuf:BUFFER-FIELD("Balance"):BUFFER-VALUE). END.When the trigger executes, the handle of the column must be in the
hColumnvariable. You need to define theROW-DISPLAYtrigger before the calculated field is added to the browse, and before the query is opened. You can modify theSCREEN-VALUEand certain other attributes of any field within the trigger. - Move the
QUERY-OPENmethod after the statements that create the browse and its columns so that rows are initialized properly with the calculated value:hColumn = hBrowse:ADD-CALC-COLUMN("DECIMAL","ZZ,ZZZ,ZZ9.99",0,"Available",4). hQuery:QUERY-OPEN().If you open the query before you create the browse and its trigger, the first rows of the query appear in the browse viewport, but the calculated field is not assigned to them. Only when you scroll down through the browse do the values for the calculated field appear. This is why it is important to define the trigger and add the column before you open the query.
- Run the procedure: