Presentation is loading. Please wait.

Presentation is loading. Please wait.

Presentation © Copyright 2002, Bryan Meyers Externally Described Files Chapter 6.

Similar presentations


Presentation on theme: "Presentation © Copyright 2002, Bryan Meyers Externally Described Files Chapter 6."— Presentation transcript:

1 Presentation © Copyright 2002, Bryan Meyers Externally Described Files Chapter 6

2 Programming in RPG IV Third Edition 2 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

3 Programming in RPG IV Third Edition 3 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

4 Programming in RPG IV Third Edition 4 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

5 Programming in RPG IV Third Edition 5 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

6 Programming in RPG IV Third Edition 6 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

7 Programming in RPG IV Third Edition 7 Data Types and Data Storage A = Character S = Zoned decimal B = Binary P = Packed decimal

8 Programming in RPG IV Third Edition 8 Packed Decimal Only the digit (low order) bits of a number are stored Sign occupies right-most four bit positions iSeries 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

9 Programming in RPG IV Third Edition 9 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

10 Programming in RPG IV Third Edition 10 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 ________ ________ ________

11 Programming in RPG IV Third Edition 11 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 ________ ________

12 Programming in RPG IV Third Edition 12 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

13 Programming in RPG IV Third Edition 13 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

14 Programming in RPG IV Third Edition 14 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

15 Programming in RPG IV Third Edition 15 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 A S DEPT VALUES(‘MIS’ ‘ACT’)

16 Programming in RPG IV Third Edition 16 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

17 Programming in RPG IV Third Edition 17 Multiple Record Formats *..1....+....2....+....3....+....4....+....5....+....6....+....7....+....8 A* T.Name++++++RLen++TDpB Functions A R STUDREC PFILE(STUDMAST) A K STUD_NO * A R CRSEREC PFILE(STUDCRSE) A K STUD_NO A K SEMESTER

18 Programming in RPG IV Third Edition 18 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

19 Programming in RPG IV Third Edition 19 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

20 Programming in RPG IV Third Edition 20 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+++++++++++++++++++++++++++++ FEmpMaster IF E K DISK

21 Programming in RPG IV Third Edition 21 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

22 Programming in RPG IV Third Edition 22 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 agreed- upon mnemonic prefix to denote the system

23 Programming in RPG IV Third Edition 23 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

24 Programming in RPG IV Third Edition 24 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

25 Programming in RPG IV Third Edition 25 Externally Described PRTF *..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)

26 Programming in RPG IV Third Edition 26 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 (*IN10, *IN11, *IN99 etc.) Named indicators also allowed *.. 1...+... 2...+... 3...+... 4...+... 5...+... 6...+... 7...+... 8 FFilename++IPEASFRlen+LKlen+AIDevice+.Keywords+++++++++++++++++++++++++++++ FSalesRpt O E PRINTER OflInd(EndOfPage)

27 Programming in RPG IV Third Edition 27 Externally Described Printer Files Calculation Specifications –Use WRITE instead of EXCEPT Output Specifications not needed

28 Programming in RPG IV Third Edition 28 Points to Remember The iSeries 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)

29 Programming in RPG IV Third Edition 29 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

30 Programming in RPG IV Third Edition 30 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

31 Programming in RPG IV Third Edition 31 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

32 Programming in RPG IV Third Edition 32 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

33 Programming in RPG IV Third Edition 33 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


Download ppt "Presentation © Copyright 2002, Bryan Meyers Externally Described Files Chapter 6."

Similar presentations


Ads by Google