Previous Topic: Preliminary Analysis and DesignNext Topic: Defining Path Groups


Starting to Define the Subschema

This section contains the following topics:

Introduction

Specifying a Subschema Usage Mode

Specifying a Subschema Currency Option

Including Records, Sets, and Areas

Defining Logical Records

Introduction

Once you have analyzed your organization's information needs and thought about how you will design your logical records, you are ready to define a subschema.

This chapter describes how to start defining a subschema that includes one or more logical records. In this chapter, you will:

As you read this chapter, you should refer to the CA IDMS Database Administration Guide for a description of subschema compiler syntax.

Specifying a Subschema Usage Mode

One of the first steps in defining a logical-record subschema is to specify a subschema usage mode. For a subschema that contains logical records, the usage mode can be either LR or MIXED.

LR usage mode

A usage mode of LR allows programs using the subschema to issue requests for logical records (through LRF DML statements). Database records are accessed as components of logical records.

Additionally, these programs can issue the following commands, if appropriate:

MIXED usage mode

A usage mode of MIXED (the default) allows programs using the subschema to issue LRF DML statements and navigational DML statements. These programs can access logical records and single database records.

Specifying the usage mode

You specify a subschema usage mode by using the USAGE IS clause of the ADD SUBSCHEMA Data Description Language (DDL) statement. The following example shows how to specify a subschema usage mode for the sample EMPLR35 subschema.

The EMPLR35 subschema has a usage mode of LR. Programs that use this subschema can issue requests for logical records only.

ADD
SUBSCHEMA NAME IS EMPLR35 OF SCHEMA NAME IS EMPSCHM VERSION IS 1
   DESCRIPTION IS 'SAMPLE SUBSCHEMA FOR LRF MANUAL'
   PUBLIC ACCESS IS ALLOWED FOR ALL
   USAGE IS LR  ◄--------
   .
   .
   .

Specifying a Subschema Currency Option

When a subschema contains logical records, you can specify whether LRF is to reset currency and restore the logical-record area of program variable storage. You specify these currency options in the LR CURRENCY clause of the ADD SUBSCHEMA DDL statement.

NO RESET currency option

NO RESET directs LRF to restore currency for the last path-DML statement. LRF will restore currency before it reexecutes an OBTAIN path.

RESET currency option

RESET (default) directs LRF to reset currency and to restore the logical record's program variable storage area before it reexecutes an OBTAIN path.

The following example shows how to specify a currency option for the EMPLR35 subschema. The EMPLR35 subschema has a currency option of NO RESET.

ADD
SUBSCHEMA NAME IS EMPLR35 OF SCHEMA NAME IS EMPSCHM VERSION IS 1
   DESCRIPTION IS 'SAMPLE SUBSCHEMA FOR LRF MANUAL'
   PUBLIC ACCESS IS ALLOWED FOR ALL
   USAGE IS LR
   LR CURRENCY NO RESET  ◄-----
   .
   .
   .

For more information on subschema currency options, refer to Chapter 15, Currency Considerations.

Including Records, Sets, and Areas

You must include the following database components in a subschema that contains logical records:

You include database components in a subschema by using the ADD RECORD, ADD SET, and ADD AREA DDL statements.

Restricting the subschema's view

You should restrict the subschema's view of any database records included in your subschema definition. You can restrict this view in two ways:

If you don't use one of these clauses, the record description will include all fields contained in the database record. This could:

The following example shows how to include database components for the sample EMPLR35 subschema.

ADD
SUBSCHEMA NAME IS EMPLR35 OF SCHEMA NAME IS EMPSCHM VERSION IS 1
    .
    .
    .
ADD
AREA NAME IS EMP-DEMO-REGION
    .
ADD
AREA NAME IS ORG-DEMO-REGION
    .
ADD
RECORD NAME IS EMPLOYEE
   ELEMENTS ARE EMP-ID-0415 EMP-NAME-0415 START-DATE-0415
   STATUS-0415
    .
ADD
RECORD NAME IS DEPARTMENT
   ELEMENTS ARE DEPT-ID-0410 DEPT-NAME-0410
    .
ADD
RECORD NAME IS OFFICE
   ELEMENTS ARE OFFICE-CODE-0450
    .
