Beruflich Dokumente
Kultur Dokumente
Physical Files:
AIM:
Introduction:
The AS/400 database, DB2/400 is part of the AS/400 operating system. The standard method of
creating files is to define the specifications of the file using DDS(Data Description Specification). Of
course DDS is used for other things on the AS/400 like defining display files and print files.
Similar to disk files on non-data based computer system, physical files contain the actual data records.
The attributes of the records may be data based-defined or program-defined. If they are database-
defined, the field definitions are specified outside of a program. For program-defined files, the field
attributes must be included in the program in the traditional RPG II way.
Physical files may be organized as non-keyed or keyed sequence files. The type of organization
determines the access path followed when the file is processed.
A non-keyed file is similar to the standard sequential organization file in which keys are not specified.
Records, which are processed in the order that they were loaded, may be read, written, and updated
using sequential or relative record processing methods. Direct file organization is not supported on the
AS/400. The processing methods unique to that file type, however, may be simulated for arrival of key-
sequenced files.
A keyed sequence file is similar to the traditional indexed sequential file organization in which one or
more fields may be specified as a key. Processing features unique to key sequence file are the
following:
1. Records may be accessed sequentially in key value order or randomly by the value of a key.
2. Records may be accessed in arrival sequence order (ignores key value order).
3. Composite keys may be defined by specifying more than one field within the body of a record.
These fields need not be contiguous.
4. Any field in the body of the record may be specified as a key field after the file is created.
However, a logical file must be used to process the physical file by the new key(s).
5. In addition to standard sequential and random processing, files may be read backward or
accessed by a relative record number.
6. The next record that is lower or higher than the specified key value may be accessed.
S R CHOWDARY
Physical File
After the line naming the record, each line describes a field. The field length and its data type follow
the field name. Once you have entered the DDS source code, you must compile it. You do this by
keying option 14 next to your member name on the PDM screen. Field length should not be greater
than 10 characters.
Data Access:
You now have a database physical file, see Figure 1. This file has built into it the fields and their
attributes. Let's modify this file definition to add key fields. If a physical file has key fields, programs
can randomly access the records or read them sequentially in the order of the key fields.
The records are written to the file in arrival sequence. If you read the data by specifying keyed access,
the records will read as though company number and customer number have sorted them. Also, your
programs can randomly retrieve records.
S R CHOWDARY
Physical File
To create physical file, press F6 (source entry utility) write source file name, Library name, source
member, source type as ‘PF’ and text description.
Bottom
F3=Exit F4=Prompt F5=Refresh F12=Cancel F13=How to use this display
F24=More keys
S R CHOWDARY
Physical File
HIT ENTER
Columns . . . : 1 71 Edit BIZLIB/QDDSSRC
SEU==> STUDENT
FMT PF .....A..........T.Name++++++RLen++TDpB......Functions++++++++++++++++++
IPPF *************** Beginning of data *************************************
NOTE : ‘IPPF’ IS INPUT PROMP FOR PHYSICAL FILE, USED TO DO FIELD ENTRIES IN PHYSICAL FILE.
Functions
HEADING DESCRIPTION
Name type Blank : Leave the field blank to indicate a Field
Name.
S R CHOWDARY
Physical File
Now in second step you have to define fields having attributes field length, data type and decimal
positions if field is numeric. Insert the define fields using same way.
S R CHOWDARY
Physical File
While entering fields the values, which we provide for LENGTH, and DECIMAL POSITION are numeric
must be RIGTHT align. To make it RIGHT ALIGN use right ‘Enter Key’ from numeric pad.
PRESS F3
Exit
Hit Enter
S R CHOWDARY
Physical File
File . . . . . . QDDSSRC
Library . . . . BIZLIB Position to . . . . .
Bottom
Parameters or command
===>
F3=Exit F4=Prompt F5=Refresh F6=Create
F9=Retrieve F10=Command entry F23=More options F24=More keys
To compile PF use command CRTPF or opt 14 against PF that create object of PF (as shown below).
File . . . . . . QDDSSRC
Library . . . . BIZLIB Position to . . . . .
After writing 14 over Opt and press F4 that is same as CRTPF on command line with F4.
S R CHOWDARY
Physical File
More...
F3=Exit F4=Prompt F5=Refresh F12=Cancel F13=How to use this display
F24=More keys
Press enter which creates physical files object. Now to UPDATE pf, write ‘UPDDTA <FILE NAME> ‘
command on command line.
File . . . . . . QDDSSRC
Library . . . . BIZLIB Position to . . . . .
Bottom
Parameters or command
===> UPDDTA
F3=Exit F4=Prompt F5=Refresh F6=Create
F9=Retrieve F10=Command entry F23=More options F24=More keys
S R CHOWDARY
Physical File
Bottom
F3=Exit F4=Prompt F5=Refresh F12=Cancel F13=How to use this display
F24=More keys
ROLL:
SNAME:
CCD:
CORS:
ADD:
S R CHOWDARY
Physical File
F3=Exit F12=Cancel
Press enter. After insertion of data do not compile the file which delete your data. Use ‘RUNQRY *N
<FILENAME>’ to run or to see the content of physical file.
File . . . . . . QDDSSRC
Library . . . . BIZLIB Position to . . . . .
More...
Parameters or command
===> RUNQRY *N STUDENT
Press enter
S R CHOWDARY
Physical File
Display Report
Report width . . . . . : 60
Position to line . . . . . Shift to column . . . . . .
Line ....+....1....+....2....+....3....+....4....+....5....+....6
ROLL NUMBER STUDENT NAME COURSE CODE COURSE NAME ADDRESS
000001 101 RAJU 200 VB PUNE
000002 102 SANJU 201 AS MUM
****** ******** End of report ********
Bottom
F3=Exit F12=Cancel F19=Left F20=Right F21=Split
KEYWORDS:
A) File level keywords:
Following are the File Level Keywords:
UNIQUE
FIFO (First In First Out)
LIFO (Last In First Out)
FCFO (First Change First Out)
1) UNIQUE: The "UNIQUE" record at the beginning of the source is used if you want the AS/400
to insist on having no records with duplicate keys. This is optional. At the end of the source
code, there are two lines with "K" in position 17. These lines define the key fields.
2) FIFO LIFO FCFO: These keywords are used with the duplicate entries to specify the order.
S R CHOWDARY
Physical File
The database-file-name parameter is required. It is the name of the physical or logical file from which
the previously defined record format is taken.
Create new physical file ‘student1’ and define only record format name with FORMAT keyword having
filename which is to be reffered.
COMPILE THIS FILE AND USE RUNQUERY OPTION TO RUN THE FILE.
The name of this record format (RSTUD) must be the same as the name of the record format in
STUDENT. Like FORMAT ‘TEXT’ is also a record level keyword use as follows:
S R CHOWDARY
Physical File
The name of this record format (RSTUD) must be the same as the name of the record format in
STUDENT.
Use this field-level keyword to specify an alternative name for a field. When the program is compiled,
the alternative name is brought into the program instead of the DDS field name.
The alternative name must be different from all other alternative names and from all DDS field names
in the record format. If a duplicate is found, an error message appears on the field name or alternative
name. When you refer to a field that has the ALIAS keyword, the ALIAS keyword is copied in unless the
ALIAS keyword is explicitly specified on the referencing field.
Example:
S R CHOWDARY
Physical File
A maximum of three lines of 20 characters each is allowed. Each line of the column heading must be
enclosed in apostrophes. Use double apostrophes (’ ’) to specify apostrophes within column headings.
Use one or more blanks to separate the first column heading line from the second and the second from
the third.
Example:
The following example shows how to specify the COLHDG keyword for a physical file.
|...+....1....+....2....+....3....+....4....+....5....+....6....+....7....+....8
00150A ROLL 50 COLHDG(’ROLL’ ’NUMBER’)
00160A SNAME 20 COLHDG(’Student’s Name’)
TEXT : This is record level as well as field level keyword which describes your field.
Example:
The following example shows how to specify the COLHDG keyword for a physical file.
|...+....1....+....2....+....3....+....4....+....5....+....6....+....7....+....8
00150A ROLL 50 TEXT(’ROLL NUMBER’)
00160A SNAME 20 TEXT(‘Student’s Name’)
CHECK
Use this field-level keyword to specify validity checking in display files.
The rules for specifying this keyword in a physical or logical file are similar to those for a display file.
However, only the following codes are allowed in physical or logical files:
Code Meaning
AB Allow blank
ME Mandatory enter
MF Mandatory fill
M10 IBM* Modulus 10 self-check algorithm
M10F IBM® Modulus 10 self-check algorithm
M11 IBM Modulus 11 self-check algorithm
M11F IBM Modulus 11 self-check algorithm
VN Validate name
VNE Validate name extended
|...+....1....+....2....+....3....+....4....+....5....+....6....+....7....+....8
00150A ROLL 50 CHECK(AB)
00160A SNAME 20 CHECK(MF)
Above example shows that roll number may be blank and student name is mandatory.
S R CHOWDARY
Physical File
Example:
The following example shows how to specify the DESCEND keyword for a logical file.
|...+....1....+....2....+....3....+....4....+....5....+....6....+....7....+....8
00010A KITEM
00020A KBALDUE DESCEND
Specify the value parameter at either the field level or the select/omit field level. Specify the field name
parameter only at the select/omit field level.
When the related field is defined as character , the low and high values must both be enclosed in single
quotes. The quotes are omitted for numeric fields. Figure details two examples of the RANGE
keyword.
S R CHOWDARY
Physical File
One hundred values may be specified, each separated by at least one blank. A VALUES keyword
specified with character fields must have each value in the list enclosed in single quotes. Numeric
values are specified without quotes Identical to any relational comparison function, the value list must
be the same type as the related field. Figure shows two coding examples of the VALUES keyword.
CPYF Copy file Copies the data stored in a physical file to an output
device or another physical file. Either all of the
records or only selected records may be copied. A
variety of selection criteria may be specified such as
a key or a relative record number range. When
output is to a printer, either character or
hexadecimal format may be specified. For
readability, however, hexadecimal format is
necessary if packed numeric values are stored in one
or more fields of the record format.
DLTF Deletes the physical file’s object and any data stored
Delete File in the file. A file cannot be deleted if a logical file has
been created over it or if the file is in use.
DSPPFM Display Physical File Member Displays the field values in the records stored in a
physical file. Records are displayed in arrival
sequence even if the file was created as keyed. A
character or hexadecimal display of the record values
may be specified. Other than printing the current
display with the values may be specified. Other than
printing the current display with the Print key, printer
output is not supported.
RMVM Remove Member Removes the specified member from the physical file
and deletes all of the data stores in the member.
DSPFD Display Physical file Description Displays the file description like total no. of files,
fields, records etc.
ADDPFM Add Physical file member Adds the member in created physical file.
Entering the command on the command line of an AS/400 display and pressing F4 may execute any of
these CL commands. One or more prompt screens will display enabling the programmers to enter
command specific data.
Step1:
Write command CHGPF on command line and press F4 to change the option of physical file-
S R CHOWDARY
Physical File
Bottom
F3=Exit F4=Prompt F5=Refresh F10=Additional parameters F12=Cancel
F13=How to use this display F24=More keys
Press enter and change option ‘Maximum members’ to 3 (change according to your requirement)
Hit enter which shows you message on message area that File STUDENT in library PB01U01O
changed.
Step2 : Now in second step add 3 members with your created Physical file. You can add ‘<=3’
members but not Greater than 3 as you define max members 3.
S R CHOWDARY
Physical File
Bottom
F3=Exit F4=Prompt F5=Refresh F10=Additional parameters F12=Cancel
F13=How to use this display F24=More keys
Hit enter and see message on command line that MEMBER PF1 is added in Physical file STUDENT.
Add more member using above procedure. And you can see the content of member using RUNQRY
command and press F4 on command line
Bottom
F3=Exit F4=Prompt F5=Refresh F12=Cancel F13=How to use this display
F24=More keys
S R CHOWDARY