troubleshooting Question

RPG - get the most recent record and write to a file

Avatar of bggauth
bggauthFlag for United States of America asked on
IBM System i
20 Comments3 Solutions914 ViewsLast Modified:
I'm new to RPG so I have no clue how to go about doing this but I’m sure it will be easy for most.
I need to read a file, keying on the user name. Once the first record is read with each user name, I need the program to write that record to a file.   Now if you simply display the file, the entry with the oldest date appears first. However if you DBU the file or RUNQRY *N and select a specific user to key on, the output is sorted by the most recent date/time or the date/time is in descending order.
So when the program runs, hopefully the first record of each user would show the most recent date of access.

Sample Output from DBU:
USER       SYSTEM      DATETIME                   SERVERID    REASON
BARRY      MYSYSTEM   2010-03-23-  *SQL          1    
BARRY      MYSYSTEM   2010-03-23-  *SQL          1    
BARRY      MYSYSTEM   2010-01-22-  *SQL          1    
BARRY      MYSYSTEM   2009-08-31-  *SQL          1    

Source file:
A          R ODBC                                              
A            USER          10A         TEXT('USER PROFILE')    
A            SYSTEM         8A         TEXT('#SYSNAME')        
A            DATETIME        Z         TEXT('LOGIN DATE/TIME')  
A            SERVERID      10A         TEXT('SERVER IDENTIFIER')
A            REASON         1A                                  
A          K DATETIME                  DESCEND                  

The logical:
A          R ODBC                      PFILE(*LIBL/ODBCLOG)
A          K USER                                          
A          K DATETIME                  DESCEND              

Any help would be greatly appreciated.


Our community of experts have been thoroughly vetted for their expertise and industry experience.

Join our community to see this answer!
Unlock 3 Answers and 20 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 3 Answers and 20 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros