Copyright © Cloud Software Group, Inc. All Rights Reserved
Copyright © Cloud Software Group, Inc. All Rights Reserved


Chapter 8 Using Expressions and Operators : Using a Rule Argument for Indirect Referencing

Using a Rule Argument for Indirect Referencing
Example of an Argument to a Rule
The COUNT rule in the following figure is a generic rule that determines the sum of a field over all occurrences. The rule is general enough to sum any field of any table (without parameters). The rule receives the name of the table in the argument TABLEREF and it receives the name of the field in the argument FIELDREF.

 
RULE EDITOR ===> SCROLL: P
COUNT(TABLEREF, FIELDREF);
_ LOCAL SUM;
_ ---------------------------------------------------------------------------
_ ------------------------------------------------------------+--------------
_ SUM = 0; | 1
_ FORALL TABLEREF : | 2
_ SUM = SUM +(TABLEREF).(FIELDREF); |
_ END; |
_ CALL MSGLOG('THE SUM OF ' || TABLEREF ||'.' || FIELDREF || | 3
_ ' IS ' || SUM); |
_ ---------------------------------------------------------------------------
PFKEYS: 1=HELP 3=END 12=CANCEL 13=PRINT 14=EXPAND 2=DOCUMENT 22=DELETE

 
About the Example
The parentheses around the names TABLEREF and FIELDREF in the assignment statement signify indirection.
The FORALL statement loops over the table specified by the indirect table reference (TABLEREF), and the action in the body of the loop involves the field specified by the indirect field reference (FIELDREF).
CALL COUNT('EMPLOYEE_VIEW','SALARY');
The value of TABLEREF is EMPLOYEE_VIEW, and the value of FIELDREF is SALARY. The called rule finds the sum of the salaries of all employees.
Use of Parentheses
Parentheses must enclose the indirect reference when one of the following occurs:

Copyright © Cloud Software Group, Inc. All Rights Reserved
Copyright © Cloud Software Group, Inc. All Rights Reserved