You are on page 1of 49

Keane School Of Excellence

Subfiles Concepts Programming

Module - 6

Objectives
What are Subfiles?
Why Use Subfiles?
Basic Subfile Concepts
Types of Subfiles
Subfile Formats
Subfile Keywords
Multiple Subfiles
Input and Update Subfiles
Equal Subfiles Vs Expanding Vs Loadall Subfiles
Limitations
2

What are Subfiles?

Subfiles are used in display file programming to allow


programmers to handle lists of columnar data more easily.
Subfiles are used to display the multiple records having
single record format.
Using subfiles users can select records:
Enquire
Edit
Delete the selected record (s)

Why Use Subfiles


Some typical ways you can make use of subfiles include:

Display only. The work-station user reviews the display.


Display with selection. The user requests more information about
one of the items on the display.
Display for Modification. The user changes one or more of the
records.
Display for Input only, with or without validity checking. A subfile is
used for a data entry function.
Display for Delete. A subfile is used to delete the record from the
database file.
Combination of tasks. A subfile can be used as a display with
modification, plus the input of new records.

Basic Subfile Concepts

Subfiles Process Two steps Loading and Displaying

Fig shows steps required to load a subfile and display it on a screen

File
1

Subfile Format
File
2

Subfile Control Format

Subfile Record
Subfile Record

File

Subfile Record

Subfile Record
Display
Subfile Record

Screen
5

Loading a Subfile
Loading a Subfile : You place records into the subfile format with a process known
as loading. During the loading process, you read one or more database files to
extract information. You then write this information in the form of subfile
records to the subfile format.
DATABASE FILES
File
1

Subfile Format
File

Subfile Record

2
Subfile Record
File
3

Subfile Record
Subfile Record

Displaying a Subfile : (i) Full screen mode


Work with Members Using PDM
Member

Type

Text

ARR1

RPG

ARRAYS.....

OERCHGRIC

RPGLE

Order Ent Fil Maintanance-Emplng.RI and Commitment

OERMNT#

RPGLE

Application to rely on Referential Integrity....

OERMNTRI

RPGLE

Application to rely on Referential Integrity....

PARMRPG

RPG

parm checking..............

PARM1

RPGLE

rpgle passsing

POVALID

RPGLE

rpgle passsing

RCVPARM

RPG

check pgmmmmmmmmmmm......
More...

Displaying a Subfile : (ii) Window subfile Example

Member

Type

ARR1

RPG

OERCHGRIC RPGLE
OERMNT#

RPGLE

OERMNTRI

RPGLE

F3 = Exit

Types of Subfiles
Load - all Method
Expanding Subfiles
Single Page Subfiles

Load-all Method
To load all of the records that you want to display into the subfile at one
time. After this load is complete, you can display the subfile, which
gives the users access to all of the subfile records by allowing them to
roll backwards and forwards. Subfile handles roll keys.
Data Base Files

Load All Method

File
1
Subfile Format
File

Subfile Record

2
Subfile Record
File
3

All records that a


user would want
see are loaded
into subfile

Subfile Record
Subfile Record

10

Load-all Method Contd.,

The main reason to use a load-all subfile is for simplicity in


programming. You do not need to program for the roll keys.
These are handled by the display file. This is used for small
loads. For bigger loads the performance is not good.

11

Expanding Subfile Method


In this method specific number of records are loaded each time user presses
Page Down Key. The number of records to be loaded each time are
specified in SFLPAG keyword in DDS of the Display file. The subfile
size is given SFLSIZ keyword in DDS of the Display file.
Subfile is displayed to the user after 1st set of records are loaded.
Database files

Extended Load Method


2

File
1

Subfile Format

File

Subfile Record

Subfile Record

File

Subfile Record

Subfile Record

The subfile is loaded


with a fixed number
of records
12

Expanding Subfile Method..Contd.,


If the user rolls forward, subfile automatically switches the display to Subfile page
two, three and so on, once the records are loaded to subfile
Subfile Format
Subfile Record
Subfile Record

Workstation Display
Subfile Record1

Sub file Page 1

Subfile Record2

Subfile Record
Subfile Record
Workstation Display
Subfile Record3
Subfile Record4

Sub file Page 2

Load fixed number of records into subfile, until user find the information on a
particular page

13

Expanding Subfile Method..Contd.,


