0
Week # 6 - Agenda <ul><li>Review Test # 1 </li></ul><ul><li>DB2/400 Overview </li></ul>
DB2/400 <ul><li>What is it? </li></ul><ul><li>Many ‘types’ of files </li></ul><ul><li>Program-described files </li></ul><u...
DB2/400 <ul><li>Characteristics of a Physical File  - one record format  - contains DDS & data  - supports multiple member...
DB2/400 <ul><li>Characteristics of a Logical file  - multiple record formats  - contains DDS  - has access paths  - replac...
DB2/400 <ul><li>What is a LEVEL CHECK? </li></ul><ul><li>How to create random access with a ‘key’ </li></ul>
Week # 6 Lesson Overview <ul><li>Objectives: </li></ul><ul><li>Introduce the concept of externally described files </li></...
Week # 6  File Varieties <ul><li>On the AS/400, all  “files”  are classified as object type *FILE. </li></ul><ul><li>Withi...
Week # 6  File Varieties (continued) <ul><li>Common file attributes: </li></ul><ul><li>PRTF --  Printer files format outpu...
Week # 6  File Varieties (Continued) <ul><li>PF --  Physical files have two distinct functions: to hold and organize user ...
Week # 6  File Varieties (Continued) <ul><li>LF --  Logical files are created over physical database files and cannot be c...
Week # 6  Program-Described Files <ul><li>Physical files described at the record level contain  </li></ul><ul><li>Record n...
Week # 6  Program-Described Files (Continued) <ul><li>Program-described files can be useful when you need to: </li></ul><u...
Week # 6  Externally Described Files <ul><li>Externally described files are physical files that contain detailed field-lev...
Week # 6  Externally Described Files (Continued) <ul><li>Standardized record formats  -- Because field attributes (includi...
Week # 6   Externally Described Files (Continued) <ul><li>Utilities that are easier to use  -- Because externally describe...
Week # 6   Externally Described Files (Continued) <ul><li>Less tedious programming  -- When programmers use externally des...
Week # 6   Externally Described Files (Continued) <ul><li>Externally described files contain information at four levels of...
Week # 6 Externally Described Files (Continued) <ul><li>After you run the DSPFFD command on a database physical file, you ...
Week # 6 Externally Described Files (Continued) <ul><li>The record-format information lists the name of the record format....
Week # 6 Externally Described Files (Continued) <ul><li>The essence of an externally described file is in the  field-level...
Week # 6   Externally Described Files (Continued) <ul><li>Character-type fields also have a Coded Character Set Identifier...
Week # 6   Creating an Externally Described Database File <ul><li>The process of creating an externally described database...
Week # 6 Creating an Externally Described Database File (Continued) <ul><li>Create  -- After you describe the file, you ca...
Week # 6  SQL <ul><li>SQL is a powerful relational database language supported by OS/400 that is standardized, has wide su...
Week # 6  SQL (Continued) <ul><li>Using SQL to define, control, and manipulate database files has drawbacks: </li></ul><ul...
Week # 6  DDS <ul><li>DDS is a language used to code source descriptions for several types of files, including: </li></ul>...
Week # 6  DDS Record-Format Entry <ul><li>In a DDS file description, several different types of records may be used; not a...
Week # 6   DDS Record-Format Entry (Continued) <ul><li>To describe a simple physical file:  Minimum requirements would inc...
Week # 6   DDS Record-Format Entry (Continued) <ul><li>On the next screen that comes up, you can see that a sequence numbe...
Week # 6   Field-Level Entries <ul><li>After you insert a record-format line, you can enter  field-level specifications . ...
Week # 6   Field-Level Entries (Continued) <ul><li>For numeric fields, you must also enter the number of decimal positions...
Week # 6    Field-Level Entries (Continued) <ul><li>Name.  For record and field names, use from one to 10 characters, the ...
Week # 6    Field-Level Entries (Continued) <ul><li>Length.  Length is the number of characters or digits in the field. Fo...
Week # 6    Field-Level Entries (Continued) <ul><li>Length and data type are related.  Each data type has a valid maximum ...
Week # 6    Field-Level Entries (Continued) <ul><li>For numeric data types, the length specification really means the numb...
Week # 6 Field-Level Entries (Continued) <ul><li>A date field can have three different lengths, depending on which date fo...
Week # 6   Field-Level Entries (Continued) <ul><li>Timestamp data includes both the date and the time and is formatted as ...
Week # 6    Field-Level Entries (Continued) <ul><li>An advantage of using date type fields is that they use four digits to...
Week # 6   Field-Level Entries (Continued) <ul><li>Data type.  Ref. the previous table listing the data types most commonl...
Week # 6   Field-Level Entries (Continued) <ul><li>Advantages of storing numeric data in packed-decimal format: </li></ul>...
Week # 6  Field-Level Entries (Continued) <ul><li>NOTE:  If you don’t explicitly provide a data type, the default is  A  (...
Week # 6  Physical Files and Access Paths <ul><li>Externally described physical files contain data records whose format is...
Week # 6   Physical Files and Access Paths (Continued) <ul><li>The record format provides a blueprint of a record’s fields...
Week # 6  Arrival-Sequence Access Paths <ul><li>On the AS/400, there are two kinds of access paths, one of which every fil...
Week # 6  Sequential Retrieval <ul><li>With sequential record retrieval, records are presented one after another in the or...
Week # 6  Direct Retrieval <ul><li>Direct retrieval (random access) implies that you can access a specific record in a fil...
Week # 6  Keyed-Sequence Access Paths <ul><li>To read an entire file or access an individual record by the value of a cert...
Week # 6   Keyed-Sequence Access Paths (Continued) <ul><li>For any file accessed often using the value of a certain field,...
Week # 6  Keyed-Sequence Access Paths (Continued) <ul><li>Specifying Key Fields (continued): </li></ul><ul><li>When UNIQUE...
Week # 6   Keyed-Sequence Access Paths (Continued) <ul><li>Specifying Key Fields (continued): </li></ul><ul><li>You code k...
Week # 6  Logical Files <ul><li>Logical files: </li></ul><ul><li>Represent different ways to present all or part of the da...
Week # 6  Logical Files (Continued) <ul><li>A physical file must exist before any logical file can be based on it; many di...
Week # 6  Logical Files (Continued) <ul><li>These basic functions include the ability to: </li></ul><ul><li>Allow the rand...
Week # 6   Logical Files (Continued) <ul><li>Basic functions (continued): </li></ul><ul><li>Include in the logical file on...
Week # 6  Logical Files (Continued) <ul><li>Three distinct types of logical files exist: </li></ul><ul><li>Simple </li></u...
Week # 6  Describing a Simple Logical File <ul><li>Simple logical files are created over a single physical file that must ...
Week # 6  Alternate Access Path <ul><li>Physical files can have only one keyed-sequence access path, and logical files pro...
Week # 6   Alternate Access Path (Continued) <ul><li>All fields currently in the physical file are included in the logical...
Week # 6  Alternate Access Path (Continued) <ul><li>You can use the same record-format name as the physical file’s record ...
Week # 6 Alternate Access Path (Continued) <ul><li>Summary: </li></ul><ul><li>To build a logical file whose only purpose i...
Week # 6  Selection <ul><li>When a logical file uses selection, its population is limited to a certain group of records fr...
Week # 6  Selection (Continued) <ul><li>On the AS/400, implement selection in DDS by using Select an Omit entries and by s...
Week # 6 Projection <ul><li>Projection has to do with limiting access to fields of a physical file that are sensitive and ...
Week # 6   Projection (Continued) <ul><li>When you specify field names, as you do with projection, you can use a record-fo...
Week # 6   Projection (Continued) <ul><li>You can also combine projection with selection and the use of an alternate acces...
Week # 6  Creating Join Logical Files <ul><li>A  Join Logical  file lets you include fields from two or more related physi...
Week # 6  Creating Join Logical Files (Continued) <ul><li>Query/400 supports join logical files and treats the files like ...
Upcoming SlideShare
Loading in...5
×

