Format { TO n2 TIMES DEPENDING ON name1 [ IN name2 ] ... } OCCURS n1 { TIMES } { } [ INDEXED BY index-name ]
1 – Parameters
1.1 – n1,_n2
Specifies the range for the number of occurrences. The value of n1 is greater than or equal to zero. The value of n2 is greater than or equal to n1.
1.2 – name1
Specifies the field element whose value determines the actual number of occurrences.
1.3 – name2
Specifies the element that contains the depending field. This element is often a record.
1.4 – index-name
Specifies the field element that functions as an index.
2 – Description
The OCCURS ... DEPENDING record property declares a variable- length, one-dimensional array. The actual number of occurrences varies according to the value of the name1 field element. An error occurs if name2 does not include the name1 field, or if name2 specifies an array record element. You can repeat name2 as many times as necessary to identify the particular instance of name1. For example, name2 can repeat to identify a field element within nested record elements: CDO> DEFINE RECORD RETIREMENT_CHECKS OCCURS 1 TO 2 TIMES cont> DEPENDING ON ID_NUMBER IN EMPLOYEES cont> IN MEDICALLY_RETIRED_EMPLOYEES IN RETIRED_EMPLOYEES. cont> END RECORD.
3 – Examples
1.CDO> DEFINE RECORD VACATION_PAY OCCURS 1 TO 2 TIMES cont> DEPENDING ON EXCESS_VACATION IN EMPLOYEE_BENEFITS. cont> EMP_SSN. cont> WEEKLY_SALARY. cont> END RECORD. In this example, the OCCURS ... DEPENDING record property specifies the number of times the VACATION_PAY record element occurs. The number of occurrences is based on the run-time value of the tag variable field element, EXCESS_VACATION, which is part of the EMPLOYEE_BENEFITS record element. 2.CDO> CHANGE RECORD VACATION_PAY cont> NOOCCURS. cont> END RECORD. In this example, the keyword NOOCCURS in the CHANGE RECORD command removes the OCCURS ... DEPENDING record property from the VACATION_PAY record element. 3.CDO> DEFINE FIELD MESSAGE_TABLE_IDX DATATYPE IS LONGWORD. CDO> DEFINE FIELD MESSAGE_TEXT DATATYPE IS TEXT SIZE IS cont> 256 CHARACTERS. CDO> DEFINE RECORD MESSAGE_TABLE. cont> MESSAGE_STRUCT STRUCTURE OCCURS 10 TIMES INDEXED BY cont> MESSAGE_TABLE_IDX. cont> MESSAGE_TEXT. cont> END MESSAGE STRUCTURE. cont> END MESSAGE_TABLE RECORD. CDO> DEFINE RECORD MESSAGE_TABLE2. cont> MESSAGE_STRUCT STRUCTURE OCCURS 1 TO 10 TIMES cont> DEPENDING ON MESSAGE_TEXT cont> INDEXED BY MESSAGE_TABLE_IDX. cont> MESSAGE_TEXT. cont> END MESSAGE STRUCTURE. cont> END MESSAGE_TABLE2 RECORD. CDO> SHOW RECORD MESSAGE_TABLE/FULL Definition of record MESSAGE_TABLE | Contains record MESSAGE_STRUCT | | Occurs 10 indexed by MESSAGE_TABLE_IDX | | Contains field MESSAGE_TEXT | | | Datatype text size is 256 characters CDO> SHOW RECORD MESSAGE_TABLE2/FULL Definition of record MESSAGE_TABLE2 | Contains record MESSAGE_STRUCT | | Occurs 1 to 10 depending on MESSAGE_TEXT indexed by MESSAGE_TABLE_IDX | | Contains field MESSAGE_TEXT | | | Datatype text size is 256 characters In this example, the MESSAGE_TABLE record contains an INDEXED BY clause. The name of the index field must already be defined.