Check rules are not allowed to change any transaction field or modules and can work only with local variables. Thus if it is needed to read database entries in check rules it is not possible to use standard database access functions as e.g. dbread.
The only option is to access the data by DbExecuteSql(var) and manually assign and use register fields locally in the checkrule.
To escape from this a typical implementation is to fill a module in a default rule and use the fields loaded that way in the check rule.
The negative performance effect of this is
A different implementation is to define a separate module instance with the module property static which places this module instance outside the TradeDesign flow. Thus nothing depends on this module instance. A checkrule might fill this instance and utilize the loaded data within the context of the checkrule to issue error messages including references or names of the originating dataset.
To flag the special instance those instances should be prefixed by CHK followed by the table / class name.
When utilizing a cached database access, the performance will be pretty high, as the data is loaded only once, when the field is left or the Check / Save Button is pressed and not when loading the transaction.
Implementing the additional module instance has the cost of additional data and potentially multiple loading of the same data in case multiple check rules will check the same dataset.
Assuming that in the current transaction and module structure there is an instance PTAMAA which holds a field ANTID to be checked for a unique usage.
Check PTAMAA\ANTID if not isempty( PTAMAA\ANTID ) then $Sql = FormatText( SdbEtyGenSql( CHKPTA, “where ANTID = $1 and INR <> $2” ), SqlLit( PTAMAA\ANTID ), SqlLit( PTAMAA\PTAINR ) ) CacheDbReadSql ( CHKPTA, $Sql ) If Errorcode <= 0 then Error( ‘The allNETT Id $1 is already used with $2 / $3 and cannot be assigned to this customer.\n If needed first change the data of customer $4.’, PTAMAA\ANTID, CHKPTA\EXTKEY, CHKPTA\NAM, CHKPTA\EXTKEY ) Else If Errorcode <> TdOdbcNotFound then Reraise Endif Endif Endif