One advantage of the expanding subfile over a load-all subfile
is that the subfile is displayed to the user in a very stable
amount of time, depending on how many records the
program loads. Performance achieved by this method is
better than the Load all.
But there is a limit of having maximum 9999 records in the
subfile

14

Single Page Load Method


In this method one subfile page is loaded at a time. Each time user presses
Page Down / Page Up Key, new set of records are loaded into the
subfile.

Database files

Single Page Load Method

File
1

Subfile Format
Subfile Record

File
1

Subfile Record

One page of
subfile records
loaded into subfile

15

Types Page
Single
of Subfiles
Load Method
3 of 3..Contd.,

Program loads only one page of records for display


Subfile Format
Subfile Record
Subfile Record

Workstation Display
Subfile Record1

Sub file Page1

Subfile Record2

Clear the existing subfile, and load some more records to subfile

Workstation Display
-----------------

Existing records are

-----------------

Cleared out

Now load another page of records


Load fixed number of records into subfile, until user find the information on a
particular page

16

Single Page Load Method ..Contd.,

Single-page subfiles are usually the least desirable method


because the program becomes much more involved. You
must handle the roll keys inside the program. This type of
subfiles are often used when the maximum number of
records that a user will attempt to roll through could exceed
9999.

17

Subfile Formats in DDS

Subfile Record Format (SFL)

Subfile Control Record Format (SFLCTL)

18

DDS for a Subfile Record Format


AAN01N02N03T.Name++++++RLen++TDpBLinPosFunctions++++++++
++++++++++++*
A** CUSTOMER NAME SEARCH
A
A

REF(DSTREF)
R

SUBFIL

SFL

TEXT('Subfile Record')

CUST

R 7 3

NAME

R 7 10

ADDR

R 7 32

CITY

R 7 54

STATE

R 7 77

A*
19

Subfile Record Format


The data description specifications (DDS) for a subfile record
format describe the records in the subfile:

The attributes for the fields in the record format are


contained in the field reference file DSTREF as specified
by the REF keyword.

The SFL keyword identifies the record format as a subfile.


The line and position entries define the location of the
fields on the display.

20

DDS for a Subfile Control-Record Format


AAN01N02N03T.Name++++++RLen++TDpBLinPosFunctions++++++++++++++++++++*
A

FILCTL

SFLCTL(SUBFIL)

A N70

SFLCLR

A 70

SFLDSPCTL

A 71

SFLDSP

SFLSIZ(15)

SFLPAG(15)

TEXT('Subfile Control Record')

OVERLAY

A 71
A

ROLLUP(97 'Continue Search')


CA01(98 'End of Program')

HELP(99 'Help Key')

2'Customer Name Search'

2'Search Code'

SRHCOD

I
5

10'Name'

32'Address'

14PUTRETAIN

2'Number'

21

Subfile Control Record Format

The subfile control-record format defines the attributes of the subfile,


the search input field, constants, and function keys.

The keywords you can use indicate the following:

SFLCTL names the associated subfile (SUBFIL).

SFLCLR indicates when the subfile should be cleared (when indicator


70 is off).

SFLDSPCTL indicates when to display the subfile control record


(when indicator 70 is on).

SFLDSP indicates when to display the subfile (when indicator 71 is


on).

SFLSIZ indicates the total number of records to be included in the


subfile (15).
22

Subfile Control Record Format

SFLPAG indicates the total number of records in a page (15).

ROLLUP indicates that indicator 97 is set on in the program when the


user presses the Roll Up 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

23

Subfile Keywords
SFLPAG (Subfile Page)
SFLSIZ (Subfile Size)
SFLINZ (Subfile Initialization)
SFLLIN (Subfile Line)
SFLRCDNBR (Subfile Record Number)
SFLRNA (Subfile Record Not active)
SFLNXTCHG (Subfile Next Changed)
SFLENTER (Subfile Enter)
SFLCSRRRN (Subfile Cursor Relative Record No.)
+ more..

24

Subfile Keywords
SFLPAG (Records per display) This keyword identifies the
number of records within the subfile that can appear at the
same time. You must specify the SFLPAG keyword for
subfile. SFLPAG cannot be greater than the SFLSIZ

25

