Title: Week 8 Lesson Overview
1Week 8Lesson Overview
- Objectives
- Introduce the concept of externally described
files - Explain how to use the Data Description
Specifications (DDS) language to describe
Physical and Logical database files - Describe the difference between externally
described files and program-described files
2Week 8File Varieties
- On the AS/400, all files are classified as
object type FILE. - Within that classification, AS/400 recognizes 12
varieties of objects. - A particular FILE type is identified by an
attribute when a file is created the attribute
describes how the file is to be used within the
system and is determined by the CL command used
to create the file.
3Week 8File Varieties (continued)
- Common file attributes
- PRTF -- Printer files format output from programs
or utilities to create spooled print files in
output queues. - DSPF -- Display files are similar to printer
files in function, but they format data going to
or coming from display screens rather than
printers. Display files let you position data
fields on screen displays and control color, high
intensity, reverse image, and other display
attributes. You can also control placement of
constants, such as screen-identification
information and field identifiers. Application
programs and utilities can write data to and read
data from display files.
4Week 8File Varieties (Continued)
- PF -- Physical files have two distinct functions
to hold and organize user or application data,
and to organize source programs and source-data
file descriptions written by programmers in
languages such as Cobol, DDS, and RPG. In the
latter capacity, physical files are similar to
source-program libraries or source-file
subdirectories used by other operating systems.
Under OS/400, an attribute identifier
distinguishes these two functions PF-DTA for
data physical files and PF-SRC for source
physical files.
5Week 8File Varieties (Continued)
- LF -- Logical files are created over physical
database files and cannot be created before the
physical file or files with which they are
associated. A logical file is always based on one
or more physical files. Logical files do not
contain data rather, they store access paths, or
pointers, to records in physical files. Think of
logical files as filters or limiting views of
data stored in physical files. You can use
logical files to select specific data based on
INCLUDE or OMIT functions (e.g., to restrict the
type or amount of data presented to an
application) or for efficiency (e.g., to present
data records in an order different from the order
in which the records are stored in the physical
file).
6Week 8Program-Described Files
- Physical files described at the record level
contain - Record name
- Record length
- Any program using a file described this way must
supply field-level attributes for every field in
the record. - Files described at the record level require the
programs that use them to provide additional
specifications -- thus they are referred to as
program-described files.
7Week 8Program-Described Files (Continued)
- Program-described files can be useful when you
need to - Convert older, non-relational files to the AS/400
relational database format - Move files from another system to the AS/400
- Permanent use of program-described files is not
recommended because having to describe a records
fields in every program that uses the file is
tedious and prone to errors.
8Week 8Externally Described Files
- Externally described files are physical files
that contain detailed field-level descriptions of
their record formats and information about how
the files are to be accessed. - The file carries its own record blueprint with
it wherever it goes therefore, any authorized
user program or system utility accessing the file
can determine the details of its record layout
and all field-level attributes by knowing the
objects name.
9Week 8Externally Described Files (Continued)
- Standardized record formats -- Because field
attributes (including field names) are stored in
the file object itself, the use of externally
described files eliminates the confusion caused
when programmers use different names for the same
field. Also, with externally described files it
is impossible to access data fields incorrectly
asfaras field length, data type, or number of
decimal positions when using the file because the
file object itself contains these critical
attributes. To check or compare an externally
described files record format, execute a DSPFFD
(Display File Field Description) command on the
file object.
10Week 8 Externally Described Files (Continued)
- Utilities that are easier to use -- Because
externally described file objects describe
themselves and name all their fields and
attributes, system utilities (e.g., Data File
Utility, Query/400, Screen Design Aid) can obtain
this critical information directly from the file.
Less work is therefore required on the
programmers part when using these utilities to
update data files, create queries and reports,
and code display files.
11Week 8 Externally Described Files (Continued)
- Less tedious programming -- When programmers use
externally described files in programs written in
high-level languages (HLLs), they name the file
and indicate to the compiler that it is
externally described when the program is
compiled, the information in the file is pulled
into the program and converted into the proper
syntax for the HLL. Because the source of the
record-format information is the file object
itself, not a source-library member or a copy
book (a source-code description separate from the
physical data structure), you eliminate the
possibility of pulling in a wrong version of the
record format when the program is compiled.
12Week 8 Externally Described Files (Continued)
- Externally described files contain information at
four levels of data hierarchy - file level
- Member level
- record-format level
- field level
- Example Look at a file field description display
for an existing database physical file,
accessible through a menu path -- or by a more
direct approach of using the DSPFFD command (the
commands only required parameter is the file
name).
13Week 8 Externally Described Files (Continued)
- After you run the DSPFFD command on a database
physical file, you get the display file field
description screen displaying - File name
- Library name
- File location
- Externally described (Yes/No)
- Number of record formats
- File type
14Week 8 Externally Described Files (Continued)
- The record-format information lists the name of
the record format. A record format name is
mandatory in defining a physical file. - The system also uses a format level identifier to
ensure that programs and files agree on version.
This prevents a LEVEL CHECK error. - The second screen of the display shows two
additional record-format attributes - Number of fields
- Record length
15Week 8 Externally Described Files (Continued)
- The essence of an externally described file is in
the field-level information. - For each field, the system records
- Name
- Data type
- Length (characters and digits)
- Position in the record buffer
- Length in bytes
- Field usage (input, output, both)
- Column heading for use by utilities
16Week 8 Externally Described Files (Continued)
- Character-type fields also have a Coded Character
Set Identifier (CCSID) identifying both a
character set and an encoding method, letting
many different types of character data, including
many national languages, be stored on the AS/400. - Once each files information is recorded, the
information never needs to be repeated and is
available for programs and utilities to use and
for you to see. - Record format is an important concept for
externally described files -- OS/400 examines
record formats to determine whether two files
share the same record structure.
17Week 8 Creating an Externally Described Database
File
- The process of creating an externally described
database physical file involves three distinct
steps - Describe -- You must first describe the files
record format and field-level attributes at the
source-language level, much as you would first
write a computer program in a source language
(e.g., Basic, C, Cobol, RPG).
18Week 8 Creating an Externally Described Database
File (Continued)
- Create -- After you describe the file, you can
create the file object by compiling the
source-language file description. This step is
analogous to creating an executable machine-level
object program by compiling a Cobol or RPG source
program. - Insert data -- When youve successfully compiled
the source description into a FILE type object,
you can insert, or load, data into the file.
19Week 8SQL
- SQL is a powerful relational database language
supported by OS/400 that is standardized, has
wide support, and is highly portable.
It lets you - Describe and create physical or logical files
- Limit access to, maintain, and retrieve
information from files, regardless of whether
they were created with SQL
20Week 8SQL (Continued)
- Using SQL to define, control, and manipulate
database files has drawbacks - The SQL licensed program product is not part of
the AS/400s base operating-system support - SQL is capable of wasting huge amounts of DASD,
input/output (I/O) operations and CPU machine
cycles if code containing logic errors is
executed - Mastering SQL requires time and practice
- The object overhead created by SQL collections,
catalogs, etc., is substantial - You cannot use SQL alone to describe and create a
display file -- you need another tool for display
files
21Week 8DDS
- DDS is a language used to code source
descriptions for several types of files,
including - Physical and logical database files
- Display Files
- Printer Files
22Week 8DDS Record-Format Entry
- In a DDS file description, several different
types of records may be used not all are
required for every file description. - For a physical file, the record types are
- File -- blank name type optional when used,
must precede record type - Record -- R name type one required for physical
file - Field -- blank name type describes fields
follows record almost always present - Key -- K name type optional follows field
entries
23Week 8 DDS Record-Format Entry (Continued)
- To describe a simple physical file Minimum
requirements would include only a record-format
line and a few field entries. - To key a record-format specification in the
prompter Specify the value R for the Name Type
field and a value for the Name field. When you
press Enter, the record is moved up to the Edit
screens work area and a new, empty prompt is
provided.
24Week 8 DDS Record-Format Entry (Continued)
- On the next screen that comes up, you can see
that a sequence number (1.00) has been assigned
to the inserted record the decimal portion of
the number lets you insert up to 99 new records
between two existing records during the edit
session without renumbering.
25Week 8Field-Level Entries
- After you insert a record-format line, you can
enter field-level specifications. For these, you
leave the Name Type field blank. But you must
enter values for - Name (field name)
- Length (number of characters or digits)
- Data Type (e.g., character, zoned decimal, packed
decimal, binary, date, time)
26Week 8Field-Level Entries (Continued)
- For numeric fields, you must also enter the
number of decimal positions. For a physical file,
then, the four required attributes of a field
are - Name
- Length
- Data type
- Decimal positions (numeric types)
27Week 8 Field-Level Entries (Continued)
- Name. For record and field names, use from one
to 10 characters, the first of which must be
uppercase alphabetic (AZ) or one of the special
characters _at_, , or . - Subsequent characters can consist of any of
these, the numbers 0 through 9, and the
underscore character (_). - Embedded blanks are not allowed in a name.
Within a record format, field names must be
unique.
28Week 8 Field-Level Entries (Continued)
- Length. Length is the number of characters or
digits in the field. For character, hexadecimal,
and zoned-decimal fields, the length defines the
field size in bytes. The AS/400 uses the Extended
Binary-Coded Decimal Interchange Code, or EBCDIC,
method of encoding characters and zoned-decimal
numbers into binary code, and for all code points
encompassed by EBCDIC (uppercase and lowercase
alphabetic characters, numbers, special
characters), one character equals one byte. So,
for example, an address field of length 30
occupies 30 bytes of record-buffer space.
Languages whose alphabets do not code to EBCDIC
(e.g., Japanese, Chinese) use a
two-byte-per-character coding scheme called
Double Byte Character Set (DBCS). The examples
and exercises in this book assume EBCDIC data.
29Week 8 Field-Level Entries (Continued)
- Length and data type are related. Each data type
has a valid maximum length - Data Types and Maximum Lengths
- Abbreviation Data type Maximum length
- P Packed decimal 31 digits
- S Zoned decimal 31 digits
- B Binary 9 digits
- F Floating-point (short) 9 digits
- F Floating-point (long) 17 digits
- A Character 32,766 characters
- H Hexadecimal 32,766 bytes
- L Date 6, 8, or 10 characters
- T Time 8 characters
- Z Timestamp 26 characters
30Week 8 Field-Level Entries (Continued)
- For numeric data types, the length
specification really means the number of digits
in the field. - For date, time, and timestamp types, you do not
specify a value for length it is determined by
type, and for date fields, by format. The values
shown (in the previous slide) for date, time, and
timestamp data types are the number of characters
needed to display the stored values, not the
number of bytes required for disk storage.
31Week 8 Field-Level Entries (Continued)
- A date field can have three different lengths,
depending on which date format is specified by
the DATFMT keyword in DDS. - If you do not use keyword DATFMT, the default is
ISO format (International Standards
Organization), whose display format is yyyy-mm-dd
(10 characters). - The default time format (also ISO) is displayed
as hh.mm.ss (eight characters) -- you can change
this format by using either a different time
format, such as TIMFMT(USA), or a different
separator, such as TIMSEP('').
32Week 8Field-Level Entries (Continued)
- Timestamp data includes both the date and the
time and is formatted as yyyy-mm-dd-hh.mm.ss.uuuuu
u (26 characters), where uuuuuu represents
millionths of a second.
33Week 8 Field-Level Entries (Continued)
- An advantage of using date type fields is that
they use four digits to record the year. - Programs using files with four-digit years (e.g.,
a DATFMT value of ISO or USA) would have had
few Year 2000 modification problems. - A less obvious advantage is the ability to
perform date duration calculations easily.
34Week 8Field-Level Entries (Continued)
- Data type. Ref. the previous table listing the
data types most commonly used on the AS/400.
Fields of type character, zoned decimal, and
hexadecimal all occupy a number of bytes of
storage equal to the length of the field. But for
other numeric types, the length of the field in
bytes is calculated from the number of digits.
For example, if a Social Security number is typed
S for zoned decimal, the true length of the field
is 9 (bytes and digits). But if the same field is
typed P for packed decimal, then the value 9
specified for length really means nine digits,
and the true field length is five bytes. (Length
in bytes of a packed-decimal field can be
calculated as (Total digits / 2) 1, throwing
away any decimal part.) This difference in length
is due to the way in which numeric data is stored
in packed-decimal format two digits per byte
except for the rightmost byte, which codes the
least significant digit in the high-order four
bits and the sign in the low-order four bits.
35Week 8Field-Level Entries (Continued)
- Advantages of storing numeric data in
packed-decimal format - The field itself is smaller (requiring fewer
bytes of storage space) - Arithmetic and logic operations are more
efficient (requiring fewer intermediate
conversion steps) - Minor disadvantages to storing numbers as packed
decimal - A zoned-decimal numeric field of a physical file
can be redefined as a character field through a
logical file - You cannot directly observe the packed-decimal
field value by using a DSPPFM (Display Physical
File Member) command, which does no conversion
36Week 8Field-Level Entries (Continued)
- NOTE If you dont explicitly provide a data
type, the default is A (alphanumeric/ character)
when no decimal-positions value is specified. If
you provide a decimal-positions value and do not
specify a data type, DDS defaults to the numeric
packed-decimal (P) data type.
37Week 8Physical Files and Access Paths
- Externally described physical files contain data
records whose format is defined according to a
specific layout this record format - Specifies the name and relative order of
fields - Identifies each fields data type and length
- A physical file has only one record format,
designated in the Data Description Specifications
(DDS) source code by an R in the Name Type field
followed by a name for the record format in the
Name field.
38Week 8 Physical Files and Access Paths
(Continued)
- The record format provides a blueprint of a
records fields it does not tell us in what
order records of data can be made available to
applications. - This information -- describing the way in which
records can be read or retrieved from files -- is
called an access path.
39Week 8Arrival-Sequence Access Paths
- On the AS/400, there are two kinds of access
paths, one of which every file uses - Arrival-sequence
- Keyed-sequence
- Records are both stored and retrieved in arrival
sequence (order in which they were added to the
file) unless otherwise specified. - Files using arrival-sequence access paths may
have their records read sequentially or directly.
40Week 8Sequential Retrieval
- With sequential record retrieval, records are
presented one after another in the order in which
they entered (or arrived in) the file -- first
in, first out. - The order in which a DSPPFM (Display Physical
File Member) command lists records is in arrival
sequence. - Sequential retrieval for a file with an
arrival-sequence access path does not imply the
sequencing of records by any field value but only
by the order in which records arrived or were
entered into the file.
41Week 8Direct Retrieval
- Direct retrieval (random access) implies that you
can access a specific record in a file without
having to read all the other records preceding
it. - Any record in an arrival-sequence file can be
retrieved directly if its relative record number
is known. - Relative record numbers are assigned to records
as they are added to a file in a consecutive
series of integers, starting from 1. - HLL programs can read a file randomly by relative
record number.
42Week 8Keyed-Sequence Access Paths
- To read an entire file or access an individual
record by the value of a certain field (the key
field), specify a keyed-sequence access path for
a physical file when it is created by defining
one or more fields in the record format as keys. - A program can then process the files records in
key-field order instead of arrival sequence.
43Week 8 Keyed-Sequence Access Paths (Continued)
- For any file accessed often using the value of a
certain field, specify a keyed-sequence access
path when the file is created. - Key fields are specified in the DDS source code
of the file description, and the key itself can
be a single field in the files record format or
consist of several fields used together (a
composite key). - If the field value must be unique for every
record, the field is a primary key, and a special
file-level keyword, UNIQUE, can be coded in DDS
when you do this, the system does not permit
duplicate keys.
44Week 8Keyed-Sequence Access Paths (Continued)
- Specifying Key Fields (continued)
- When UNIQUE is not used, the system lets records
having the same key-field values be stored in the
file.
45Week 8 Keyed-Sequence Access Paths (Continued)
- Specifying Key Fields (continued)
- You code keyword UNIQUE in DDS as a file-level
entry before the record-format specification
line. - The actual declaration of the key follows the
field-level DDS specifications. - Define keys by coding a K in the Name Type field,
followed by the name of the field that will serve
as the key in the name field of the DDS
specification.
46Week 8Logical Files
- Logical files
- Represent different ways to present all or part
of the data of one or more physical files - Function as a set of rules that tell DB2 UDB/400
how to select, limit, combine, and present the
data of the underlying physical file(s) - Contain no data records -- they get their data
from the physical file(s) on which they are based
(but programs and utilities can access and
manipulate logical files as if they did)
47Week 8Logical Files (Continued)
- A physical file must exist before any logical
file can be based on it many different logical
files can be based on the same physical file. - Logical files, which generally correspond to
views in a relational database, need to be able
to perform several basic functions on
physical-file data.
48Week 8Logical Files (Continued)
- These basic functions include the ability to
- Allow the random access of data by the value of a
field other than the primary key, or present the
logical file in sequence by an alternate key - Select only certain records of the physical file
to be included in the logical file and omit the
others (selection)
49Week 8 Logical Files (Continued)
- Basic functions (continued)
- Include in the logical file only those fields
necessary to the user/application from the
physical-file record format, thus ensuring that
users have access to data strictly on a
need-to-know basis (projection) - Combine data elements (fields) from two or more
physical files into a single logical-file record
format by matching records from the physical
files with the value of a common field (join)
50Week 8 Logical Files (Continued)
- Three distinct types of logical files exist
- Simple
- Join
- Multiple-format
51Week 8Describing a Simple Logical File
- Simple logical files are created over a single
physical file that must already exist as a FILE
type object. - When describing a simple logical file, name the
underlying physical file in the DDS record-format
statement using the PFILE() keyword.
52Week 8Alternate Access Path
- Physical files can have only one keyed-sequence
access path, and logical files provide the
capability to access the data in physical files
using different (alternate) keys. - When you use the physical files record-format
name for the logical file and include no
field-level entries, the logical file copies the
physical files record format as it exists at the
time the logical file is created.
53Week 8 Alternate Access Path (Continued)
- All fields currently in the physical file are
included in the logical file -- with the same
attributes. - The record-format entry must also identify the
based-on physical file as the value of the PFILE
keyword. - The only other entries needed are those to
identify the key.
54Week 8 Alternate Access Path (Continued)
- You can use the same record-format name as the
physical files record format when you do this
and supply no field attributes, the logical file
includes all the fields from the physical file
with their same attributes. - However, its wise to list all fields to be
included in the logical file even when the list
exactly matches the current field list of the
based-on physical file.
55Week 8 Alternate Access Path (Continued)
- Summary
-
- To build a logical file whose only purpose is to
provide an alternate access path over the
physical file, code keyword PFILE in the
record-format entry and list the fields to be
included by name. - Following the field list is a key-level entry
(or entries), with a K in DDS column 17, to
identify the key fields(s).
56Week 8Selection
- When a logical file uses selection, its
population is limited to a certain group of
records from the underlying physical file. - Selection lets users work only with the data
records needed for an application, and it
protects excluded data from users who do not need
that data or are not authorized to it.
57Week 8Selection (Continued)
- On the AS/400, implement selection in DDS by
using Select an Omit entries and by specifying
keywords that define how the selection/omit
operation is to occur Select/Omit entries are
used only with logical files.
58Week 8 Projection
- Projection has to do with limiting access to
fields of a physical file that are sensitive and
need to be secured or are unnecessary for a given
user or application. - When you use projection, the logical-file record
format included only those fields needed by the
applications that use the logical file. - Projection works for field security in much the
same way that selection works for record
security The restricted fields are excluded from
the logical files record.
59Week 8 Projection (Continued)
- When you specify field names, as you do with
projection, you can use a record-format name
different from that of the underlying physical
file. -
60Week 8 Projection (Continued)
- You can also combine projection with selection
and the use of an alternate access path within a
single logical file.
61Week 8Creating Join Logical Files
- A Join Logical file lets you include fields from
two or more related physical files in a single
record format, giving you a convenient way to
pull together data from several physical files
under one logical file with a single name. - Though you can use join logical files to display
information or print reports, you cannot use join
logical files to update underlying physical files
and you cannot use DFU with join logical files.
62Week 8Creating Join Logical Files (Continued)
- Query/400 supports join logical files and treats
the files like any other physical or simple
logical file when the join operation has been
specified in the logical-file description.