RPG IV -Chapter 6

Download Report

Transcript RPG IV -Chapter 6

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 (firstin, 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 loworder 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
0
1
2
3
4
5
6
7
8
9
EBCDIC
11110000
11110001
11110010
11110011
11110100
11110101
11110110
11110111
11111000
11111001
Zoned-decimal Representation
Digit
+1
-1
10
-10
22
99
100
-999
EBCDIC
11110001
11010001
11110001
11110001
11110010
11111001
11110001
________
11110000
11010000
11110010
11111001
11110000
________
# of Bytes
1
1
2
2
2
2
11110000 3
________
Packed-decimal
Representation
Digit
+1
-1
10
-10
22
99
100
-999
EBCDIC
00011111
00011101
00000001
00000001
00000010
00001001
00010000
________
00001111
00001101
00101111
10011111
00001111
________
# of Bytes
1
1
2
2
2
2
2
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
A
A
A
A
A
A
A
A
R EMPREC
J
ORDER_NO
CUST_NO
PART_NO
DESCRPT
SELL_PRICE
QTY_ORD
JFILE(ORDERS INVENT)
JOIN(ORDERS INVENT)
JFLD(PART_NUM PART_NO)
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 singlerecord format that actually combines
data fields stored in different physical
files; this kind of file is called a joinlogical 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