Subfile Keywords
SFLSIZ (Subfile Size) - The meaning of this keyword depends
on the value to which the SFLPAG keyword is set. If the
SFLSIZ is equal to the SFLPAG, then the maximum
number of records that can be loaded into the subfile at any
one time is equal to the SFLSIZ. SFLSIZ cannot be less
than the value specified in the SFLPAG keyword. If the
value of SFLSIZ is greater than SFLPAG, then the subfile is
initially sized to handle the number of records specified in
SFLSIZ. However, the subfile will extend itself to handle
more records if the program writes more records than the
number specified in SFLSIZ.
26

Subfile Keywords
SFLINZ (Subfile Initialization) : It allows you to initialize the subfile with
as many active records as the value specified in the SFLSIZ keyword.
If you specify SFLINZ and your subfile size is set to 100, your subfile
would contain 100 active, but blank, subfile records.
SFLRNA (Subfile Record Not Active) : It is used in conjunction with the
SFLINZ keyword. When the two are specified together, the subfile is
initialized with inactive records.
SFLNXTCHG (Subfile Next Changed Record) : It is used to flag a subfile
record as changed and if the program displays it again on the screen,
not lose that attribute. This keyword is specified on the subfile format
because the SFLNXTCHG information will be unique to each subfile
record. It is actually stored in the record, but cannot be viewed on the
screen, similar to a hidden field.

27

Subfile Keywords
SFLEND (Sufile End) : When it is specified, you will get a + pr the
MORE message at the end of your subfile, regardless of whether
the controlling indicator is on or off.
SFLDROP (Subfile Drop) : It tells the subfile program that it should
initially be displayed with only the first subfile line in view. The rest of
the subfile record, which exists on separate lines, should be dropped
from view.
SFLCSRRRN (Subfile Cursor Relative Record Number) : Using this
keyword, the subfile will return the relative record number of the
subfile record on which the cursor was positioned.
SFLLIN (Subfile Line) : Using it you can create a horizontal subfile. In
other words, you can cause a subfile to display more than one subfile
record per line.

28

Subfile Keywords
SFLRCDNBR (Subfile Record Number) : Using it you can control which
subfile page the subfile displays when you output the subfile. By
placing a value in the subfile record number keyword field, the subfile
will locate the page on which that subfile record resides. When it finds
the page, it displays that page first. Then you can roll up and down
from that point.
SFLCLR (Subfile Clear) : It removes all records out of a subfile. If the
user changes the position-to field, the program needs to clear out all the
existing records in the subfile. Then it can set lower limits on the file
and start filling up the subfile up.
SFLENTER (Subfile Enter) : It makes the Enter key act like the roll-up
key. You can then define a function key to act as the Enter key. One
reason you might want to do this is for mouse-controlled terminals
+ more.
29

Subfile Coding Single Page Load

30

Display File (DDS) 1 of 2


0000.30
0000.31
0000.32
0000.40
0000.60
0000.80
0001.00
0001.20
0001.40
0001.50
0001.60
0001.70
0001.80
0001.90
0002.00

DSPSIZ(24 80 *DS3)
CA03
CA12
A
R SFL1
SFL
A
DBLNAM R
O 5 3REFFLD(PFR/DBLNAM/PMICENTRALF)
A
DBFNAM R
O 5 26REFFLD(PFR/DBFNAM PMICENTRALF)
A
DBNAM R
O 5 49REFFLD(PFR/DBNNAM PMICENTRALF)
A
R SF1CTL
SFLCTL(SFL1)
A
OVERLAY
A N32
SFLDSP
A N31
SFLDSPCTL
A 31
SFLCLR
A 90
SFLEND
A
SFLSIZ(0006)
A
SFLPAG(0006)

31

Display File (DDS) 2 of 2


0002.20
0002.30
0002.40
0002.50
0002.60
0002.70
0002.80
0002.90
0003.00
0003.10
0003.30
0003.40
0003.50
0003.60

A
A
A
A
A
A
A
A
A
A
A
A
A
A

1 64DATE
EDTCDE(Y)
2 64TIME
3 11'Last Name'
COLOR(WHT)
3 31'First Name'
COLOR(WHT)
3 52'Nick Name'
COLOR(WHT)
R FKEY1
23 2'F3=Exit'
COLOR(BLU)
23 11'F12=Cancel'
COLOR(BLU)

32

Subfile Coding Expanding Subfiles

33

Display File (DDS) 1 of 2


