You are on page 1of 12

WORK WITH LOGICAL-FILE

Logical Files:

 Create a Logical file


 Understand the part of Logical files.
 Commands related to files.

Logical File:
A logical file is provide access the data stored in one or more physical files. The features unique to
logical files include the following:
1. Logical files do not contain data.
2. Access one or more physical files in an arrival sequence or in any single or multiple field (key)
value order.
3. A physical file may be processed by any number of logical files.
4. Two or more logical files may share the same access path.
5. Omit and select criteria may be specified in a logical file to process only the required physical
file data.
6. A logical file may include multiple record formats. Each format however must relate to one or
more physical files and include at least one key field.
7. One logical file with multiple record formats may process only the required physical file data.
8. A logical file with multiple record formats may be used to process the data from more than one
physical file. The file record formats accessed may be of different lengths.
9 During processing a physical file’s field attributes may be changed by a logical file. However,
the data stored in the physical file not be modified.

Logical files may be specified as either nonjoin or join. A nonjoin logical file processes each record
individually from one or more physical files. Join logical files however create a single record from the
selected fields from two or more physical files.

The type of logical file (nonjoin or join) specified is determined in the related DDS coding. In the
following text, the processing logic and DDS syntax for nonjoin logical files are introduced first,
followed by the coding requirements associated with join logical files.

NONJOIN LOGICAL FILES (ONE-RECORD FORMAT)


All logical files are formatted and defined by DDS coding. The DDS coding for nonjoin logical files is
specified in the following order.
1. File level entries (optional)
2. Record level entries
3. Field level entries (optional)
4. Key field level entries (optional)
5. Select/omit level entries (optional).

Non-join logical files may specify more than one record format. If two or more physical files with
different record formats are to be used by a logical file, separate PFILE keywords must be specified.
When the record formats are the same, only one PFILE keywords is required. A maximum of 32
physical files may be referenced in one PFILE keyword.

When two or more physical files with a logical file accesses different record formats. *NONE may be
specified as a key field substance for any of the following conditions:
1. The related keyfields from the physical files do not have the same attributes.
2. The key fields from the physical files have the same attributes, but they are not to be merged
and sequenced together.

Specify the entries in the following order to define a simple or multiple format logical file:
1. File-level entries (optional)
2. Record-level entries

S R CHOWDARY
WORK WITH LOGICAL-FILE

3. Field-level entries (optional)


4. Key field level entries (optional)
5. Select and omit-field level entries (optional)

How to create simple logical file? Create student pf file as discussed above. Like physical file create
logical file as shown below. Press ‘F6’ &

IN NEXT STEP YOU HAVE TO WRITE SOURCE TYPE AS ‘LF’ & SOURCE MEMBER –

Start Source Entry Utility (STRSEU)

Type choices, press Enter.

Source file . . . . . . . . . . > qddssrc Name, *PRV


Library . . . . . . . .> BIZLIB Name, *LIBL, *CURLIB, *PRV
Source member . . . . . . . . . LSTUDENT Name, *PRV, *SELECT
Source type . . . . . . . . . . LF Name, *SAME, BAS, BASP...
Text ‘description’ . . . . . . . ‘LOGICAL FILE FOR STUDENT’

Bottom
F3=Exit F4=Prompt F5=Refresh F12=Cancel F13=How to use this display
F24=More keys

PRESS ENTER SO THAT YOU GET THE FOLLOWING SCREEN

Columns . . . : 1 71 Edit SHEET/QSRC


SEU==> LSTUDENT
FMT LF .....A..........T.Name++++++.Len++TDpB......Functions++++++++++++++++++
*************** Beginning of data *************************************
'''''''
'''''''
'''''''
'''''''
'''''''
'''''''
'''''''
'''''''
'''''''
'''''''
'''''''
'''''''
'''''''
'''''''
'''''''
****************** End of data ****************************************

F3=Exit F4=Prompt F5=Refresh F9=Retrieve F10=Cursor F11=Toggle


F16=Repeat find F17=Repeat change F24=More keys
Member LSTUDENT added tofile BIZLIB/MYDDS. +

S R CHOWDARY
WORK WITH LOGICAL-FILE

AFTER TYPING ‘IPLF’ AS SHOWN ABOVE USER GETS THE FOLLOWING PROMPT

Columns . . . : 1 71 Edit BIZLIB/QDDSSRC


SEU==> LSTUDENT
FMT LF .....A..........T.Name++++++.Len++TDpB......Functions++++++++++++++++++
*************** Beginning of data *************************************
'''''''

