
I was asked how is it possible to determine where the cursor is on a subfile when the F4 key is pressed.
I have written about the parts needed to achieve this in separate posts, and I thought it would be a good idea to put it all together into one new post.
What I would need is:
- A subfile program
- Determine when the F4 is pressed
- Retrieve the record format name
- Retrieve subfile relative record number, RRN, of the record the cursor is on
- Retrieve the name of the field the cursor is on in the subfile
First off, I need a subfile display file, a simple one. The code for a minimalist subfile could be:
01 A INDARA 02 A CA03(03 'Exit') *-------------------------------------------------- 03 A R SFL01 SFL 04 A ZRRN 2S 0O 2 2 05 A ZFIELD1 10A B 2 7 06 A ZFIELD2 10A B 2 18 07 A ZFIELD3 10A B 2 29 08 A ZFIELD4 10A B 2 40 09 A ZFIELD5 10A B 2 51 10 A ZFIELD6 10A B 2 62 *-------------------------------------------------- 11 A R CTL01 SFLCTL(SFL01) 12 A SFLSIZ(0010) 13 A SFLPAG(0010) 14 A OVERLAY 15 A 31 SFLDSP 16 A 30 SFLDSPCTL 17 A N30 SFLCLR 18 A 30 SFLEND(*MORE) 19 A CA04(04 'Prompt') 20 A SFLCSRRRN(&ZSFLRRN) 21 A RTNCSRLOC(&ZRCDFMT &ZFIELD) 22 A ZSFLRRN 5S 0H 23 A ZRCDFMT 10A H 24 A ZFIELD 10A H 25 A 1 2'This is a subfile' 26 A DSPATR(HI) |
Line 1: Like all modern display files this one has the INDARA, indicator area, so that is may use the indicator data structure in a RPG program.
Line 2: F3 key defined as indicator 3.
Line 3: Start of the subfile record format.
Line 4: I am displaying the subfile's relative record number as output.
Lines 5 – 10: Five fields which will be used for "both", input and output.
Lines 11 – 18: What I call the "subfile control stuff". I described this in detail in my post about writing a simple subfile program.
Line 19: F4 is defined as indicator 4.
Line 20: I can use this keyword, SFLCSRRRN, to place the subfile's RRN into the given variable.
Line 21: This keyword, RTNCSRLOC, returns the record format and field names where the cursor is.
Line 22: The field the subfile's RRN will be in.
Line 23: Record format name field.
Line 24: Field name field.
Line 25: Record format heading.
The RPG program I wrote consists of three parts. The first part is the "main body" of the program:
01 **free 02 ctl-opt option(*srcstmt) dftactgrp(*no) ; 03 dcl-f TESTDSPLF workstn indds(Dspf) sfile(SFL01 : ZRRN) ; 04 dcl-ds Dspf qualified ; 05 Exit ind pos(3) ; 06 Prompt ind pos(4) ; 07 SflDspCtl ind pos(30) ; 08 SflDsp ind pos(31) ; 09 end-ds ; 11 LoadSfl() ; 12 dow (*on) ; 13 exfmt CTL01 ; 14 if (Dspf.Exit) ; 15 leave ; 16 elseif (Dspf.Prompt) ; 17 WhereIsCursor() ; 18 endif ; 19 enddo ; 20 *inlr = *on ; |
Line 2: My favorite control option, *SRCSTMT, and this program cannot run in the default activation group as it has sub procedures.
Line 3: The definition of the display file, which I called TESTDSPF. It uses the indicator data structure, INDDS, and as it contains a subfile I need to define which field is to be used a the RRN for the subfile.
Lines 4 – 9: The indicator data structure. This is where I give all the indicators on the display meaningful names.
Line 11: I call a subprocedure to load the subfile.
Lines 12 - 19: A "never ending" Do loop to display the subfile.
Line 13: Displays the subfile, and awaits input.
Lines 14 and 15: If the F3 key is pressed, indicator three is on, which translated to Exit in the program. And processing exits the Do loop.
Lines 16 and 17: If the F4 was pressed, Prompt is on and the subprocedure is called to determine where the cursor is in the subfile.
As this is an example program the subprocedure to load the subfile is very simple:
21 dcl-proc LoadSfl ; 22 for ZRRN = 1 to 10 ; 23 write SFL01 ; 24 endfor ; 25 Dspf.SflDspCtl = *on ; 26 Dspf.SflDsp = *on ; 27 end-proc ; |
Lines 22 – 24: I am using a For group to write ten records to the subfile.
Lines 25 and 26: I then turn on the indicators to display the subfile and the subfile control record formats.
The other subprocedure displays the information we desire:
28 dcl-proc WhereIsCursor ; 29 dsply ('Record format = ' + ZRCDFMT) ; 30 dsply ('Subfile RRN = ' + %char(ZSFLRRN)) ; 31 dsply ('Field name = ' + ZFIELD) ; 32 end-proc ; |
Do I really need to describe what the above does? I use the Display operation code, DSPLY, to show record format name, subfile RRN, and the subfield field.
When both the display and RPG program are created, and the program is called, the following is displayed:
This is a subfile 01 02 03 04 05 06 07 08 09 10 |
What happens when I use this screen? When I position the cursor on various subfile records and in various fields and press F4 I get the following displayed:
DSPLY Record format = SFL01 DSPLY Subfile RRN = 1 DSPLY Field name = ZFIELD1 DSPLY Record format = SFL01 DSPLY Subfile RRN = 3 DSPLY Field name = ZFIELD4 DSPLY Record format = SFL01 DSPLY Subfile RRN = 8 DSPLY Field name = ZFIELD5 DSPLY Record format = SFL01 DSPLY Subfile RRN = 10 DSPLY Field name = ZFIELD6 |
This make it very easy for the questioner to get what they wanted.
This article was written for IBM i 7.5 TR5 and 7.4 TR11.
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.