ADD
SET NAME IS EMP-NAME-NDX
    .
ADD
SET NAME IS DEPT-EMPLOYEE
    .
ADD
SET NAME IS OFFICE-EMPLOYEE
    .
    .
    .

Defining Logical Records

Now you are ready to define the logical records that you want to include in the subschema. You define a logical record by using the ADD LOGICAL RECORD DDL statement. LRF uses the record layout described by this statement to reserve an area in program variable storage.

Steps in defining a logical record

To define a logical record, you should:

  1. Name the logical record
  2. Name the elements of the logical record
  3. Specify whether the logical-record description in program variable storage will be reinitialized when certain path statuses are returned
  4. Document the logical record

Step 1: Name the logical record

The logical record name must be from 1 through 16 characters and must be unique for the current subschema; it can't duplicate the name of another logical record or database record described in the same subschema.

You name a logical record by using the NAME IS clause of the ADD LOGICAL RECORD DDL statement. The following example shows how to name the EMP-INFO-LR logical record.

ADD
SUBSCHEMA NAME IS EMPLR35 OF SCHEMA NAME IS EMPSCHM VERSION IS 1
   .
   .
   .
ADD
LOGICAL RECORD NAME IS EMP-INFO-LR
   .
   .
   .

Step 2: Name the logical-record elements

You identify the records that participate in the logical record by using the ELEMENTS clause of the ADD LOGICAL RECORD DDL statement. Program variable storage will contain a description of each record you name as a logical-record element.

Note: Fields that are excluded from the subschema view will not be included in a logical-record description.

Records to include

You should include the following records as logical-record elements:

Using role names

To include an element that occurs more than once in a single logical record, you can use role names. Role names must be included in the ELEMENTS clause of the ADD LOGICAL RECORD statement. Once a role name has been assigned, both the path and the program must refer to the role rather than to the associated record element. For complete information on the use of roles, refer to Chapter 13, Using Role Names.

Naming record elements for EMP-INFO-LR

The following example shows how to name the record elements for the EMP-INFO-LR logical record.

Note: All logical-record components are double-word aligned when they appear in program variable storage.

The EMP-INFO-LR logical record includes the EMPLOYEE, DEPARTMENT, OFFICE, and PATHREC records.

ADD
SUBSCHEMA NAME IS EMPLR35 OF SCHEMA NAME IS EMPSCHM VERSION IS 1
   .
   .
   .
ADD
LOGICAL RECORD NAME IS EMP-INFO-LR
   ELEMENTS ARE
       EMPLOYEE
       DEPARTMENT
       OFFICE
       PATHREC VERSION 1  ◄------ IDD-defined work record
   .
   .
   .

The following example shows the description of the EMP-INFO-LR logical record that will appear in program variable storage. The logical-record description for EMP-INFO-LR includes selected fields from the EMPLOYEE, DEPARTMENT, and OFFICE database records, and all fields from the PATHREC work record.

01  EMP-INFO-LR.
    02  EMPLOYEE.
        03  EMP-ID-0415               PIC 9(4).
        03  EMP-NAME-0415
            04  EMP-FIRST-NAME-0415   PIC X(10).
            04  EMP-LAST-NAME-0415    PIC X(15).
        03  START-DATE-0415
            04  START-YEAR-0415       PIC 9(2).
            04  START-MONTH-0415      PIC 9(2).
            04  START-DAY-0415        PIC 9(2).
        03  STATUS-0415               PIC 9(4).
        03  FILLER                    PIC X(1).
    02  DEPARTMENT.
        03  DEPT-ID-0410              PIC 9(4).
        03  DEPT-NAME-0410            PIC X(45).
        03  FILLER                    PIC X(7).
    02  OFFICE.
        03  OFFICE-CODE-0450          PIC 9(3).
        03  FILLER                    PIC X(5).
    02  PATHREC.
        03  WORK-PATH-ID              PIC X(10).

Step 3: Specify initialization options for program variable storage

You can request that LRF clear program variable storage automatically when the following path statuses are returned:

You specify these options in the ON LR-ERROR and ON LR-NOT-FOUND clauses of the ADD LOGICAL RECORD DDL statement. The default for each option is NOCLEAR.

Specifying CLEAR