0000.30
0000.31
0000.32
0000.40
0000.60
0000.80
0001.00
0001.20
0001.40
0001.50
0001.60
0001.80
0001.90
0002.00

A
R SFL1
A
DBLNAM R
A
DBFNAM R
A
DBNAM R
A
R SF1CTL
A
A N32
A N31
A 90
A
A

DSPSIZ(24 80 *DS3)
CA03
CA12
SFL
O 5 3 REFFLD(PFR/DBLNAM/PMICENTRALF)
O 5 26 REFFLD(PFR/DBFNAM PMICENTRALF)
O 5 49 REFFLD(PFR/DBNNAM PMICENTRALF)
SFLCTL(SFL1)
OVERLAY
SFLDSP
SFLDSPCTL
SFLEND
SFLSIZ(0007)
SFLPAG(0006)

34

Display File (DDS) 2 of 2


0002.20
0002.30
0002.40
0002.50
0002.60
0002.70
0002.80
0002.90
0003.00
0003.10
0003.30
0003.40
0003.50
0003.60

A
A
A
A
A
A
A
A
A
A
A
A
A
A

1 64DATE
EDTCDE(Y)
2 64TIME
3 11'Last Name'
COLOR(WHT)
3 31'First Name'
COLOR(WHT)
3 52'Nick Name'
COLOR(WHT)
R FKEY1
23 2'F3=Exit'
COLOR(BLU)
23 11'F12=Cancel'
COLOR(BLU)

35

Subfile Coding Load All

36

Display File (DDS) 1 of 2


0000.30
0000.31
0000.32
0000.40
0000.60
0000.80
0001.00
0001.20
0001.40
0001.50
0001.60
0001.80
0001.90
0002.00

DSPSIZ(24 80 *DS3)
CA03
CA12
A
R SFL1
SFL
A
DBLNAM R
O 5 3REFFLD(PFR/DBLNAM/PMICENTRALF)
A
DBFNAM R
O 5 26REFFLD(PFR/DBFNAM PMICENTRALF)
A
DBNAM R
O 5 49REFFLD(PFR/DBNNAM PMICENTRALF)
A
R SF1CTL
SFLCTL(SFL1)
A
OVERLAY
A N32
SFLDSP
A N31
SFLDSPCTL
A 90
SFLEND
A
SFLSIZ(0016)
A
SFLPAG(0004)

37

Display File 2 of 2
0002.10
0002.20
0002.30
0002.40
0002.50
0002.60
0002.70
0002.80
0002.90
0003.00
0003.10
0003.30
0003.40
0003.50
0003.60

A
A
A
A
A
A
A
A
A
A
A
A
A
A
A

RRN1

4S 0H SFLRCDNBR
1 64DATE
EDTCDE(Y)
2 64TIME
3 11'Last Name'
COLOR(WHT)
3 31'First Name'
COLOR(WHT)
3 52'Nick Name'
COLOR(WHT)

R FKEY1
23 2'F3=Exit'
COLOR(BLU)
23 11'F12=Cancel'
COLOR(BLU)

38

Subfile Program 1 of 2
0002.00 FSFL001DF CF E
WORKSTN
0002.02 F
SFILE(SFL1:RRN1)
0004.00 FSFL001LF IF E
k DISK
0005.00 *BUILD THE SUBFILE
0007.00 C
EXSR
sflbld
0008.00 C
DOU
*INKC or *inkl
0009.00 C
WRITE FKEY1
0010.00 C
EXFMT SF1CTL
0011.00 C
ENDDO
0012.00 C
EVAL *INLR = *ON
0012.02 C sflbld begsr
0012.03 *clear subfile
0012.05 C
eval
rrn1=*zero
0012.06 C
eval
*in31 = *on
0012.07 C
write sf1ctl
0012.08 C
eval
*in31 = *off
39

Subfile Program 2 of 2
0013.00 *load the data in subfile
0015.00 C *loval setll sfl001lf
0016.00 C
read
sfl001lf
90
0017.00 C
dow (not *in90) and (rrn1 <= 500)
0017.02 C
eval
rrn1=rrn1+1
0017.03 C
write sfl1
0017.04 C
read
sfl001lf
0017.05 C
enddo
0018.00 *if no records were loaded ,do not display the subfile
0020.00 C
if
rrn1 = *zero
0022.00 C
eval
*in32 = *on
0023.00 C
else
0025.00 C
eval
rrn1=1
0026.00 C
endif
0027.00 C
endsr
40

