• Aucun résultat trouvé

DEFINE DOMAIN PERSONNEL DSING

Dans le document VAX/VMS Software (Page 67-73)

PERSONNEL_RECORD ON PERSDNNEL.DATi

In this example, PERSONNELJlliCORD is a record definition that describes a particular record format, and PERSONNEL.DAT is a VAXNMS file that contains data stored iDthe format described in PERSONNELJlliCORD. PERSONNEL is the domain that logically connects the format in PERSONNELJlliCORD with the actual data in PERSONNEL.DAT.

VAX DAThTRIEVE allows you to define a domain that points to other domains.

Such a domain is calleP a view domain, because it provides a logical view of data stored in more than one data file.

A remote domain can also be created. In a remote domain, you can use a record definition and a data file that are both stored on a remote system, linked to the first by DECnet.

VAX DATATRIEVE also allows you to define DBMS domains. Using DBMS domains, you can use VAX DATATRIEVE to store, modify, and display data man-aged by VAX DBMS.

You can create domains and record definitions with the Application Design Tool (ADT). ADT is an interactive tool that prompts you for the information needed to create the definitions for a domain or a record. Using the example of a domain definition, you are prompted for:

• The domain name

• The file specification of the data file

• The name of each field in the file record

• The type of data in each field

• The format for fields containing dates, numbers, or money

• The length of fields containing character strings

• The organization of the data file

• The name and attributes of each iridex key for indexed files

• The name of a command file to contain the definitions

4-5

Should you be unable to answer a given prompt, ADT can suggest answers to you, in non-programming language. You can instruct ADT to create the data file you defined, and to add to your default directory in the CDD the domain and record definitions you created. If you do not do this, ADT creates a com-mand file containing your definitions. You can then create the data file and store your definitions in the CDD any time you wish, by invoking the com-mand file in response to the DTR> prompt of VAX. DATATRlEVE.

Retrieving and Displaying Data

VAX. DATATRlEVE allows you to retrieve and display data in ways that would otherwise require input and output functions performed by a program written in a high-level programming language.

For example, a typical programming language might retrieve and display the records of all employees named Foster using a loop similar to the following:

LOOP:

READ EMPLOYEE-FILE AT END EX IT

IF LAST_NAME NOT

=

"FOSTER"

GD TO LOOP

PRINT FIRST_NAME. LAST_NAME. ADDRESS •••

GO TO LOOP

Before writing these lines of code, the programmer would have had to define the record data structures comprising the fields FIRST-NAME, LAST-NAME, ADDRESS and so forth_ And the programmer would have had to specify where the record could be found.

In VAX. DATATRlEVE, all the work accomplished by the preceding six lines of code can be accomplished by the single line:

PRINT EMPLOYEES WITH LAST_NAME = "FOSTER"

Of course, the domain EMPLOYEES and the last name FOSTER must have pre-viously been defined.

Using VAX. DATATRIEVE, you retrieve and display data interactively as follows:

• Use the READY command to access a particular domain

• Use the FIND command with a record seleCtion expression (RSE) to form collections of records, and/or

• Use the PRINT command with an RSE to display (and sort) record streams

4-6 • VAX DATATRIEVE

A typical session to retrieve and display data might proceed as follows:

DTR) READY PERSONNEL®]

This command accesses the domain named PERSONNEL.

DTR) PRINT FIRST 2 PERSONNEL®]

In response to this statement, VAX DA11\TRIEVE uses the record definition. con-tained in the domain PERSONNEL to access and format the data contained in the data file pointed to in domain PERSONNEL; it then displays the following lines on your terminal: 00012 EXPERIENCED CHARLOTTE SPIVA

00891 EXPERIENCED EDWARD HOWELL

TOP 12-Sop-1972 $75,892 00012 Fll 9-Apr-197B $59.594 00012

The headings in this display ate the names of the individual fidds described in the record definition used to access the data displayed. Note that two records are displayed, as specified in the PRINT statement. If you want to put this infor-mation in a file, you can specify an output file in the command line, as follows:

DTR) PRINT FIRST 2 PERSONNEL ON FILE.DAT®]

You can also send the information to a line printer, as follows:

DTR) PRINT FIRST 2 PERSONNEL ON LP:®]

The following statement establishes a collection of records:

OTR> FINO PERSONNEL WITH STARTOATE AFTER "Ol-Jan71SB2"@) And might yidd a response such as:

[50 records found]

This collection is caIled the current collection. By specifying record sdection expressions in additional FIND statements, you can narrow this collection down in any way you wish. For example, the following statement locates four records in the current collection:

DTR) FIND CURRENT WITH DEPARTMENT EQUAL

"SALES" OR "MARKETING" AND ZIP_CODE EQUAL 02138 [4 records found]

This collection is now the current collection. If you wish at this point, you can use the PRINT statement to display these records on the terminal screen, or wtite them to a file, or print them on paper. For example, you could display the data on your terminal screen with the statement:

DTR) PRINT ALL NAME. ADDRESS. PHONE®m

4-7

Storing and Modifying Data You store data interactively as follows:

• Use the READY command with WRITE access to reach a particular domain

• Use the SlOR,E command to store a new record

• Use the SlORE command with the REPEAT command to store a specified number of new records

A typical session at the terminal to store new records in a domain might appear as follows:

DTR) READY YACHTS WRITE®]

DTR) REPEAT 2 STDRE YACHTS®]

Enter MANUFACTURER: SARTINI®]

Enter MDDEL: 6800®]