By specifying CLEAR, you ensure that the data in program variable storage made available to the user meets program WHERE clause selection criteria. This option is recommended if you want LRF to return complete logical records to the program.

The following example shows how to specify initialization options for the EMP-INFO-LR logical record. These initialization options ensure that program variable storage will be cleared when LRF returns a path status of LR-NOT-FOUND or LR-ERROR.

ADD
SUBSCHEMA NAME IS EMPLR35 OF SCHEMA NAME IS EMPSCHM VERSION IS 1
   .
   .
   .
ADD
LOGICAL RECORD NAME IS EMP-INFO-LR
   ELEMENTS ARE
       EMPLOYEE
       DEPARTMENT
       OFFICE
       PATHREC VERSION 1
   ON LR-ERROR CLEAR         ─┐  Initialization
   ON LR-NOT-FOUND CLEAR     ─┘  options
   .
   .
   .

For more information on complete and partial logical records, refer to Chapter 11, Controlling Path Execution.

Step 4: Document the logical record

To give programmers the information they need to use the subschema successfully, you should document each logical record thoroughly. You can document a logical record by using the COMMENTS clause of the ADD LOGICAL RECORD DDL statement. The information you provide will be copied along with the logical record to the appropriate area of program variable storage.

Coding preliminary comments

It is recommended that you code preliminary comments at this stage of the subschema definition process. Once you have defined the associated path groups and paths, you can make your comments more complete.

For the preliminary comments, you can:

The following example shows how to code preliminary comments for the EMP-INFO-LR logical record. For instructions on coding comments, refer to Chapter 14, Documenting the Subschema.

ADD
SUBSCHEMA NAME IS EMPLR35 OF SCHEMA NAME IS EMPSCHM VERSION IS 1
    .
    .
    .
ADD
LOGICAL RECORD NAME IS EMP-INFO-LR
    ON LR-ERROR CLEAR
    ON LR-NOT-FOUND CLEAR
    ELEMENTS ARE
        EMPLOYEE
        DEPARTMENT
        OFFICE
        PATHREC VERSION 1
    COMMENTS
        '***************************************************************'
  -     'THE EMP-INFO-LR LOGICAL RECORD ACCESSES INFORMATION FROM THE'
  -     'EMPLOYEE DATABASE RECORD AND ALSO ACCESSES INFORMATION'
  -     'FROM THE ASSOCIATED DEPARTMENT AND OFFICE RECORDS.'
  -     '***************************************************************'
  -     ' '
  -     'LR VERBS ALLOWED: OBTAIN'
  -     ' '
  -     '***************************************************************'
  -     ' '
  -     'SELECTION CRITERIA (TOTAL OF FIVE PATHS)'
  -     ' '
  -     '   OBTAIN PATH GROUP:'
  -     ' '
  -     ' '
  -     '    PATH 1)  THIS PATH RETRIEVES EMPLOYEE, DEPARTMENT, AND'
  -     '             OFFICE INFORMATION FOR ALL EMPLOYEES WHO ARE'
  -     '             ON LEAVE.'
  -     ' '
  -     '             THE PATH WILL BE SELECTED IF THE PROGRAM'
  -     '             REQUEST INCLUDES THE KEYWORD ON-LEAVE.'
  -     ' '
  -     ' '
  -     '    PATH 2)  THIS PATH RETRIEVES EMPLOYEE, DEPARTMENT, AND'
  -     '             OFFICE INFORMATION FOR A PARTICULAR EMPLOYEE.'
  -     '             IT USES THE EMP-ID-0415 FIELD AS A'
  -     '             CALC KEY TO ACCESS EMPLOYEE INFORMATION.'
  -     ' '
  -     '             THE PATH WILL BE SELECTED IF ANY OF THESE'
  -     '             COMPARISONS ARE INCLUDED IN THE PROGRAM WHERE'
  -     '             CLAUSE:'
  -     ' '
  -     '             EMP-ID-0415 = A NUMERIC LITERAL'
  -     '                           A PROGRAM VARIABLE'
  -     '                           A FIELD IN THE LOGICAL-RECORD'
  -     '                            AREA OF PROGRAM VARIABLE STORAGE'
  -     ' '
  .
  .
  .