DTRHELP.HLB  —  Commands Statements Clauses, MATCH Statement, Example
       Consider the following record definition for the domain FAM:

       DTR> SHOW FAM_REC
       RECORD FAM_REC USING
         01 FAMILY.
           03 PARENTS.
              06 FATHER PIC X(10).
              06 MOTHER PIC X(10).
           03 NUMBER_KIDS PIC 99 EDIT_STRING IS Z9.
           03 KIDS_N OCCURS 10 TIMES.
              06 EACH_KID.
                  09 KID_NAME PIC X(10) QUERY_NAME IS KID.
           03 KIDS_A OCCURS 10 TIMES.
              06 EACH_KID.
                  09 AGE PIC 99 EDIT_STRING IS Z9.
       ;

       The fixed-length list format means that values are displayed for
       10 KIDS_N and 10 KIDS_A, no matter what the value for NUMBER_
       KIDS. In displays and reports, this means that most FAM records
       would be separated by strings of blanks (for "empty" occurrences
       of KIDS_N) and zeros (for "empty" occurrences of KIDS_A).

       DTR> PRINT FAM

                             NUMBER    KID
         FATHER     MOTHER    KIDS     NAME    AGE

       JIM        ANN           2   URSULA      7
                                    RALPH       3
                                                0
                                                0
                                                0
                                                0
                                                0
                                                0
                                                0
                                                0
       JIM        LOUISE        5   ANNE       31
                                    JIM        29
                                    ELLEN      26
                                    DAVID      24
                                    ROBERT     16
                                                0
                                                0
                                                0
                                                0
                                                0
                 .          .          .
                 .          .          .
                 .          .          .

       To improve display and report formats for this domain, you could
       restructure it using the MATCH statement so that it contains one
       variable-length list field. In other words, the modified record
       definition would look like the current one for the FAMILIES
       domain.

       DTR> SHOW FAMILY_REC
       RECORD FAMILY_REC
       01 FAMILY.
          03 PARENTS.
             06 FATHER PIC X(10).
             06 MOTHER PIC X(10).
          03 NUMBER_KIDS PIC 99 EDIT_STRING IS Z9.
          03 KIDS OCCURS 0 TO 10 TIMES DEPENDING ON NUMBER_KIDS.
             06 EACH_KID.
                09 KID_NAME PIC X(10) QUERY_NAME IS KID.
                09 AGE PIC 99 EDIT_STRING IS Z9.
       ;

       If you attempted to restructure FAM without using the MATCH
       statement, DEC DATATRIEVE would not store the list elements.
       This problem occurs because the modified record definition
       combines two list fields into one. Therefore, to restructure
       the FAM domain, you must use the MATCH statement within a STORE
       statement that is controlled by a FOR loop. The following series
       of statements stores the data from the records in FAM into the
       records in FAMILIES and then prints the results:

       DTR> READY FAM
       DTR> DEFINE FILE FOR FAMILIES
       DTR> READY FAMILIES WRITE
       DTR> FOR FAM
       CON> STORE FAMILIES USING
       CON>   BEGIN
       CON>     PARENTS = PARENTS
       CON>     NUMBER_KIDS = NUMBER_KIDS
       CON>     MATCH KIDS, KIDS_N
       CON>       KID_NAME = KID_NAME
       CON>     MATCH KIDS, KIDS_A
       CON>       AGE = AGE
       CON>   END
       DTR> PRINT FAMILIES

                             NUMBER    KID
         FATHER     MOTHER    KIDS     NAME    AGE

       JIM        ANN           2   URSULA      7
                                    RALPH       3
       JIM        LOUISE        5   ANNE       31
                                    JIM        29
                                    ELLEN      26
                                    DAVID      24
                                    ROBERT     16
                 .          .          .
                 .          .          .
                 .          .          .
Close Help