Problem solve Get help with specific problems with your technologies, process and projects.

Which record was the cursor on?

Is there a way of returning control to the RPG program when using SFLDROP/SFLFOLD? The problem I have is that I want to determine which record the cursor was on when the appropriate function key was pressed. I then want to move this record to the top of the subfile so that it is available to the user without them needing to scroll down to the relevant record. Do you have any thoughts on how to achieve this?

"Yes, but..."

 In the DSPF DDS, try this: 

     A N16                                   SFLFOLD(CF01)                   
     A  16                                   SFLDROP(CF01)                   
     A                                       SFLMODE(&SFL1MODE)               
     A                                       SFLCSRRRN(&CRRN)                 
     A                                       RTNCSRLOC(*WINDOW &CROW &CCOL)   
     A                                       RTNCSRLOC(*RECNAME &CREC &CFLD) 

The SFLFOLD and SFLDROP lines are the ones to look at -- the others are useful for positioning your subfile and returning/setting the cursor in the subfile.

Note: I'm using the F1 key as the fold/drop key, and controlling the keywords with F16. I'm using F1 because it is NOT a standard or often-used function key in my shop.

Now in the RPG/ILE source, I set the mode to truncated in *INZSR:


     C                   Eval      *In16       = *On                            ¦ Start in       
     C                   Eval      Sfl1Mode    = *On                            ¦ truncated mode  

In the mainline, when testing for the function key the user returns, I use a CASE block:


     C     Fkey          CasEq     fnExit        EndScreenLoop                  Exit             
     C     Fkey          CasEq     fnRefresh     RefreshScreen                  Reload F5         
     C     Fkey          CasEq     fnClear       RefreshScreen                  Reload CLEAR     
     C     Fkey          CasEq     fnPrevious    EndScreenLoop                  Previous         
     C     Fkey          CasEq     fnHelp        ShowHelp                       Show help text   
===> C     Fkey          CasEq     fnFold        FoldDrop                       Fold/Drop s'file 
     C     Fkey          CasEq     fnPrint       PrintScreen                    Show help text   
     C     Sfl1SelDta    CasNe     Sfl1SelDtaCpy LoadScreen                     Reload screen     
     C                   Cas                     CheckScreen                    Check screen     
     C                   EndCs                                                                   

The important line here is marked -- the function key fnFold is NOT CF01, but CF17, which is shown on the screen as the Fold/Drop function key.

(NOTE: I do not match the *INnn indicators with the CF/CAnn keys, I use the AID byte -- so don't think that CF17 = *IN17)

Click here to view the subroutine.

An easy switch, here. The user presses F17 to switch between truncated and folded, under program control. You can detect the subfile RRN under the cursor in this routine, and set CRRN so that on redisplay that record will be on the screen with the cursor still on it.

Now here is the BUT...

You can't get around the CF01 key. That's the key I specified for SFLDROP/SFLFOLD in the DDS. If the user presses F1, the screen will behave 'normally' and control will NOT return to your program.

Dig Deeper on RPG iSeries programming

Have a question for an expert?

Please add a title for your question

Get answers from a TechTarget expert on whatever's puzzling you.

You will be able to add details on the next page.

Start the conversation

Send me notifications when other members comment.

Please create a username to comment.