******************End of data ****************************************

Prompt type . . . LF Sequence number . . . “”””””

Name Data Decimal


Type Name Length Type Positions Use
Functions

F3=Exit F4=Prompt F5=Refresh F11=Previous record F12=Cancel F23=Select prompt


F24=More keys

Enter reference file using ‘PFILE(FILE NAME)’ function key as well as record format name
as shown below :

Columns . . . : 1 71 Edit BIZLIB/QDDSSRC


SEU==> LSTUDENT
FMT LF .....A..........T.Name++++++.Len++TDpB......Functions++++++++++++++++++
*************** Beginning of data *************************************
0001.00 A R SR PFILE(STUDENT)
****************** End of data ****************************************

Prompt type . . . LF Sequence number . . . 0001.00


Name Data Decimal
Type Name Length Type Positions Use
R SR
Functions
PFILE(STUDENT) File name using PFILE()
F3=Exit F4=Prompt F5=Refresh F11=Previous record
F12=Cancel F23=Select prompt F24=More keys

Enter key field of referred physical file :

S R CHOWDARY
WORK WITH LOGICAL-FILE

Columns . . . : 1 71 Edit BIZLIB/QDDSSRC


SEU==> LSTUDENT
FMT LF .....A..........T.Name++++++.Len++TDpB......Functions++++++++++++++++++
*************** Beginning of data *************************************
0001.00 A R SR PFILE(STUDENT)
0002.00 K ROLL
****************** End of data ****************************************

Prompt type . . . LF Sequence number . . . 0002.00


Name Type Name Length Type Decimal Positions Use
K ROLL
Key Key field name
Functions
Field
Name F3=Exit F4=Prompt F5=Refresh F11=Previous record
F12=Cancel F23=Select prompt F24=More keys

Press F3 and use option 14 to compile the above file and create object in BIZLIB and
Runqry command for above logical file gives following output:

Display Report
Report width . . . . . : 39
Position to line . . . . . Shift to column . . . . . .
Line ....+....1....+....2....+....3....+....
ROLL SNAME CCD CORS ADD CITY
000001 101 sneha vv VB pune pune
000002 102 ramesh hh C mumbai mumbai
000003 103 titu iii AS mumbai pune
000004 104 rahul AS400 VB pune pune
****** ******** End of report ********

Bottom
F3=Exit F12=Cancel F19=Left F20=Right F21=Split

Reference file name and key field gives all field from related physical file. But in logical file user is able
to select particular field as shown below. Just insert the required field name as per above define
sequence:

S R CHOWDARY
WORK WITH LOGICAL-FILE

Columns . . . : 1 71 Edit BIZLIB/QDDSSRC


SEU==> LSTUDENT
FMT LF .....A..........T.Name++++++.Len++TDpB......Functions++++++++++++++++++
*************** Beginning of data *************************************
0001.00 A R RSTUDENT PFILE(STUDENT)
0002.00 A ROLL
0003.00 A SNAME
0004.00 A CORS
0005.00 A K ROLL
****************** End of data *******************************

F3=Exit F4=Prompt F5=Refresh F9=Retrieve F10=Cursor F11=Toggle


F16=Repeat find F17=Repeat change F24=More keys
© COPYRIGHT IBM CORP. 1981, 2002.
Above logical file shows following output:

Use RUNQRY command on command prompt to see the output.


Display Report
Report width . . . . . : 19
Position to line . . . . . Shift to column . . . . . .
Line ....+....1....+....
ROLL SNAME CORS
000001 101 sneha vv
000002 102 ramesh hh
000003 103 titu iii
000004 104 rahul AS400
****** ******** End of report ********

Bottom
F3=Exit F12=Cancel F19=Left F20=Right F21=Split

Also you are able to define multiformat logical file as shown below:

S R CHOWDARY
WORK WITH LOGICAL-FILE

Columns . . . : 1 71 Edit BIZLIB/QDDSSRC


SEU==> LSTUDENT
FMT LF .....A..........T.Name++++++.Len++TDpB......Functions++++++++++++++++++
*************** Beginning of data *************************************
0001.00 A R RS PFILE(STUDENT)
0002.00 A ROLL
0003.00 A SNAME
0004.00 A CORS
0005.00 A K ROLL
0005.01 *
0006.00 A R RCORS PFILE(CORS)
0007.00 A K CCD
****************** End of data ****************************************

F3=Exit F4=Prompt F5=Refresh F9=Retrieve F10=Cursor F11=Toggle