Enter RIG: YAWL®]

Enter LENGTH-oVER-ALL: 40®]

Enter DISPLACEMENT: 20000®]

Enter BEAM: 12®]

Enter PRICE: 82000®]

Enter MANUFACTURER: CARDINAL®]

Enter MODEL: SAVANT®]

Enter RIG: SLOOP®]

Enter LENGTH-oVER-ALL: 27®]

Enter DISPLACEMENT: 7200®]

Enter BEAM: 8®]

Enter PRICE: 23000®]

oTR>

You modify data in existing records as follows:

• Use the READY command with MODIFY to access a particular domain

• Use FIND to fortn a collection of records to be modified

• Use the SELECT command to access a particclat record in the collection

• Use the MODIFY command to update or correct any desired field or fields in the selected record

A typical session at the terminal to modify a record might appear as follows:

OTR) READY YACHTS MOOIFy®m

OrR) FINO YACHTS WITH MANUFACTURER = "CAROINAL"®m [30 records 'ound]

OTR) SELEC.T FIRST®m OTR) PRINT®m

4-8 • VAX DATATRIEVE

LENGTH OI.IER

MANUFACTURER MODEL RIG ALL WEIGHT BEAM PRICE

CARDINAL ADONIS SLOOP 18 575 08 $1 .800

DTR> MODIFY PRICEOO1 Enter PRICE: 2100001 DTR> PRINTOO1

LENGTH OVER

MANUFACTURER MODEL RIG ALL WEIGHT BEAM PRICE

CARDINAL ADONIS SLOOP 18 575 08 $2,100

If an entire collection of records is to be modified in the same general way, you can use a MODIFY statement with the keywords ALL OF and an appropriate record selection expression, instead of forming a collection in one step and then using a series of SELECT and MODIFY statements to modify individual records in the collection.

To delete a record, you follow the procedure outlined above, but use an ERASE statement instead of a MODIFY statement.

Using the VAX DATATRIEVE Editor

You can use the VAX DATATRIEVE Editor to edit the last command statement you entered, to save you from reentering the entire command line should you make a mistake or change your mind.

You can also use the Editor to modify domain and record definitions, proce-dures, and other objects stored in the Common Data Dictionary.

To use the editor, you simply type EDIT followed by a carriage return. VAX DATATRIEVE then places the last command or statement you entered in the Editor's main buffer and on your terminal screen. You can now edit the text or your statement in any way you wish.

To edit an object in the CDD with the VAX DATATRIEVE editor, you type EDIT followed by the name of the dictionary object. You then edit the dictionary object in any way you wish.

Using CROSS to Access Multiple Files

Although not a relational database system, VAX DATATRIEVE has a relational facility for linking a number of domains dynamically. This relational facility is the CROSS clause. Using the DATATRIEVE CROSS clause, you can use a single statement to dynamically join.. data from a number of separate RMS, DBMS and! or Rdb files.

4·9

This is an especially powerful facility that makes it possible to join records from different files related to one another by a common field. For example, a college might maintain a Currrent Academic Status file containing student ID numbers and grades and a separate Registration file containing student ID numbers and home addresses. At the time grades are to be mailed home, the with the Registration file to dynamically link grades with home addresses. The VAX DATATRIEVE statement to accomplish this relational operation might appear as follows:

PRINT ACAOEMICSTATUS CROSS REGISTRATION OVER STUoENT_IO The STUDENT-.lD field is the common field that makes linking these two @es possible.

Writing and Using Procedures

Using the DEFINE PROCEDURE command, you can define sequences of VAX DATATRIEVE commands and statements and store them in the Common Data Dictionary for later use. These stored sequences of commands and statements are called procedures. Procedures can be embedded in other procedures.

They are especially useful in cases where the same set of VAX DATATRIEVE commands is used repeatedly. For example, you could include all the com·

mands necessary to create a weekly inventory report on the same group of prod.

ucts in a procedure that you could then invoke with a single command.

Procedures can be invoked by users at the terminal, or by application programs.

Using the Report Writer Facility to Create Formatted Reports

The VAX DATATRIEVE Report Writer provides a set of formatting options for producing printed reports with page and column headings, page numbers, totals, subtotals, and other summary information.

You can control the format of a report or allow the Report Writer to do some or

all

of the formatting for you.

The following example illustrates use of the VAX DATATRIEVE Report Writer:

OTR> YACHTS WITH LOA

=

38~

[5 records found]

OTR) REPORT YACHTS WITH LOA

=

38 SORTED BY BEAM, PRICE~

RW> SET REPoRTNAME = "REPORT WITH"/"A SPLIT TITLE"~

RW> SET COLUMN PAGE

=

50~

RW> PRINT BEAM, BUILDER, OISP, PRICE~

RW> ENOREPORT~

4-10 • VAXDATATRlEVE

Using the VAX DATATRIEVE graphics facility, you can create charts and graphs from any desired selection of data. The graphs you can create include bar charts, pie charts, hiStograms, scatter graphs, time series graphs, and linear regression plots. Figure 4-1' shoWs agtaph created by the VAX DATATRIEVE

graphics facility. '

To create a graph; you simply use a PLOT statement that includes the name of the graphyou want to create and a record selection exptessibn that specifies the data you want to use. For example, you can display a multi-bar chart ona graphics terminal screen with a statement such as:' '

PLOT MULTI_SHADE ALL DATE. SERVICES. EQUIPMENT_SALES.

Dans le document VAX/VMS Software (Page 67-73)