After reading the post about controlling the cursor's movement on a display file, a friend asked:
How can I make the cursor stay in the same column when I tab through a subfile?
What I described in that post will not work on a subfile as each record's fields have the same names. I would have to use another approach.
Subfile have their own keyword to control cursor movement: Subfile Cursor Progression, SFLCSRPRG. This is a field level keyword that is placed with a field in the subfile. The field must be input or both, of course. Alas, only one field in the subfile can have this keyword. You cannot condition the keyword by using indicators.
Here is my very simple display file with a subfile with the SFLCSRPRG keyword:
01 A DSPSIZ(24 80 *DS3)
02 A CA03(03 'Exit')
03 A INDARA
*-------------------------------------------------------------
04 A R SFL01 SFL
05 A ZRRN 4Y 0O 2 2EDTCDE(Z)
06 A ZFIELD1 10A B 2 9SFLCSRPRG
07 A ZFIELD2 2A B 2 20
*-------------------------------------------------------------
08 A R CTL01 SFLCTL(SFL01)
09 A SFLSIZ(0100)
10 A SFLPAG(0010)
11 A SFLDSP
12 A SFLDSPCTL
13 A 30 SFLEND(*MORE)
14 A 1 3'Subfile'
15 A DSPATR(HI)
|
Lines 1 – 3: This are the file level definitions.
Line 3: The INDARA keyword allows the RPG program that uses this display file to have an indicator data area.
Lines 4 – 7: The subfile details.
Line 5: This is the subfile relative record number field; I am displaying it so you can see upon which record the cursor is positioned.
Line 6: A both (input and output) field that has the SFLCSRPRG keyword.
Line 7: A second both field.
Lines 8 – 15: The subfile control details.
Lines 9 and 10: The subfile size, SFLSIZ, gives the number of records the subfile can contain. The subfile page, SFLPAG, gives the maximum number of records that are displayed on each page.
Line 13: I like to have the "More…" and "Bottom" at the bottom of my subfile pages. I need to condition these keyword with an indicator.
The RPG program is similarly simple:
01 **free
02 ctl-opt option(*nodebugio:*srcstmt) dftactgrp(*no) ;
03 dcl-f TESTDSPF indds(Dspf) sfile(SFL01:ZRRN) ;
04 dcl-ds Dspf qualified ;
05 Exit ind pos(3) ;
06 EndOfSfl ind pos(30) ;
07 end-ds ;
08 LoadSubfile() ;
09 dow (*on) ;
10 exfmt CTL01 ;
11 if (Dspf.Exit) ;
12 leave ;
13 endif ;
14 enddo ;
15 *inlr = *on ;
//------------------------------------------------
16 dcl-proc LoadSubfile ;
17 for ZRRN = 1 to 15 ;
18 write SFL01 ;
19 endfor ;
20 Dspf.EndOfSfl = *on ;
21 end-proc ;
|
Line 2: I have my favorite control options, as I do not want to debug the I/O to the subfile, and I want to program sequence number to be the same as the source statement numbers. As I call a subprocedure I cannot use the default activation group.
Line 3: The definition for the display file.
Lines 4 – 7: The indicator data area, which is the other end of the display file's INDARA. Indicator 3 is mapped to the name "Exit", and the subfile end, indicator 30, is mapped to "EndOfSfl".
Line 8: This is the subprocedure where the subfile is loaded.
Lines 9 – 14: This is a never-ending Do-loop.
Line 10: The subfile is shown.
Lines 11 – 13: If the F3 key is pressed the indicator Exit in the indicator data structure is on, and I leave the Do-loop.
Lines 16 – 20: This is the subprocedure that loads the subfile.
Lines 17 – 19: I am using a For-group to write fifteen records to the subfile.
Line 20: I need to set on the EndOfSfl indicator, 30, so that the subfile will display "Bottom" at the end of the subfile.
After compiling the program, I call it and the following is displayed:
Subfile
1
2
3
4
5
6
7
8
9
10
More...
|
When I press the Tab key the cursor moves to the second subfile record:
Subfile
1
2
3
4
5
6
7
8
9
10
More...
|
Pressing the tab key moves the cursor to the same column in each subfile record until I reach the tenth record:
Subfile
1
2
3
4
5
6
7
8
9
10
More...
|
When I press the tab key the cursor moves to the second column:
Subfile
1
2
3
4
5
6
7
8
9
10
More...
|
Pressing the tab key again it returns to the first column on the first subfile record.
To move to the eleventh record I need to page down to the next subfile page:
Subfile
11
12
13
14
15
Bottom
|
The cursor is positioned in the first column of the eleventh record of the subfile. When the tab key is pressed the cursor moves down to the corresponding column in the twelfth record. When it reaches the fifteenth and the tab key is pressed again the cursor moves to the second column. Press it again and it returns to the first column in the eleventh record.
This shows how to achieve what the question asked for, apart from the annoying trait that the cursor moves to the other fields in the last subfile record on each page.
You can learn more about the SFLCSRPRG DDS display file keyword command from the IBM website here.
This article was written for IBM i 7.6, and should work for some earlier releases too.




No comments:
Post a Comment
To prevent "comment spam" all comments are moderated.
Learn about this website's comments policy here.
Some people have reported that they cannot post a comment using certain computers and browsers. If this is you feel free to use the Contact Form to send me the comment and I will post it for you, please include the title of the post so I know which one to post the comment to.