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

You were signed on for how long?

Use this easy, versatile program to find out how long users are signed on.

Recently several people have asked how they can find out how long a user was signed on. There are a couple ways...

that I've done this, but the following example, although it was done a long time ago and for a specialized purpose, may be of interest to some you because it's easy, it's versatile in that it will run on CISC boxes running V3R2 to RISC boxes running V5R1, and it requires no special setup.

First a little background about the program. This program was originally developed for programmers by programmers as a quick and easy tool to see who would hold the unofficial bragging rights for being the most dedicated, productive, etc. It does this by using QHST to get the user's first signon of the day and then the last signoff of the day and then calculating the number of minutes in between.

It then writes this information to a file that can be queried later on. It does that by assuming that interactive device names will start with /DSP or /QPADEV. And since this was for programmers, it also assumes that no ending time will go beyond midnight of the same day in which it started. If what you're looking for needs more fine tuning than that, I suggest that you enable security auditing and generate your reports from that information. But for many applications, these are doable restrictions. This program could also be done in less code and the time calculations can be greatly improved by using RPGIV, but I left this example in RPG III so that the widest possible audience can take advantage of it. This consists of one CL program, two files and one RPG program. To run this, pass the 6 character beginning and end dates in MDY format as parameters to pgm called TIMCL.

Program TIMCL

PGM        PARM(&BDTT &EDTT)                          
                                                      
DCL        VAR(&BDTT) TYPE(*CHAR) LEN(6) /* MDY */    
DCL        VAR(&EDTT) TYPE(*CHAR) LEN(6) /* MDY */    
                                                      
OVRPRTF    FILE(QPDSPLOG) HOLD(*YES)                  
DSPLOG     PERIOD((*AVAIL &BDTT) (*AVAIL &EDTT)) +    
             OUTPUT(*PRINT) MSGID(CPF1124 CPF1164)    
CPYSPLF    FILE(QPDSPLOG) TOFILE(TIMLOG) SPLNBR(*LAST)
DLTSPLF    FILE(QPDSPLOG) SPLNBR(*LAST)               
DLTOVR     FILE(*ALL)                                 
                                                      
CALL       PGM(TIMRPG)                                
                                                      
ENDPGM

File TIMFIL -- Time file by user 

R TIMEFM                                           
  TIMUSR        10          COLHDG('USER')         
  TIMDTT         6S 0       COLHDG('DATE')         
  TIMBTM         6S 0       COLHDG('BEGIN TIME')   
  TIMETM         6S 0       COLHDG('END TIME')     
  TIMTMN         6S 0       COLHDG('TOTAL MINUTES')
K TIMUSR                                           
K TIMDTT

File TIMLOG -- Time log -- Temporary file

R LOGFM                                          
  LOGMSG         7A         COLHDG('MSG NUMBER') 
  LOGTXT       125          COLHDG('TEXT')

