efe9d678e76b80bcda127e19237ffdc4.ppt
- Количество слайдов: 33
Externally Described Files Chapter 6 Presentation © Copyright 2002, Bryan Meyers
Objectives: • Define physical and logical files • Discuss data types • Discuss storage implications of numeric and character types • Access physical and logical files from an RPG program • Discuss field reference files • Define externally described printer files Programming in RPG IV Third Edition 2
Physical File • Stores data records • Can be defined as key sequence – Designate a key • Can be defined as arrival sequence – First-in, first-out • If the key field is not defined, then access is limited to arrival sequence Programming in RPG IV Third Edition 3
Logical File • Does not actually contain data • Stores access paths – Pointers to records in physical files • RPG programs use logical files just as though the logical files themselves contained data Programming in RPG IV Third Edition 4
Introduction to DDS • Use SEU to create a source member of definition statements • Source type for physical files is PF • Source type for logical files is LF • Description Specifications (DDS) define files • File, record and field level keywords are used to define a file • CRTPF command creates physical file from DDS source – CRTLF command creates logical file Programming in RPG IV Third Edition 5
Physical File Example *. . 1. . +. . 2. . +. . 3. . +. . 4. . +. . 5. . +. . 6. . +. . 7. . +. . 8 A* T. Name++++++RLen++TDp. B Functions A UNIQUE A R EMPREC A EMPNO 9 S 0 A LNAME 15 A A FNAME 10 A A DEPT 3 A A SALARY 6 P 0 A STREET 15 A A CITY 15 A A STATE 2 A A ZIP 5 S 0 A K EMPNO Programming in RPG IV Third Edition 6
Data Types and Data Storage • • A = Character S = Zoned decimal B = Binary P = Packed decimal Programming in RPG IV Third Edition 7
Packed Decimal • Only the digit (low order) bits of a number are stored • Sign occupies right-most four bit positions • i. Series converts all numeric data to packed decimal before values are used in calculations • Packed fields take (n+1)/2 bytes of storage – n=number of digits Programming in RPG IV Third Edition 8
Extended Binary Coded Decimal Interchange (EBCDIC) Digit 0 1 2 3 4 5 6 7 8 9 Programming in RPG IV Third Edition EBCDIC 11110000 11110001 11110010 11110011 11110100 11110101 11110110 11110111 11111000 11111001 9
Zoned Decimal Representation Digit +1 -1 10 -10 22 99 100 -999 Programming in RPG IV Third Edition EBCDIC 11110001 11010001 11110001 11110010 11111001 11110001 ____ 11110000 11010000 11110010 11111001 11110000 ____ # of Bytes 1 1 2 2 11110000 3 ____ 10
Packed Decimal Representation Digit +1 -1 10 -10 22 99 100 -999 Programming in RPG IV Third Edition EBCDIC 00011111 00011101 000000010 00001001 00010000 ____ 00001111 00001101 00101111 10011111 00001111 ____ # of Bytes 1 1 2 2 2 11
Simple Logical Files • Contain the record level keyword PFILE and the name of the physical file • Have one or more field level keywords • Widely used to change the retrieval order of records in a file – Same as physically sorting a physical file Programming in RPG IV Third Edition 12
Simple Logical File Example *. . 1. . +. . 2. . +. . 3. . +. . 4. . +. . 5. . +. . 6. . +. . 7. . +. . 8 A* T. Name++++++RLen++TDp. B Functions A R EMPREC PFILE(EMPMST) A K LNAME Programming in RPG IV Third Edition 13
Simple Logical File Example *. . 1. . +. . 2. . +. . 3. . +. . 4. . +. . 5. . +. . 6. . +. . 7. . +. . 8 A* T. Name++++++RLen++TDp. B Functions A R EMPREC 1 PFILE(EMPMST) A EMPNO A LNAME A FNAME A DEPT A SALARY A K DEPT A K EMPNO Programming in RPG IV Third Edition 14
Simple Logical File Example *. . 1. . +. . 2. . +. . 3. . +. . 4. . +. . 5. . +. . 6. . +. . 7. . +. . 8 A* T. Name++++++RLen++TDp. B Functions A R EMPREC 1 PFILE(EMPMST) A EMPNO A LNAME A FNAME A DEPT A SALARY A K DEPT A K EMPNO A S DEPT VALUES(‘MIS’ ‘ACT’) Programming in RPG IV Third Edition 15
Multiple Record Formats • Defined based on two or more physical files • Each format is based on a different physical file • Gives the appearance that the two physical files have been merged together Programming in RPG IV Third Edition 16
Multiple Record Formats *. . 1. . +. . 2. . +. . 3. . +. . 4. . +. . 5. . +. . 6. . +. . 7. . +. . 8 A* T. Name++++++RLen++TDp. B Functions A R STUDREC PFILE(STUDMAST) A K STUD_NO * A R CRSEREC PFILE(STUDCRSE) A K STUD_NO A K SEMESTER Programming in RPG IV Third Edition 17
Join Logical Files • Fields are combined from different physical files into a single record • JFILE signals which physical files are used by the logical file • JOIN designates which physical files are used in this join • JFLD keyword indicates which fields’ values are to be matched Programming in RPG IV Third Edition 18
Join Logical File Example *. . 1. . +. . 2. . +. . 3. . +. . 4. . +. . 5. . +. . 6. . +. . 7. . +. . 8 A* T. Name++++++RLen++TDp. B Functions A A A A A R EMPREC J Programming in RPG IV Third Edition JFILE(ORDERS INVENT) JOIN(ORDERS INVENT) JFLD(PART_NUM PART_NO) ORDER_NO CUST_NO PART_NO DESCRPT SELL_PRICE QTY_ORD 19
Externally Defined Files • Code an ‘E’ in position 22 on the F spec • Omit any entry for record length • If file is keyed, code a ‘K’ in position 34 – Omitting the ‘K’ results in record retrieval based on arrival sequence • Input specs not needed for externally defined files • Program makes no distinction made between physical and logical files • If you change a file (physical or logical) after you have compiled a program using that file, you must recompile the program *. . 1. . . +. . . 2. . . +. . . 3. . . +. . . 4. . . +. . . 5. . . +. . . 6. . . +. . . 7. . . +. . . 8 FFilename++IPEASFRlen+LKlen+AIDevice+. Keywords+++++++++++++++ FEmp. Master IF E K DISK Programming in RPG IV Third Edition 20
Additional Database Concepts • Keywords can be used for data validity checks, for interactive data entry, and editing output • Data dictionary or Field Reference File is used to provide field definitions for use in subsequent file creation – You never actually use this file for data storage Programming in RPG IV Third Edition 21
Additional Database Concepts • To use a field from the Field Reference File, use the file-level keyword REF and code an ‘R’ in positions 29 on the field referenced • Field-reference files can enforce a uniformity and consistency • File names should consist of an agreedupon mnemonic prefix to denote the system Programming in RPG IV Third Edition 22
Database File Naming • File names should contain a short alphabetic mnemonic code to uniquely identify the file – Often related to key field • Suffix of P (Physical), L (logical), F (field reference), S (screen), R (report) – and a number to differentiate between similar files • CCSSTUP - CCS system, student, physical file Programming in RPG IV Third Edition 23
Externally Described Printer Files • Printer files can be created the same as physical files – Use CRTPRTF command • DDS – Each record format begins with an ‘R’ in position 17 – Specify the field’s or constant’s beginning position • Where it starts on the line – Use SPACEA, SPACEB, SKIPA, and SKIPB keywords for spacing and skipping – Use DATE and PAGNBR for UDATE and PAGE – Use EDTWRD and EDTCDE keywords for editing Programming in RPG IV Third Edition 24
Externally Described PRTF *. . 1. . +. . 2. . +. . 3. . +. . 4. . +. . 5. . +. . 6. . +. . 7. . +. . 8 A* T. Name++++++RLen++TDp. BLin. Pos. Functions A R HEADINGS SKIPB(1) A 10 DATE EDTCDE(Y) A 22’SALES REPORT’ A 37’PAGE’ A 42 PAGNBR EDTCDE(3) A SPACEA(2) A 14’SLSPSN. ’ A 34’AMT. ’ A SPACEA(2) A R DETAILLINE SPACEA(1) A SALESPRSN 4 15 A SALESAMT 6 2 32 EDTCDE(1) A R BREAKLINE SPACEB(1) SPACEA(2) A 20’TOTAL’ A SLSPTOTAL 6 2 31 EDTCDE(1) A 40’*’ A R TOTALLINE A 16’GRAND TOTAL’ A GRANDTOTAL 8 2 30 EDTCDE(1) Programming in RPG IV Third Edition 25
Externally Described Printer Files • File Specification – Code printer file name • Not QPRINT – – ‘E’ in position 19 Omit any entry for record length Device (36 -42) must be PRINTER The overflow indicator cannot be OA - OF or OV • Use OFLIND keyword to specify almost anything else (*IN 10, *IN 11, *IN 99 etc. ) • Named indicators also allowed *. . 1. . . +. . . 2. . . +. . . 3. . . +. . . 4. . . +. . . 5. . . +. . . 6. . . +. . . 7. . . +. . . 8 FFilename++IPEASFRlen+LKlen+AIDevice+. Keywords+++++++++++++++ FSales. Rpt O E PRINTER Ofl. Ind(End. Of. Page) Programming in RPG IV Third Edition 26
Externally Described Printer Files • Calculation Specifications – Use WRITE instead of EXCEPT • Output Specifications not needed Programming in RPG IV Third Edition 27
Points to Remember • The i. Series defines data files independently of your programs • Physical files contain data records, while logical files provide access paths, or pointers to the physical file • Both physical and logical files may contain a key – Allows records to be retrieved based on the value of the key (key sequence) Programming in RPG IV Third Edition 28
Points to Remember • The key can consist of one or several data fields – In the latter case, the key is called a composite or concatenated key • A physical file may contain only a single record format • Logical files may contain multiple record formats, based on records from two or more physical files Programming in RPG IV Third Edition 29
Points to Remember • A logical file also may contain a single record format that actually combines data fields stored in different physical files – Called a join logical file • Logical files can be used to select or omit records from the physical file Programming in RPG IV Third Edition 30
Points to Remember • A Field Reference File (data dictionary) can be used to record field definitions – Physical files can then reference this file rather than having the field definitions included directly within the physical files themselves Programming in RPG IV Third Edition 31
Points to Remember • Numeric data can be stored in a physical file in one of three common formats – Zoned decimal – Packed decimal – Binary • Define packed fields with odd number of positions Programming in RPG IV Third Edition 32
Points to Remember • Externally described printer files offer several advantages – Report formats can be changed without modifying programs – RLU can be used to design the reports and generate the DDS – Output specs can be eliminated from your programs – Formats can be shared by other programs Programming in RPG IV Third Edition 33
efe9d678e76b80bcda127e19237ffdc4.ppt