F16=Repeat find F17=Repeat change F24=More keys

HOW TO USE COLHDG & ‘TEXT’ K/W:


Columns . . . : 1 71 Edit BIZLIB/QDDSSRC
SEU==> LSTUDENT
FMT LF .....A..........T.Name++++++.Len++TDpB......Functions++++++++++++++++++
*************** Beginning of data *************************************
0001.00 A R RS PFILE(STUDENT)
0002.00 A ROLL COLHDG(‘ROLL NO’)
0003.00 A NAME TEXT(‘STUDENT DETAIL’)
0004.00 A CORS
0005.00 A K ROLL
****************** End of data ****************************************

F3=Exit F4=Prompt F5=Refresh F9=Retrieve F10=Cursor F11=Toggle


F16=Repeat find F17=Repeat change F24=More keys
© COPYRIGHT IBM CORP. 1981, 2002.

S R CHOWDARY
WORK WITH LOGICAL-FILE

OUTPUT OF COLHDG & TEXT KEYWORD :

Display Report
Report width . . . . . : 21
Position to line . . . . . Shift to column . . . . . .
Line ....+....1....+....2.
ROLL NO SNAME CORS
000001 101 sneha vv
000002 102 ramesh hh
000003 103 titu iii
000004 104 rahul AS400
****** ******** End of report ********

Bottom
F3=Exit F12=Cancel F19=Left F20=Right F21=Split

The following keywords are select and omit level keywords:


1. COMP 2. RANGE 3. VALUE

HOU TO USE ABOVE KEYWORD WITH SELECT & OMIT:


Columns . . . : 1 71 Edit BIZLIB/QDDSSRC
SEU==> LSTUDENT
FMT LF .....A..........T.Name++++++.Len++TDpB......Functions++++++++++++++++++
***************Beginning of data *************************************
0001.00 A R RS PFILE(STUDENT)
0002.00 A ROLL COLHDG(‘ROLL NO’)
0003.00 A NAME TEXT(‘STUDENT DETAIL’)
0004.00 A CORS
0004.01 A K ROLL
0005.00 A S ROLL COMP(GT 102)
****************** End of data ****************************************

Prompt type . . . LF Sequence number . . . 0004.01

FOR Name Data Decimal


SELECT Type Name Length Type Positions Use
S ROLL
K/W
Functions
COMP(GT 102) FOR THE SELECTED FIELD

F3=Exit F4=Prompt F5=Refresh F11=Previous record


F12=Cancel F23=Select prompt F24=More keys

S R CHOWDARY
WORK WITH LOGICAL-FILE

Above field shows the following output:

Display Report
Report width . . . . . : 21
Position to line . . . . . Shift to column . . . . . .
Line ....+....1....+....2.
ROLL NO SNAME CORS
000001 103 titu iii
000002 104 rahul AS400
****** ******** End of report ********

Bottom
F3=Exit F12=Cancel F19=Left F20=Right F21=Split

Like that we are able to use range and value keyword with logical file. Now use of
omits keyword with logical file.

Columns . . . : 1 71 Edit BIZLIB/QDDSSRC


SEU==> LSTUDENT
FMT LF.....A..........T.Name++++++.Len++TDpB......Functions++++++++++++++++++
***************Beginning of data *************************************
0001.00 A R RS PFILE(STUDENT)
0002.00 A ROLL COLHDG(‘ROLL NO’)
0003.00 A NAME TEXT(‘STUDENT DETAIL’)
0004.00 A CORS
0004.01 A K ROLL
0005.00 A O ROLL COMP(GT 102)
****************** End of data *************************************

F3=Exit F4=Prompt F5=Refresh F9=Retrieve F10=Cursor F11=Toggle


F16=Repeat find F17=Repeat change F24=More keys
© COPYRIGHT IBM CORP. 1981, 2002.
Note: Omit keyword is always used with DYNSLT to omit the value. This is logical file level keyword.

S R CHOWDARY
WORK WITH LOGICAL-FILE

Output of above ‘omit’ keyword is as shown below see it using RUNQRY command on
command line.

Display Report
Report width . . . . . : 21
Position to line . . . . . Shift to column . . . . . .
Line ....+....1....+....2.
ROLL NO SNAME CORS
000001 100 ABC AS400
000002 101 sneha vv
****** ******** End of report ********

Bottom
F3=Exit F12=Cancel F19=Left F20=Right F21=Split

You can use this k/w on one field & one file as shown below

Columns . . . : 1 71 Edit BIZLIB/QDDSSRC


