SUBFILES
Objectives
To understand the concepts of Subfile programming
Prerequisites
Basic knowledge of RPG programming concepts.
Course Outline
The concepts of subfiles Subfile Record Formats Subfile Control-Record Formats Types of Subfiles Subfile design using SDA. Subfile Processing Subfile validation and database updates. Addition and Modification Program Update and Delete Program Coding a message subfile.
Sub file Display
Introduction to Sub files
A group of records that have the same record format and are read from and written to a display station in one operation. A subfile differs from other physical files in the following ways:
It is temporary, existing only until the RPG program that creates and owns it ends. Within a subfile, each fields description also identifies its screen location and its display attributes.
6
Introduction to Subfiles (Contd.)
Subfile is displayed a page at a time. Number of records in a subfile must also be specified in the DDS.
One display file can contain more than one subfile, and up to 12 subfiles can be active concurrently.
Create Subfile
Use of Subfiles
Subfiles can be used:
To view the output. To request for more information about one of the
items on the display.
To change one or more of the records.
Use of Subfiles(Contd..)
To input data with no validity checking To input data with validity checking Combination of display with modification and the
input of new records.
10
Record Formats of a Subfile
Records in a subfile are specified in the DDS for the file. A Subfile has 2 record formats: Subfile Control Record Format Subfile Record Format The subfile record format must precede the subfile control record format. Footer record is optional to create a subfile display. If used, definition of the function keys is given here.
11
Subfile Control Record Format
Defines the attributes of the subfile, the search input field, constants, and function keys. Defines the constants to be used as column headings for the subfile record format.
12
Data Description Specifications for a subfile Control-record format
13
Subfile Record Format
The subfile record format declares
Fields name Fields definition.
Field definitions can either be specified explicitly or by reference to a field definition in a physical file Handles the physical read, write, or control operations of a subfile
14
Data Description Specifications for a subfile record format
15
Subfile Keywords
Keywords used:
SFL SFLCTL SFLCLR
- identifies the record format as a subfile - name of the associated subfile - indicates when the subfile should be cleared
SFLDSPCTL- indicates when to display the subfile
control record
16
Subfile Keywords
SFLDSP SFLPAG
- indicates when to display the subfile - indicates the total number of records in a page
SFLSIZ
SFLEND
- indicates the number of records the subfile can contain. Maximum 9999
- Displays a plus sign, by default, to indicate when there are more records in subfile. Specify *MORE to display text.
17
Subfile Keywords (Contd.)
SFLFOLD
- Specifies the CA or CF key used to fold Multiformat subfile to single line format. - Initially displays only the first line of the subfile records, and reacts to a function key by switching into a multiline format. - Initializes all the records in a subfile
SFLDROP
SFLINZ
SFLNXTCHG- Modifies the subfile record so that it is
read on a get-next-changed operation
16
Subfile Keywords (Contd.)
SFLRCDNBR - Specifies which page of the subfile
record should be displayed.
SFLCSRRRN - Returns the relative record number of
the subfile record on which the cursor is placed.
OVERLAY
- Displays the record without first clearing the screen. - Indicator is set on in the program when the user19presses the Roll Up key.
ROLLUP
Subfile Keywords (Contd.)
ROLLDOWN - Indicator is set on in the program when
the user presses the Roll Down key
HELP
- Allows the user to press the Help key for a displayed message that describes the valid function keys.
PUTRETAIN - Allows the value that is entered in the
SRHCOD field to be kept in the display.
18
Specifying Keywords in Subfile
19
Example of Sub file record formats
A A A A A A A A A A 27 A 28 A N27 R S01 S1BUSY S1TENT S1OUTO S1UNKN R C01 SFL 13A O 8 28 13A O 8 44 13A O 8 60 13A O 8 76 SFLCTL(S01) SFLSIZ(0011) SFLPAG(0010) OVERLAY SFLDSP SFLDSPCTL SFLCLR
20
A 29
SFLEND
Types of Subfiles
Load All Subfile Loads all records of the file into a large subfile before displaying the first screen Single Page Subfile Loads a single page of records and displays the subfile Expanding Subfile Loads the records to fill a single page and displays the subfile
21
LOAD ALL Subfile
SFLSIZ value should be one more than SFLPAG value. Record Limit is 9999. Automatic support for ROLLUP and ROLLDOWN keys. User has to wait until entire file is loaded. Data is only updated when the subfile is reloaded. Changes made to the data after the subfile is loaded will not be apparent. 22
SINGLE PAGE Subfile
Replaces the page with the next/previous page of data. Subfile size(SFLSIZ) value is equal to SFLPAG. Both ROLLUP & ROLLDOWN keys should be handled. Preferred for working with dynamic data. Uses least memory. No limit to the number of records.
23
EXPANDING Subfile
Adds a page at a time to the subfile. SFLSIZ value should be one more than the subfile page(SFLPAG) value.
Record Limit is 9999.
Automatic support for ROLLUP but ROLLDOWN key should be handled. Pages added when the Page down key is pressed are up-dated at the time they are added to the subfile.
24
Example of Expanding Subfile
Handling of page down key
Subfile size 1 greater than subfile page
25
Using Subfile in a program
To use a subfile the following basic operations should be performed in the high level language program
Initialize the subfile by reading records from database file and writing them to subfile. Send subfile to the display in one output operation using subfile control record format.
26
Using Subfile in a program(Contd..)
After the user reviews the records, changes them, or enters new records) read the subfile control record format Process each record in subfile individually, updating the database file or writing new records to the database file as required.
26
Important Terms used with Subfiles
Relative Record Number(RRN)
A number which associates a file record to the
location in the file where the record resides.
READC Operation
An RPG opcode strictly used with subfiles. It returns the next changed subfile record to the
program.
27
Summary
The concepts of subfiles Subfile Record Formats Subfile Control-Record Formats Types of Subfiles Subfile design using SDA. Subfile Processing Subfile validation and database updates. Addition and Modification Program Update and Delete Program Coding a message subfile.
31
Thank You