330 likes | 662 Views
RPG IV. Externally Described Files - Chapter 6. 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
E N D
RPG IV Externally Described Files - Chapter 6
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
Physical File • Store 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
Logical File • Logical files do not actually contain data • They store access paths or pointers to records in physical files • RPG programs use logical files just as though the logical files themselves contained data
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) is used to define files • File, record and field level keywords are used to define a file
Physical File Example *..1....+....2....+....3....+....4....+....5....+....6....+....7....+....8 A* T.Name++++++RLen++TDpB Functions A UNIQUE A R EMPREC A EMPNO 9S 0 A LNAME 15A A FNAME 10A A DEPT 3A A SALARY 6P 0 A STREET 15A A CITY 15A A STATE 2A A ZIP 5S 0 A K EMPNO
Data Types and Data Storage • A: Character • S: Zoned decimal • B: Binary • P: Packed decimal
Packed Decimal • In packed format, only the digit, or low-order bits, of a number are stored • The sign of the number occupies the right most four-bit positions • AS/400 converts all numeric data to packed decimal before the values are used in calculaitons • Packed fields take (n+1)/2 bytes of storage, where n=number of digits
Extended Binary Coded Decimal Interchange (EBCDIC) Digit EBCDIC 0 11110000 1 11110001 2 11110010 3 11110011 4 11110100 5 11110101 6 11110110 7 11110111 8 11111000 9 11111001
Zoned-decimal Representation Digit EBCDIC # of Bytes +1 11110001 1 -1 11010001 1 10 11110001 11110000 2 -10 11110001 11010000 2 22 11110010 11110010 2 99 11111001 11111001 2 100 11110001 11110000 11110000 3 -999 ________ ________ ________
Packed-decimal Representation Digit EBCDIC # of Bytes +1 00011111 1 -1 00011101 1 10 00000001 00001111 2 -10 00000001 00001101 2 22 00000010 00101111 2 99 00001001 10011111 2 100 00010000 00001111 2 -999 ________ ________
Simple Logical Files • Contain the physical file record name • Contains the record level keyword PFILE and the name of the physical file • Has one or more field level keywords • This kind of logical file is widely used to change the retrieval order of records in a file • This is the same as physically sorting a physical file
Simple Logical File Example *..1....+....2....+....3....+....4....+....5....+....6....+....7....+....8 A* T.Name++++++RLen++TDpB Functions A R EMPREC PFILE(EMPMST) A K LNAME
Simple Logical File Example *..1....+....2....+....3....+....4....+....5....+....6....+....7....+....8 A* T.Name++++++RLen++TDpB Functions A R EMPREC1 PFILE(EMPMST) A EMPNO A LNAME A FNAME A DEPT A SALARY A K DEPT A K EMPNO
Multiple-Record Formats • Defined based on two or more physical files • Each format is based on a different physical file • The logical file gives the appearance that the two physical files have been merged together
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 files are used in this join • JFLD keyword indicates which fields’ values are to be matched across the physical files named in the JOIN parameter
Join-Logical File Example *..1....+....2....+....3....+....4....+....5....+....6....+....7....+....8 A* T.Name++++++RLen++TDpB Functions A R EMPREC JFILE(ORDERS INVENT) A J JOIN(ORDERS INVENT) A JFLD(PART_NUM PART_NO) A ORDER_NO A CUST_NO A PART_NO A DESCRPT A SELL_PRICE A QTY_ORD
Programming with 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 • You do not need to code Input specs for the externally defined files
Programming with Externally Defined Files (cont) • At a program level, there is no distinction made between physical and logical files • If you make changes in a physical file or logical file after you have compiled a program using that file, you must recompile the program
Additional Database File 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
Additional Database File Concepts (cont) • 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 ad consistency • File names should consist of an agreed-upon mnemonic prefix to denote the system
Additional Database File Concepts (cont) • File names should also contain a short alphabetic mnemonic code - often related to the key of the file to uniquely identify the file • A 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
Externally Described Printer Files • Printer files can be created the same as physical files • Each record format begins with an ‘R’ in position 17 • You specify the field or constant’s beginning position (where it starts on the line) • DATE is UDATE, PAGNBR is PAGE
Externally Described Printer Files • Use keywords SPACEA, SPACEB, SKIPA, and SKIPB the same as RPG • On the F spec include the name of the printer file not QPRINT and code an ‘E’ in position 19 • Omit any entry for record length • The overflow indicator cannot be OA - OF or OV, you can use almost anything else (10, 11, 99 etc.)
Externally Described Printer Files • Use keyword OFLIND with overflow indicator • You don’t need Output Specs • Use a WRITE instead of EXCEPT
Externally Described Printer File Example *..1....+....2....+....3....+....4....+....5....+....6....+....7....+....8 A* T.Name++++++RLen++TDpBLinPosFunctions A R HEADINGS SKIPB(1) A 10DATE EDTCDE(Y) A 22’SALES REPORT’ A 37’PAGE’ A 42PAGNBR 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 32EDTCDE(1) A R BREAKLINE SPACEB(1) SPACEA(2) A 20’TOTAL’ A SLSPTOTAL 6 2 31EDTCDE(1) A 40’*’ A R TOTALLINE A 16’GRAND TOTAL’ A GRANDTOTAL 8 2 30EDTCDE(1)
Points to Remember • The AS/400 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 that allows records to be retrieved based on the value of the key (key sequence)
Points to Remember (cont) • 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
Points to Remember (cont) • A logical file also may contain a single-record format that actually combines data fields stored in different physical files; this kind of file is called a join-logical file • Logical files can be used to select or omit records from the physical file
Points to Remember (cont) • 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
Points to Remember (cont) • Numeric data can be stored in a physical file in one of three formats: • Zoned decimal • Packed decimal • Binary • Define packed fields with odd number of positions
Points to Remember (cont) • 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