Lecture # 6

523

Published on

0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total Views
523
On Slideshare
0
From Embeds
0
Number of Embeds
0
Actions
Shares
0
Downloads
6
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

Transcript of "Lecture # 6"

  1. 1. Week # 6 - Agenda <ul><li>Review Test # 1 </li></ul><ul><li>DB2/400 Overview </li></ul>
  2. 2. DB2/400 <ul><li>What is it? </li></ul><ul><li>Many ‘types’ of files </li></ul><ul><li>Program-described files </li></ul><ul><li>Externally-described files </li></ul>
  3. 3. DB2/400 <ul><li>Characteristics of a Physical File - one record format - contains DDS & data - supports multiple members - supports date data field </li></ul>
  4. 4. DB2/400 <ul><li>Characteristics of a Logical file - multiple record formats - contains DDS - has access paths - replaces SORT routines </li></ul>
  5. 5. DB2/400 <ul><li>What is a LEVEL CHECK? </li></ul><ul><li>How to create random access with a ‘key’ </li></ul>
  6. 6. Week # 6 Lesson Overview <ul><li>Objectives: </li></ul><ul><li>Introduce the concept of externally described files </li></ul><ul><li>Explain how to use the Data Description Specifications (DDS) language to describe Physical and Logical database files </li></ul><ul><li>Describe the difference between externally described files and program-described files </li></ul>
  7. 7. Week # 6 File Varieties <ul><li>On the AS/400, all “files” are classified as object type *FILE. </li></ul><ul><li>Within that classification, AS/400 recognizes 12 varieties of objects. </li></ul><ul><li>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. </li></ul>
  8. 8. Week # 6 File Varieties (continued) <ul><li>Common file attributes: </li></ul><ul><li>PRTF -- Printer files format output from programs or utilities to create spooled print files in output queues. </li></ul><ul><li>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. </li></ul>
  9. 9. Week # 6 File Varieties (Continued) <ul><li>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. </li></ul><ul><li>In the latter capacity, physical files are similar to source-program libraries or source-file subdirectories used by other operating systems. </li></ul><ul><li>Under OS/400, an attribute identifier distinguishes these two functions: PF-DTA for data physical files and PF-SRC for source physical files. </li></ul>
  10. 10. Week # 6 File Varieties (Continued) <ul><li>LF -- Logical files are created over physical database files and cannot be created before the physical file or files with which they are associated. </li></ul><ul><li>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. </li></ul><ul><li>Think of logical files as “filters” or limiting “views” of data stored in physical files. </li></ul><ul><li>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). </li></ul>
  11. 11. Week # 6 Program-Described Files <ul><li>Physical files described at the record level contain </li></ul><ul><li>Record name </li></ul><ul><li>Record length </li></ul><ul><li>Any program using a file described this way must supply field-level attributes for every field in the record. </li></ul><ul><li>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. </li></ul>
  12. 12. Week # 6 Program-Described Files (Continued) <ul><li>Program-described files can be useful when you need to: </li></ul><ul><ul><li>Convert older, non-relational files to the AS/400 relational database format </li></ul></ul><ul><ul><li>Move files from another system to the AS/400 </li></ul></ul><ul><li>Permanent use of program-described files is not recommended because having to describe a record’s fields in every program that uses the file is tedious and prone to errors. </li></ul>
  13. 13. Week # 6 Externally Described Files <ul><li>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. </li></ul><ul><li>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 object’s name. </li></ul>
  14. 14. Week # 6 Externally Described Files (Continued) <ul><li>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. </li></ul><ul><li>Also, with externally described files it is impossible to access data fields incorrectly as far as field length, data type, or number of decimal positions when using the file because the file object itself contains these critical attributes. </li></ul><ul><li>To check or compare an externally described file’s record format, execute a DSPFFD (Display File Field Description) command on the file object. </li></ul>
  15. 15. Week # 6 Externally Described Files (Continued) <ul><li>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. </li></ul><ul><li>Less work is therefore required on the programmer’s part when using these utilities to update data files, create queries and reports, and code display files. </li></ul>
  16. 16. Week # 6 Externally Described Files (Continued) <ul><li>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. </li></ul><ul><li>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. </li></ul>
  17. 17. Week # 6 Externally Described Files (Continued) <ul><li>Externally described files contain information at four levels of data hierarchy: </li></ul><ul><li>file level </li></ul><ul><li>Member level </li></ul><ul><li>record-format level </li></ul><ul><li>field level </li></ul><ul><li>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 command’s only required parameter is the file name). </li></ul>
  18. 18. Week # 6 Externally Described Files (Continued) <ul><li>After you run the DSPFFD command on a database physical file, you get the display file field description screen displaying: </li></ul><ul><ul><ul><ul><ul><li>File name </li></ul></ul></ul></ul></ul><ul><ul><ul><ul><ul><li>Library name </li></ul></ul></ul></ul></ul><ul><ul><ul><ul><ul><li>File location </li></ul></ul></ul></ul></ul><ul><ul><ul><ul><ul><li>Externally described (Yes/No) </li></ul></ul></ul></ul></ul><ul><ul><ul><ul><ul><li>Number of record formats </li></ul></ul></ul></ul></ul><ul><ul><ul><ul><ul><li>File type </li></ul></ul></ul></ul></ul>
  19. 19. Week # 6 Externally Described Files (Continued) <ul><li>The record-format information lists the name of the record format. A record format name is mandatory in defining a physical file. </li></ul><ul><li>The system also uses a format level identifier to ensure that programs and files agree on version. This prevents a ‘LEVEL CHECK ’ error. </li></ul><ul><li>The second screen of the display shows two additional record-format attributes: </li></ul><ul><li>Number of fields </li></ul><ul><li>Record length </li></ul>
  20. 20. Week # 6 Externally Described Files (Continued) <ul><li>The essence of an externally described file is in the field-level information . </li></ul><ul><li>For each field, the system records: </li></ul><ul><li>Name </li></ul><ul><li>Data type </li></ul><ul><li>Length (characters and digits) </li></ul><ul><li>Position in the record buffer </li></ul><ul><li>Length in bytes </li></ul><ul><li>Field usage (input, output, both) </li></ul><ul><li>Column heading for use by utilities </li></ul>
  21. 21. Week # 6 Externally Described Files (Continued) <ul><li>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. </li></ul><ul><li>Once each file’s information is recorded, the information never needs to be repeated and is available for programs and utilities to use and for you to see. </li></ul><ul><li>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. </li></ul>
  22. 22. Week # 6 Creating an Externally Described Database File <ul><li>The process of creating an externally described database physical file involves three distinct steps: </li></ul><ul><ul><li>Describe -- You must first describe the file’s 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). </li></ul></ul>
  23. 23. Week # 6 Creating an Externally Described Database File (Continued) <ul><li>Create -- After you describe the file, you can create the file object by compiling the source-language file description. </li></ul><ul><li>This step is analogous to creating an executable machine-level object program by compiling a Cobol or RPG source program. </li></ul><ul><ul><li>Insert data -- When you’ve successfully compiled the source description into a *FILE type object, you can insert, or load, data into the file. </li></ul></ul>
  24. 24. Week # 6 SQL <ul><li>SQL is a powerful relational database language supported by OS/400 that is standardized, has wide support, and is highly portable. It lets you: </li></ul><ul><li>Describe and create physical or logical files </li></ul><ul><li>Limit access to, maintain, and retrieve information from files, regardless of whether they were created with SQL </li></ul>
  25. 25. Week # 6 SQL (Continued) <ul><li>Using SQL to define, control, and manipulate database files has drawbacks: </li></ul><ul><li>The SQL licensed program product is not part of the AS/400’s base operating-system support </li></ul><ul><li>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 </li></ul><ul><li>Mastering SQL requires time and practice </li></ul><ul><li>The object overhead created by SQL collections, catalogs, etc., is substantial </li></ul><ul><li>You cannot use SQL alone to describe and create a display file -- you need another tool for display files </li></ul>
  26. 26. Week # 6 DDS <ul><li>DDS is a language used to code source descriptions for several types of files, including: </li></ul><ul><li>Physical and logical database files </li></ul><ul><li>Display Files </li></ul><ul><li>Printer Files </li></ul>
  27. 27. Week # 6 DDS Record-Format Entry <ul><li>In a DDS file description, several different types of records may be used; not all are required for every file description. </li></ul><ul><li>For a physical file, the record types are: </li></ul><ul><li>File -- blank name type; optional; when used, must precede record type </li></ul><ul><li>Record -- R name type; one required for physical file </li></ul><ul><li>Field -- blank name type; describes fields; follows record; almost always present </li></ul><ul><li>Key -- K name type; optional; follows field entries </li></ul>
  28. 28. Week # 6 DDS Record-Format Entry (Continued) <ul><li>To describe a simple physical file: Minimum requirements would include only a record-format line and a few field entries. </li></ul><ul><li>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 screen’s work area and a new, empty prompt is provided. </li></ul>
  29. 29. Week # 6 DDS Record-Format Entry (Continued) <ul><li>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. </li></ul>
  30. 30. Week # 6 Field-Level Entries <ul><li>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: </li></ul><ul><ul><li>Name (field name) </li></ul></ul><ul><ul><li>Length (number of characters or digits) </li></ul></ul><ul><ul><li>Data Type (e.g., character, zoned decimal, packed decimal, binary, date, time) </li></ul></ul>
  31. 31. Week # 6 Field-Level Entries (Continued) <ul><li>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: </li></ul><ul><li>Name </li></ul><ul><li>Length </li></ul><ul><li>Data type </li></ul><ul><li>Decimal positions (numeric types) </li></ul>
  32. 32. Week # 6 Field-Level Entries (Continued) <ul><li>Name. For record and field names, use from one to 10 characters, the first of which must be uppercase alphabetic (A–Z) or one of the special characters @, $, or #. </li></ul><ul><li>Subsequent characters can consist of any of these, the numbers 0 through 9, and the underscore character (_). </li></ul><ul><li>Embedded blanks are not allowed in a name. Within a record format, field names must be unique. </li></ul>
  33. 33. Week # 6 Field-Level Entries (Continued) <ul><li>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. </li></ul><ul><li>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. </li></ul><ul><li>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. </li></ul>
  34. 34. Week # 6 Field-Level Entries (Continued) <ul><li>Length and data type are related. Each data type has a valid maximum length: </li></ul><ul><li>Data Types and Maximum Lengths: </li></ul><ul><li>Abbreviation Data type Maximum length </li></ul><ul><li>P Packed decimal 31 digits </li></ul><ul><li>S Zoned decimal 31 digits </li></ul><ul><li>B Binary 9 digits </li></ul><ul><li>F Floating-point (short) 9 digits </li></ul><ul><li>F Floating-point (long) 17 digits </li></ul><ul><li>A Character 32,766 characters </li></ul><ul><li>H Hexadecimal 32,766 bytes </li></ul><ul><li>L Date 6, 8, or 10 characters </li></ul><ul><li>T Time 8 characters </li></ul><ul><li>Z Timestamp 26 characters </li></ul>
  35. 35. Week # 6 Field-Level Entries (Continued) <ul><li>For numeric data types, the length specification really means the number of digits in the field. </li></ul><ul><li>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. </li></ul><ul><li>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. </li></ul>
  36. 36. Week # 6 Field-Level Entries (Continued) <ul><li>A date field can have three different lengths, depending on which date format is specified by the DATFMT keyword in DDS. </li></ul><ul><li>If you do not use keyword DATFMT, the default is * ISO format (International Standards Organization), whose display format is yyyy-mm-dd (10 characters). </li></ul><ul><li>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(':'). </li></ul>
  37. 37. Week # 6 Field-Level Entries (Continued) <ul><li>Timestamp data includes both the date and the time and is formatted as yyyy-mm-dd-hh.mm.ss.uuuuuu (26 characters), where uuuuuu represents millionths of a second. </li></ul>
  38. 38. Week # 6 Field-Level Entries (Continued) <ul><li>An advantage of using date type fields is that they use four digits to record the year. </li></ul><ul><li>Programs using files with four-digit years (e.g., a DATFMT value of *ISO or *USA) would have had few Year 2000 modification problems. </li></ul><ul><li>A less obvious advantage is the ability to perform date duration calculations easily. </li></ul>
  39. 39. Week # 6 Field-Level Entries (Continued) <ul><li>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. </li></ul><ul><li>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). </li></ul><ul><li>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.) </li></ul><ul><li>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. </li></ul>
  40. 40. Week # 6 Field-Level Entries (Continued) <ul><li>Advantages of storing numeric data in packed-decimal format: </li></ul><ul><li>The field itself is smaller (requiring fewer bytes of storage space) </li></ul><ul><li>Arithmetic and logic operations are more efficient (requiring fewer intermediate conversion steps) </li></ul><ul><li>Minor disadvantages to storing numbers as packed decimal: </li></ul><ul><li>A zoned-decimal numeric field of a physical file can be redefined as a character field through a logical file </li></ul><ul><li>You cannot directly observe the packed-decimal field value by using a DSPPFM (Display Physical File Member) command, which does no conversion </li></ul>
  41. 41. Week # 6 Field-Level Entries (Continued) <ul><li>NOTE: If you don’t 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. </li></ul>
  42. 42. Week # 6 Physical Files and Access Paths <ul><li>Externally described physical files contain data records whose format is defined according to a specific layout; this record format: </li></ul><ul><li>• Specifies the name and relative order of fields </li></ul><ul><li>• Identifies each field’s data type and length </li></ul><ul><li>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. </li></ul>
  43. 43. Week # 6 Physical Files and Access Paths (Continued) <ul><li>The record format provides a blueprint of a record’s fields; it does not tell us in what order records of data can be made available to applications. </li></ul><ul><li>This information -- describing the way in which records can be read or retrieved from files -- is called an access path . </li></ul>
  44. 44. Week # 6 Arrival-Sequence Access Paths <ul><li>On the AS/400, there are two kinds of access paths, one of which every file uses: </li></ul><ul><li>• Arrival-sequence </li></ul><ul><li>• Keyed-sequence </li></ul><ul><li>Records are both stored and retrieved in arrival sequence (order in which they were added to the file) unless otherwise specified. </li></ul><ul><li>Files using arrival-sequence access paths may have their records read sequentially or directly. </li></ul>
  45. 45. Week # 6 Sequential Retrieval <ul><li>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. </li></ul><ul><li>The order in which a DSPPFM (Display Physical File Member) command lists records is in arrival sequence. </li></ul><ul><li>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. </li></ul>
  46. 46. Week # 6 Direct Retrieval <ul><li>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. </li></ul><ul><li>Any record in an arrival-sequence file can be retrieved directly if its relative record number is known. </li></ul><ul><li>Relative record numbers are assigned to records as they are added to a file in a consecutive series of integers, starting from 1. </li></ul><ul><li>HLL programs can read a file randomly by relative record number. </li></ul>
  47. 47. Week # 6 Keyed-Sequence Access Paths <ul><li>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. </li></ul><ul><li>A program can then process the file’s records in key-field order instead of arrival sequence. </li></ul>
  48. 48. Week # 6 Keyed-Sequence Access Paths (Continued) <ul><li>For any file accessed often using the value of a certain field, specify a keyed-sequence access path when the file is created. </li></ul><ul><li>Key fields are specified in the DDS source code of the file description, and the key itself can be a single field in the file’s record format or consist of several fields used together (a composite key). </li></ul><ul><li>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. </li></ul>
  49. 49. Week # 6 Keyed-Sequence Access Paths (Continued) <ul><li>Specifying Key Fields (continued): </li></ul><ul><li>When UNIQUE is not used, the system lets records having the same key-field values be stored in the file. </li></ul>
  50. 50. Week # 6 Keyed-Sequence Access Paths (Continued) <ul><li>Specifying Key Fields (continued): </li></ul><ul><li>You code keyword UNIQUE in DDS as a file-level entry before the record-format specification line. </li></ul><ul><li>The actual declaration of the key follows the field-level DDS specifications. </li></ul><ul><li>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. </li></ul>
  51. 51. Week # 6 Logical Files <ul><li>Logical files: </li></ul><ul><li>Represent different ways to present all or part of the data of one or more physical files </li></ul><ul><li>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) </li></ul><ul><li>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) </li></ul>
  52. 52. Week # 6 Logical Files (Continued) <ul><li>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. </li></ul><ul><li>Logical files, which generally correspond to views in a relational database, need to be able to perform several basic functions on physical-file data. </li></ul>
  53. 53. Week # 6 Logical Files (Continued) <ul><li>These basic functions include the ability to: </li></ul><ul><li>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 </li></ul><ul><li>Select only certain records of the physical file to be included in the logical file and omit the others (selection) </li></ul>
  54. 54. Week # 6 Logical Files (Continued) <ul><li>Basic functions (continued): </li></ul><ul><li>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) </li></ul><ul><li>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) </li></ul>
  55. 55. Week # 6 Logical Files (Continued) <ul><li>Three distinct types of logical files exist: </li></ul><ul><li>Simple </li></ul><ul><li>Join </li></ul><ul><li>Multiple-format </li></ul>
  56. 56. Week # 6 Describing a Simple Logical File <ul><li>Simple logical files are created over a single physical file that must already exist as a *FILE type object. </li></ul><ul><li>When describing a simple logical file, name the underlying physical file in the DDS record-format statement using the PFILE() keyword. </li></ul>
  57. 57. Week # 6 Alternate Access Path <ul><li>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. </li></ul><ul><li>When you use the physical file’s record-format name for the logical file and include no field-level entries, the logical file copies the physical file’s record format as it exists at the time the logical file is created. </li></ul>
  58. 58. Week # 6 Alternate Access Path (Continued) <ul><li>All fields currently in the physical file are included in the logical file -- with the same attributes. </li></ul><ul><li>The record-format entry must also identify the based-on physical file as the value of the PFILE keyword. </li></ul><ul><li>The only other entries needed are those to identify the key. </li></ul>
  59. 59. Week # 6 Alternate Access Path (Continued) <ul><li>You can use the same record-format name as the physical file’s 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. </li></ul><ul><li>However, it’s 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. </li></ul>
  60. 60. Week # 6 Alternate Access Path (Continued) <ul><li>Summary: </li></ul><ul><li>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. </li></ul><ul><li>Following the field list is a key-level entry (or entries), with a K in DDS column 17, to identify the key fields(s). </li></ul>
  61. 61. Week # 6 Selection <ul><li>When a logical file uses selection, its population is limited to a certain group of records from the underlying physical file. </li></ul><ul><li>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. </li></ul>
  62. 62. Week # 6 Selection (Continued) <ul><li>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. </li></ul>
  63. 63. Week # 6 Projection <ul><li>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. </li></ul><ul><li>When you use projection, the logical-file record format included only those fields needed by the applications that use the logical file. </li></ul><ul><li>Projection works for field security in much the same way that selection works for record security: The restricted fields are excluded from the logical file’s record. </li></ul>
  64. 64. Week # 6 Projection (Continued) <ul><li>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. </li></ul>
  65. 65. Week # 6 Projection (Continued) <ul><li>You can also combine projection with selection and the use of an alternate access path within a single logical file. </li></ul>
  66. 66. Week # 6 Creating Join Logical Files <ul><li>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. </li></ul><ul><li>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. </li></ul>
  67. 67. Week # 6 Creating Join Logical Files (Continued) <ul><li>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. </li></ul>
  1. A particular slide catching your eye?

    Clipping is a handy way to collect important slides you want to go back to later.

×