Message Subfiles

41

MESSAGE SUBFILES
*

Used to display multiple messages


All errors can be corrected at once instead of one
by one each time
Less coding
More efficiency

42

MESSAGE SUBFILE KEYWORDS

SUBFILE RECORD
SFLMSGRCD
SFLMSGKEY
SFLPGMQ
SUBFILE CONTROL

SFLDSP

SFLDSPCTL

SFLINZ

SFLPGMQ

SFLSIZ

SFLPAG

SFLEND
43

Example - Display File DDS


***************************************************************************
A
DSPSIZ(24 80 *DS3)
A
CF03(03)
A
R DTASCR
A
OVERLAY
A
5 10'Employee Number : '
A
7 10'Employee Name
: '
A
9 10'Basic Salary
: '
A
11 10'H.R.A.
: '
A
13 10'P.F.
: '
A
EMPNO
R
B 5 30REFFLD(EMPREC/EMPNO
TRY/AAEMP)
A
EMPNAM
R
B 7 30REFFLD(EMPREC/EMPNAM TRY/AAEMP)
A
BASPAY
R
B 9 30REFFLD(EMPREC/BASPAY TRY/AAEMP)
A
EDTCDE(4)
A
HRA
R
B 11 30REFFLD(EMPREC/HRA TRY/AAEMP)
A
EDTCDE(4)
A
PF
R
B 13 30REFFLD(EMPREC/PF TRY/AAEMP)
A***********************************************************************
****

44

Example - Display File DDS Contd.,


**************************************************************
*************
A
EDTCDE(4)
A
R MSFL1
SFL
A
SFLMSGRCD(24)
A
@KEY
SFLMSGKEY
A
QPGMQ
SFLPGMQ()
A***********************************************************
****************
A
R MSFCTL
SFLCTL(MSFL1)
A
OVERLAY
A
SFLDSP
A
SFLDSPCTL
A
SFLINZ
A 30
SFLEND()
A
SFLSIZ(0002)
A
SFLPAG(0001)
A
QPGMQ
SFLPGMQ()
A***********************************************************
****************
45

EXAMPLE - RPG Program


FMSGSCR CF
**

WORKSTN

*--------------------------------------------------------------**
C* Write Message Subfile Control Record.
C
WRITEMSFCTL
C* Write & Read the Data Screen.
C
EXFMTDTASCR
C* Process the Command Keys.
C
EXSR @CMD
C* Clear the Program Queue.
C
MOVE '*CLEAR ' $MSGID
C
MOVE *BLANKS
$MSGDT
C
CALL 'SNDPGM' PARM1
46

EXAMPLE - RPG Program (Contd)


C* Validation Routines......
C
EMPNO
IFEQ *BLANKS
C
MOVE 'MSG0001'
C
CALL 'SNDPGM'
C
ENDIF
C
EMPNAM
IFEQ *BLANKS
C
MOVE 'MSG0002'
C
CALL 'SNDPGM'
C
ENDIF
C
BASPAY
IFEQ 0
C
HRA
OREQ 0
C
PF
OREQ 0
C
MOVE 'MSG0003'
C
CALL 'SNDPGM'
C
ENDIF
**

$MSGID
PARM1
$MSGID
PARM1

$MSGID
PARM1

*--------------------------------------------------------------**
47

EXAMPLE - CL Program (Sending Message)


PGM
DCL
DCL

PARM(&MSGID &MSGDTA)
VAR(&MSGID) TYPE(*CHAR) LEN(7)
VAR(&MSGDTA) TYPE(*CHAR) LEN(80)

IF

COND(%SST(&MSGID 1 6) *EQ '*CLEAR') THEN(DO) +


/* Clear Program Q, If requested */
RMVMSG
PGMQ(*PRV) CLEAR(*ALL) /* Clear it */
MONMSG
MSGID(CPF0000) /* Monitor Run Time Messages */
ENDDO
ELSE
CMD(DO) /* Send a Message from Application +
Message File */
SNDPGMMSG MSGID(&MSGID) MSGF(MYMSGS) MSGDTA(&MSGDTA) +
TOPGMQ(*PRV *)
ENDDO
EOJ: ENDPGM

48

Questions and Answers

You might also like