Thursday, June 19, 2008

Subfiles

Subfiles
A subfile is a group of records that is read from or written to a display device file in one operation.
Created with two parts
i) Data part SFL
ii) Control part. SFLCTL

e.g.
In subfiles, there are three methods to load

It can be

i) Size > page (Load all)

ii) Size = Page (Load on demand)

iii) Size > Page (Expandable i.e. Size > Page (size only one greater than page))


i) Load all
ii) And iii) are Load on demand

Load All
In load all we can load up to 9,999 records. All records are loaded by clearing the subfile one time, and then loading all the records into subfile at a time. Each and every record gets written to the subfile by incrementing the RRN. Then we can EXFMT the screen for displaying the subfile.

First we have to set display layout for the subfile.
SFLSIZ, SFLPAG. We have to set indicators for the subfile control part for SFLCLR, SFLDSPCTL, and SFLDSP.

Demo program is shown below. For getting basic idea.



A SFLSIZ(0007
A SFLPAG(0006)
A OVERLAY
A 12 SFLDSP
A 13 SFLDSPCTL
A 14 SFLCLR


RPG program is as below.

FPFNAME UF E K DISK A
FDSPFILE CF E WORKSTN
F RRN KSFILE DATA
C *IN03 DOWEQ*OFF
C EXSR CLR
C EXSR LOAD
C EXSR DSP
C ENDIF
C ENDDO
C SETON LR
C***----CLEAR SUBPROGAM
C CLR BEGSR
C SETON 40
C WRITECONTROL part name
C SETOF 40
C Z-ADD0 RRN 40
C ENDSR
C***----LOADING SUBPRORAM
C LOAD BEGSR
C *LOVAL SETLL pf rec format
C READ pf rec format 50
C *IN50 DOWEQ*OFF
C ADD 1 RRN
C WRITEDATA
C READ pf rec format 50
C ENDDO
C ENDSR
C***----- DISPLAYING SUBPROGRAM
C DSP BEGSR
C SETON 2030
C EXFMTCONTROL part name
C SETOF 2030
C ENDSR



SIZE = PAGE (LOAD ON-DEMAND)
In load on-demand we can load more than 9,999 records to the subfile. In this subfile we have to load the records only at the demand. (I.e. When ever page down is pressed we have to take control of the subfile and for page up also).

When we declare the display layouts for the subfile SFLSIZ and SFLPAG, take care of both to be equal. And for PAGEUP and PAGEDWN we have to set indicator for them and we should handle them in the program.

We have to care of the page down and page up by noticing the first and last position of the subfile records displayed at that page. If you read the code you can understand it easily.

HOPTION (*NODEBUGIO)
FSINGLEPF IF E K Disk
FSINGLEDSPFCF E Workstn Sfile (SNGSFL: Rrn1)
C ExSR #CLEARSNG
C ExSR #LOADSNG
C DoW Not *In03
C ExSR #VIEWSNG
C 03 Leave
C If *In15 = *On
C N71 ExSR #CLEARSNG
C ExSR #PGDOWN
C EndIf
C If *In16 = *On
C* N72 ExSR #CLEARSNG
C ExSR #PGUP
C EndIf
C EndDO
C SetON LR
********************
C #CLEARSNG BegSR
C 15 z-add 0 RRn1 4 0
C 16 z-add 6 RRn1
C Eval *In21 = *Off
C Eval *in22 = *Off
C Eval *In34 = *Off
C Eval *In71 = *Off
C Eval *In72 = *Off
C Eval *In33 = *On
C Write SNGSFLCTL
C Eval *In33 = *Off
C EndSR
********************
C #LOADSNG BegSR
C *Loval SetLL SNGREC
C Do 5
C Read SNGREC 71
C Eval Rrn1 = Rrn1 + 1
C N71 Write SNGSFL
C If Rrn1 = 1
C Move PNO first 2 0
C Else
C Move PNO last 2 0
C EndIf
C EndDo
C* Read SNGREC 71
C EndSR
*********************
C #VIEWSNG BegSR
C If Rrn1 <> 0
C Eval *In31 = *On
C EndIf
C Eval *In32 = *On
C Write SNGFTR
C Exfmt SNGSFLCTL
C EndSR
***********************
C #PGDOWN BegSR
C Last SetGT SNGREC
C* Z-Add 0 Rrn1 4 0
C Read SNGREC 71
C 71 Eval *In34 = *On
C 71 Eval *In22 = *On
C 71 LeaveSR
C Do 5
C
C N71 Eval Rrn1 = Rrn1 + 1
C N71 Write SNGSFL
C If Rrn1 = 1
C Move PNO first
C Else
C Move PNO last
C EndIf
C
C Read SNGREC 71
C EndDo
C EndSR
****************************
C #PGUP BegSR
C First SetLL SNGREC 54
C* z-add 6 Rrn1
C ReadP SNGREC 72
C 72 Eval *In21 = *On
C 72 LeaveSR
C ExSR #CLEARSNG
C Do 5
C N72 Eval Rrn1 = Rrn1 - 1
C N72 Write SNGSFL
C If Rrn1 = 5
C Move PNO last
C Else
C Move PNO first
C EndIf
C
C ReadP SNGREC 72
C EndDo
C EndSR

EXPANDABLE SUBFILE
In expanding subfile we have to declare the size just greater than one from page.
Such that we have to make SFLRCDNBR to be declared in the subfile.

Steps:
Make a output variable in control part of the subfile with the size equal to the RRN.
Make it non-display and then set ‘Y’ for SFLRCDNBR.(In display attributes of that output field).
Rename the same output field.

We have to take care of the PAGEDOWN only, as we have given size greater than the page by one. System may take care of the PAGEUP.
Initially we have to make SFLRCDNBR field to 1, while load begins. Then in loading
Part we have to make RRN field equal to the SFLRCDNBR. Such that for next page up system can load the records for the previous page. You can understand better as you see the sample program code.

Disadvantage:
Same as load-all we can load only up to 9,999 records to the subfile.

HOPTION(*NODEBUGIO)
FPFname UF A E K DISK
FDspfilnam CF E WORKSTN SFILE(SDPT:RRN)
C EXSR CLR
C EXSR LOAD
C *IN03 DOWEQ *OFF
C EXSR DSP
C *IN15 IFEQ *ON
C *IN38 IFEQ *OFF
C EXSR PGDWN
C ENDIF
C ENDIF
C ENDDO
C SETON LR
*****************
C CLR BEGSR
C SETON 14
C WRITE SCPT
C SETOFF 14
C Z-ADD 0 RRN 3 0
C ENDSR
************
C DSP BEGSR
C IF RRN=0
C EVAL *IN12=*OFF
C ELSE
C SETON 1213
C ENDIF
C EVAL *IN13=*ON
C EXFMT SCPT
C SETOFF 1213
C ENDSR
****************
C LOAD BEGSR
C *LOVAL SETLL STUDENT
C DO 6
C READ STUDENT 38
C 38 LEAVE
C ADD 1 RRN
C EXSR REP_A
C WRITE SDPT
C ENDDO
C EVAL RN=RRN
C ENDSR
*****************
C PGDWN BEGSR
C DO 6
C EXSR CLEARING
C READ STUDENT 38
C 38 LEAVE
C ADD 1 RRN
C EXSR REP_A
C WRITE SDPT
C ENDDO
C EVAL RN=RRN
C ENDSR
C REPL BEGSR
C MOVE SNO_S SNO
C MOVE NAME_S NAME
C MOVE M1_S M1
C MOVE M2_S M2
C MOVE M3_S M3
C MOVE TOT_S TOT
C MOVE AVG_S AVG
C MOVE GRADE_S GRADE
C ENDSR
C REP_A BEGSR
C MOVE SNO SNO_S
C MOVE NAME NAME_S
C MOVE M1 M1_S
C MOVE M2 M2_S
C MOVE M3 M3_S
C MOVE TOT TOT_S
C MOVE AVG AVG_S
C MOVE GRADE GRADE_S
C ENDSR
C CLEARING BEGSR
C EVAL SNO_S=*ZEROS
C EVAL NAME_S=*BLANKS
C EVAL M1_S=*ZEROS
C EVAL M2_S=*ZEROS
C EVAL M3_S=*ZEROS
C EVAL TOT_S=*ZEROS
C EVAL AVG_S=*ZEROS
C EVAL GRADE_S=*BLANKS
C ENDSR