SEU==> LSTUDENT
FMT LF .....A..........T.Name++++++.Len++TDpB......Functions++++++++++++++++++
************* Beginning of data *************************************
0001.00 A R RS PFILE(STUDENT)
0002.00 A ROLL COLHDG(‘ROLL NO’)
0003.00 A SNAME TEXT(‘STUDENT DETAIL’)
0004.00 A CORS
0005.00 A K ROLL
0006.00 A O ROLL COMP(EQ 102)
0007.00 A S ROLL COMP(GT 100)
**************** End of data ****************************************

F3=Exit F4=Prompt F5=Refresh F9=Retrieve F10=Cursor F11=Toggle


F16=Repeat find F17=Repeat change F24=More keys
© COPYRIGHT IBM CORP. 1981, 2002.
OUTPUT OF THIS COMPARISON IS

S R CHOWDARY
WORK WITH LOGICAL-FILE

Display Report
Report width . . . . . : 21
Position to line . . . . . Shift to column . . . . . .
Line ....+....1....+....2.
ROLL NO SNAME CORS
000001 101 SNEHA VV
000002 103 titu iii
****** ******** End of report ********

Bottom F3=Exit F12=Cancel F19=Left F20=Right F21=Split

Use of value keyword :

columns . . . : 1 71 Edit BIZLIB/QDDSSRC


SEU==> LSTUDENT FMT
LF .....A..........T.Name++++++.Len++TDpB......Functions++++++++++++++++++
***************Beginning of data *************************************
0001.00 A R RS PFILE(STUDENT)
0002.00 A ROLL COLHDG(‘ROLL NO’)
0003.00 A NAME TEXT(‘STUDENT DETAIL’)
0004.00 A CORS
0004.01 A K ROLL
0006.00 A O ROLL VALUES(102)
0007.00 A S ROLL COMP(GT 100)
****************** End of data ****************************************

F3=Exit F4=Prompt F5=Refresh F9=Retrieve F10=Cursor F11=Toggle


F16=Repeat find F17=Repeat change F24=More keys

Output of this keyword is where roll number having value 102 gets omitted.

S R CHOWDARY
WORK WITH LOGICAL-FILE

Display Report
Report width . . . . . : 21
Position to line . . . . . Shift to column . . . . . .
Line ....+....1....+....2.
ROLL NO SNAME CORS
000001 101 sneha vv
000002 103 titu iii
****** ******** End of report ********

Bottom
F3=Exit F12=Cancel F19=Left F20=Right F21=Split

S R CHOWDARY
WORK WITH LOGICAL-FILE

Questions related to above session:

3.1: Flat Files


Create flat file using the command CRTPF and specifying the record length. Add records to the file by
using UPDDTA command. View the contents of the file by using the RUNQRY command. Try if you can
see the DDS for the same.

3.2: Physical & Logical Files

Write the DDS source to create a Physical file.


Create the following physical files and populate them with data:

CUSTM
No. Field Name Length Data Type Key Description
1 CPHONE 10,0 P K Customer Phone No
2 CLNAME 10 A Customer Last Name
3 CFNAME 10 A Customer First
Name
4 CADDR 20 A Customer Address
5 CBILL 6,2 P Customer Billing
Amount
6 COWED 6,2 S Amount Owned
7 CPYDT 6,0 S Payment Date
8 STATUS 1 A Customer Status

Hint : Use Text keyword.

CUSTM
CUSTM Field Name Length Data Key Description
No. Type
1 CPHONE 10,0 P K Customer Phone No
2 CAMPD 6,2 P Amount Paid
3 CDTRC 6,0 P Date received

1. Create a logical file CUSTML1 over CUSTM keyed on Payment date and select those records
where address is Pune (Using COMP).
2. Create a logical file CUSTML2 over CUSTM and select the records with bill amount ranging from
1000.00 to 9999.99 (Using RANGE).
3. Create a logical file CUSTM3 over CUSTM and the records with status equal to (‘A’ or ‘I’)
active/inactive (using VALUES).
4. Create a logical file CUSTML4 over CUSTM and rename the field COWED to AMTOD and update
the data using the file.
5. Check all the logical files associated with CUSTM using command DSPDBR.
6. Create a Join logical file over CUSTM and CTRANS joined on CPHONE and arrange the duplicate
records according to Amount Paid.
7. Create a field reference file and use its reference to create a physical file CUSTM1.identical to
CUSTM
8. Add a physical file member to file CUSTM using command ADDPFM. Add data to it.

S R CHOWDARY

You might also like