Program  - TIMRPG -- Calculate time from QHST logs
FTIMLOG  IF  E                    DISK                        
FTIMFIL  UF  E           K        DISK                      A 
I            DS                                               
I                                       16  25 DSPID          
I                                       27  36 USER           
I                                       38  43 JOBNBR         
I                                       63  64 MM             
I                                       66  67 DD             
I                                       69  70 YY             
I                                       72  73 HH             
I                                       75  76 MN             
I                                       78  79 SS             
I                                        1 125 TIMTXX         
I            DS                                               
I                                        1   20YEAR           
I                                        3   40MONTH          
I                                        5   60DAY            
I                                        1   60DATE           
I            DS                                               
I                                        1   20HOUR
I                                        3   40MINUTE          
I                                        5   60SECOND          
I                                        1   60TIME            
C           TIMKY     KLIST                                    
C                     KFLD           USER                      
C                     KFLD           DATE                      
C           *LIKE     DEFN LOGMSG    HLDMSG                    
C*                                                             
C           *IN51     DOUEQ*ON                                 
C                     READ TIMLOG                   51         
C*                                                             
C           *IN51     IFEQ *OFF                                 
C           LOGMSG    IFEQ 'CPF1124'                           
C           LOGMSG    OREQ 'CPF1164'                           
C                     MOVELLOGMSG    HLDMSG                    
C                     MOVEL*BLANKS   ARGUMN                    
C                     MOVEL'/DSP'    ARGUMN 10        PATTERN  
C                     Z-ADD4         PATLEN  30                
C                     EXSR SCNVAR                              
C           RESULT    IFEQ 0                                   
C                     MOVEL*BLANKS   ARGUMN
C                     MOVEL'/QPADEV' ARGUMN 10        PATTERN      
C                     Z-ADD7         PATLEN  30                    
C                     EXSR SCNVAR                                  
C                     END                                          
C           RESULT    IFGT 0                                       
C                     EXSR WRTUPD                                  
C                     END                                          
C*                                                                 
C                     END                                          
C                     END                                          
C                     END                                          
C*                                                                 
C                     SETON                     LR                 
C***************************************************************** 
C*  SCNVAR - SCAN A VARIABLE ROUTINE                               
C***************************************************************** 
C*                                                                 
C           SCNVAR    BEGSR                                        
C* Initialize                                                      
C                     MOVELLOGTXT    SRCDTA125        PATTERN      
C                     Z-ADD125       STRLEN  30       String len
C                     Z-ADD1         STRPOS  30       Start pos    
C                     MOVE '0'       TRANS   1        No translate 
C                     MOVE '1'       TRIM    1        Trim pattrn  
C* Normal processing including call to QCLSCAN                     
C                     CALL 'QCLSCAN'                  QCLSCAN      
C                     PARM           SRCDTA           String       
C                     PARM           STRLEN           String len   
C                     PARM           STRPOS           Start pos    
C                     PARM           ARGUMN           Pattern      
C                     PARM           PATLEN           Pattern len  
C                     PARM           TRANS            Translate    
C                     PARM           TRIM             Trim         
C                     PARM           WILD    1        Wild char    
C                     PARM           RESULT  30       Result       
C                     ENDSR                                        
C*                                                                 
C***************************************************************** 
C*  WRTUPD - WRITE/UPDATE                                          
C***************************************************************** 
C*                                                                 
C           WRTUPD    BEGSR
C*                                                           
C                     READ TIMLOG                   51       
C                     MOVELLOGTXT    TIMTXX                  
C*                                                           
C                     MOVELYY        YEAR                    
C                     MOVELMM        MONTH                   
C                     MOVELDD        DAY                     
C                     MOVELHH        HOUR                    
C                     MOVELMN        MINUTE                  
C                     MOVELSS        SECOND                  
C*                                                           
C           TIMKY     CHAINTIMFIL               52           
C           *IN52     IFEQ *OFF                               
C* BEGINNING                                                 
C           HLDMSG    IFEQ 'CPF1124'                         
C           TIMBTM    ANDEQ0                                 
C                     MOVELTIME      TIMBTM                  
C                     UPDATTIMEFM                            
C                     END                                    
C* COMPLETION                                                
C           HLDMSG    IFEQ 'CPF1164'                         
C           TIME      ANDGTTIMETM               
C                     MOVELTIMBTM    HLD4    4  
C                     MOVELHLD4      HLDHR   20 
C                     MOVE HLD4      HLDMN   20 
C           HLDHR     MULT 60        CLCBTM  60 
C                     ADD  HLDMN     CLCBTM     
C           HOUR      MULT 60        CLCETM  60 
C                     ADD  MINUTE    CLCETM     
C           CLCETM    SUB  CLCBTM    TIMTMN     
C                     MOVELTIME      TIMETM     
C                     UPDATTIMEFM               
C                     END                       
C*                                              
C                     ELSE                      
C*                                              
C                     CLEARTIMEFM               
C                     MOVELUSER      TIMUSR     
C           HLDMSG    IFEQ 'CPF1124'            
C                     MOVELTIME      TIMBTM     
C                     ELSE                      
C                     MOVELTIMBTM    HLD4
C                     MOVELHLD4      HLDHR   20    
C                     MOVE HLD4      HLDMN   20    
C           HLDHR     MULT 60        CLCBTM  60    
C                     ADD  HLDMN     CLCBTM        
C           HOUR      MULT 60        CLCETM  60    
C                     ADD  MINUTE    CLCETM        
C           CLCETM    SUB  CLCBTM    TIMTMN        
C                     MOVELTIME      TIMETM        
C                     END                          
C                     MOVELDATE      TIMDTT        
C*                                                 
C                     WRITETIMEFM                  
C*                                                 
C                     END                          
C                     ENDSR

---------------------------
About the author: Tim is vice president of Technical Services at Interlink Technologies in Maumee, Ohio, where he serves as chief architect for their warehouse management system. He has worked in the banking, insurance, healthcare and distribution industries in various positions, including programmer/analyst, systems analyst and DP manager. Tim has worked on IBM midrange platforms since 1983.

==================================
MORE INFORMATION
==================================

This was last published in December 2001

Start the conversation

Send me notifications when other members comment.

By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy

Please create a username to comment.

-ADS BY GOOGLE

SearchEnterpriseLinux

SearchDataCenter

Close