Return to the RPG Tips
Selecting a Subfile Record by Cursor Location
If you want to let a user select a subfile record by positioning the cursor anywhere on that subfile record and then pressing Enter or a function key (defined as a CFxx key in DDS), you can add the SFLCSRRRN (Subfile Cursor Relative Record Number) keyword to the subfile control format in your DDS: A R SFLCTL SFLCTL(SFL) . . . A SFLCSRRRN(&CSRRRN) A 61 SFLMSG('Must place cursor on a - A record, then press Enter.' 61) . . . A CSRRRN 5S 0H Then use the RPG routine below (here, it's a subroutine) to process the subfile: C @SFLRD BEGSR * * returned good subfile rrn for cursor position C CSRRRN IFNE 0 C CSRRRN CHAINSFL 21 * here you can retrieve any value from the subfile record C ELSE * cursor not positioned in subfile, send error message C MOVE *ON *IN61 C ENDIF * C ENDSR Note that if variable CSRRRN returns the value 0, the user positioned the cursor somewhere other than on a valid subfile record. Otherwise, variable CSRRRN contains the number of the subfile record the user selected, and you can then access the subfile record via a CHAIN to retrieve any value you might need in your program.
[report a broken link by clicking here]