Newsletters Subscriptions Media Kit About Us Contact Search Home

mgo
OS/400 Edition
Volume 3, Number 28 -- April 23, 2003

Select Subfile Records by Position


Hey, Ted:

We have inquiry programs that require users to key an X next to a subfile record in order to select the record. I have seen programs that require that a user place the cursor on a subfile record and press Enter to select it. If we could use that technique, it would mean less keying for the users. Can you tell me how to select a subfile record by cursor position?

--Chad


This is not a difficult technique to use, and, yes, it will help the users by requiring them to key less.

In the display file, define a hidden five-digit zoned decimal field and assign it to the SFLCSRRRN keyword, like this:

A                                      SFLCSRRRN(&S1SLTRRN)
A            S1SLTRRN       5S 0H

The relative record number of the selected record will be returned through the hidden field. If the cursor is not sitting on a subfile record, the hidden field will have a value of zero.

Here is a short display file and an RPG program you can play with to learn about this technique. It builds a small subfile of five records. When you call the program, move the cursor to one of the subfile records or outside of the subfile. When you press Enter, the system will tell you the number of the record you selected and retrieve the data from the record.

* display file SFL333D
A                                      DSPSIZ(24 80 *DS3)   
A                                      INDARA               
A                                      CA03(03 'F3=EXIT')   
A                                      CA12(12 'F12=CANCEL')
A          R S1SFL                     SFL                  
A            S1DATA        40   O  5  2                     
A          R S1CTL                     SFLCTL(S1SFL)        
A                                      SFLSIZ(13)           
A                                      SFLPAG(11)           
A                                      OVERLAY              
A                                      SFLCSRRRN(&S1SLTRRN) 
A  45                                  SFLDSP               
A  44                                  SFLDSPCTL            
A N99                                  SFLEND(*MORE)        
A            S1SFLRRN       4S 0H                           
A            S1SLTRRN       5S 0H                           
A                                  2  2'Selected record:'   
A            CTLRCD         3  0O  2 19EDTCDE(1)            
A                                  2 25'Data:'                    
A            CTLDATA       40   O  2 31                           
A                                  4  2'Move cursor, press Enter.'
A                                      DSPATR(UL)                 
A          R S1LEGEND                                             
A                                 17  2'F3=Exit   F12=Cancel'     

 * RPG program SFL333R
H option(*srcstmt: *nodebugio)                             
H dftactgrp(*no) actgrp(*new)                              
                                                           
Fsfl333d   cf   e             workstn                      
F                                     indds(wsIndicators)  
F                                     sfile(s1SFL:s1SFLRRN)
                                                           
D CancelRequestd  s               n                        
                                                           
 * Indicator data structure for display file               
D wsIndicators    DS            99                         
D  wsExit                 3      3N                        
D  wsCancel              12     12N                        
D  s1SflDspCtl           44     44N                        
D  s1SflDsp              45     45N                        
D  msgSFLEnd             99     99n   inz('0')             
                                                           
 * load the subfile                                        
C                   exsr      s1LoadSFL         
                                                
 * until user cancels                           
C                   dou       CancelRequestd    
 * display the subfile                          
C                   write     s1Legend          
C                   exfmt     s1Ctl             
C                   if        wsCancel or wsExit
C                   eval      CancelRequestd = *on
C                   iter                        
C                   endif                       
 * select the record the cursor is sitting on   
C                   eval      ctlRcd = s1SltRRN 
C                   if        s1SltRRN > *zero  
C     s1SltRRN      chain     s1SFL             
C                   eval      ctlData = s1Data  
C                   else                        
C                   eval      ctlData = '*NONE*'
C                   endif                                    
C                   enddo                                    
C                                                            
C                   eval      *inlr = *on                    
 * ==========================================================
C     s1LoadSFL     begsr                                    
C                                                            
C                   eval      s1Data = 'The first record.'   
C                   eval      s1SFLRRN = 1                   
C                   write     s1SFL                          
C                   eval      s1Data = 'Another record.'     
C                   eval      s1SFLRRN = 2                   
C                   write     s1SFL                          
C                   eval      s1Data = 'Yet another record.' 
C                   eval      s1SFLRRN = 3                   
C                   write     s1SFL                          
C                   eval      s1Data = 'Record 4.'           
C                   eval      s1SFLRRN = 4                   
C                   write     s1SFL                       
C                   eval      s1Data = 'The last record.' 
C                   eval      s1SFLRRN = 5                
C                   write     s1SFL                       
C                                                         
C                   eval      s1SflDspCtl = *on           
C                   eval      s1SflDsp = *on              
C                                                         
C                   endsr                                 

--Ted


This article has been corrected since its was first published. The line of code that read:

           C   eval  CancelRequestd = *
           

Has been replaced with the following line:

           C   eval  CancelRequestd = *on
          

Guild Companies regrets the error. [Correction made 4/11/03.]

Sponsored By
ADVANCED SYSTEMS CONCEPTS

TOP TEN REASONS

Why You Should
Retire Query/400

Yes, there is a much better way!

Learn how you can access and present
AS/400 and iSeries
database information
without jumping through hoops.

Read More


THIS ISSUE
SPONSORED BY:

Advanced Systems Concepts
DRV Technologies


BACK ISSUES

TABLE OF
CONTENTS

Select Subfile Records by Position

Retrieve Java Source

Reader Feedback and Insights: More Advantages of Surrogate Keys


Editors
Howard Arner
Joe Hertvik
Ted Holt
David Morris

Managing Editor
Shannon Pastore

Publisher and
Advertising Director:

Jenny Thomas

Advertising Sales Representative
Kim Reed

Contact the Editors
Do you have a gripe, inside dope or an opinion?
Email the editors:
editors@itjungle.com

Copyright © 1996-2008 Guild Companies, Inc. All Rights Reserved.