RULE EDITOR ===> SCROLL: P EMPLOYEE_A;
_
_ ---------------------------------------------------------------------------
_ ------------------------------------------------------------+--------------
_ FORALL EMPLOYEE_A : | 1
_ DEPARTMENT.DEPTNAME = EMPLOYEE_IMP.DEPTNAME; |
_ INSERT DEPARTMENT; |
_ END; |
_ ---------------------------------------------------------------------------
PFKEYS: 1=HELP 3=END 12=CANCEL 13=PRINT 14=EXPAND 2=DOCUMENT 22=DELETE
RULE EDITOR ===> SCROLL: P EMPLOYEE_B;
_
_ ---------------------------------------------------------------------------
_ ------------------------------------------------------------+--------------
_ FORALL EMPLOYEE_IMP_A : | 1
_ FORALL EMPLOYEE_IMP_B(EMPLOYEE_IMP_A.KEY) : |
_ CALL MSGLOG(EMPLOYEE_IMP_B.LNAME); |
_ END; |
_ END; |
_ ---------------------------------------------------------------------------
PFKEYS: 1=HELP 3=END 12=CANCEL 13=PRINT 14=EXPAND 2=DOCUMENT 22=DELETE
To access multi-record formats, a parent import table and one or more child import tables must be defined. In the EMPLOYEE_B rule definition, you need two tables: one for the parent (EMPLOYEE_IMP_A) and a second for the child (EMPLOYEE_IMP_B).
To access the record B data, you must first access the parent record A data. This causes the import record to be read into a buffer and an internal cursor set to determine the positioning of data being accessed within the buffer.
In this rule, the FORALL EMPLOYEE_IMP_A: causes the first record to be read and buffered. The data contained within the format A record is returned to the rule and the cursor set to the end of the record data A area (in this case the first record B data portion).
The second FORALL EMPLOYEE_IMP_B(EMPLOYEE_IMP_A.KEY): then returns the first format B data and moves the cursor to the next piece of data (in this case, the second record format B data). Employee last names are written into the message log. This continues until the data within the buffer is exhausted. At this point, the second FORALL terminates and the next parent record A is retrieved by the first FORALL statement.