• The Four Hundred
  • Subscribe
  • Media Kit
  • Contributors
  • About Us
  • Contact
Menu
  • The Four Hundred
  • Subscribe
  • Media Kit
  • Contributors
  • About Us
  • Contact
  • Guru: Analyzing User Session Statistics, Part 1

    July 20, 2026 Mike Larsen

    I wanted to report on user activity on our IBM i. Knowing that there is a wealth of SQL table functions available to me, I knew it wouldn’t be hard to find something that would help me. For this report, I wanted to see how many times a user logged into the system during a certain timeframe.

    The table function I used is QSYS2.HISTORY_LOG_INFO. I’ll show the code I built, followed by a breakdown of what is does.

    Here is the SQL statement to determine the number of times a user signed in:

    SELECT COUNT(DISTINCT DATE(MESSAGE_TIMESTAMP)) AS DAYS_LOGGED_IN
    FROM TABLE(QSYS2.HISTORY_LOG_INFO(
        START_TIME => CURRENT TIMESTAMP - 5 days, 
        END_TIME => CURRENT TIMESTAMP
    )) AS H
    WHERE MESSAGE_ID = 'CPF1124' 
      AND from_job_user = 'USER_ID'; 
    

    Since one can log in and out multiple times in a day, I chose to get a distinct count of the times one logged into the system. To narrow the results, I used a date range for the past five days. You can change the date range to suit your needs. Note that in my where clause, I have two criteria. The first column I used in my SQL statement is MESSAGE_ID. I did this because I know that message id CPF1124 tells me when a job started. The second selection criteria I used is from_job_user. Here, I specified the user ID I would like to see.

    When I run this statement, I get the distinct number of times a user logged in over the past five days:

    It’s worth noting that I can also determine the number of times the user logged out of the system by making a small change to the SQL statement:

    SELECT COUNT(DISTINCT DATE(MESSAGE_TIMESTAMP)) AS DAYS_LOGGED_IN
    FROM TABLE(QSYS2.HISTORY_LOG_INFO(
        START_TIME => CURRENT TIMESTAMP - 5 days, 
        END_TIME => CURRENT TIMESTAMP
    )) AS H
    WHERE MESSAGE_ID = 'CPF1164' 
      AND from_job_user = 'USER_ID'; 
    

    There is one small change to the code, and that is the MESSAGE_ID for which I’m filtering. To see when a job ended, I change this selection criteria to CPF1164. When I run this code, I get the result shown below:

    Using these SQL statements provides useful insight into how many times people are signing into the system. In the second part of this tip, I’ll show how to get the days people signed into the system, and how long their session was active.

    Mike Larsen is a director of information technology at Auburn Pharmaceutical and has been working with IBM i systems for over 20 years. He specializes in RPG, CL, and SQL and recently has been working with PHP and Python. Current projects have given Mike the opportunity to work with generating and parsing XML and JSON from SQL and consuming SOAP and REST web services. Although his main area of expertise is on IBM i, Mike has a passion for learning other languages and how he can integrate other platforms with IBM i.

    RELATED STORIES

    Guru: Playing Sounds From An RPG Program

    Guru: Creating An SQL Stored Procedure That Returns A Result Set

    Guru: Creating An RPG Stored Procedure That Returns A Result Set

    Guru: Creating An RPG Stored Procedure With Parameters

    Guru: Creating A Web Service With Basic Authentication

    Guru: Parsing JSON That Has Spaces In The Key

    Guru: Partitioning Result Sets Using SQL

    Guru: Comparing IFS Directories Using SQL

    Guru: String Manipulation Using SQL

    Guru: Regular Expressions, Part 1

    Guru: Regular Expressions, Part 2

    Guru: Debugging SQL Stored Procedures With ACS

    Guru: Creating PDF Documents With Python

    Guru: Creating Excel Spreadsheets With Python

    Share this:

    • Share on Reddit (Opens in new window) Reddit
    • Share on Facebook (Opens in new window) Facebook
    • Share on LinkedIn (Opens in new window) LinkedIn
    • Share on X (Opens in new window) X
    • Email a link to a friend (Opens in new window) Email

    Tags: Tags: 400guru, FHG, Four Hunded Guru, IBM i, SQL

    Sponsored by
    JAMS Software

    One Scheduler. IBM i, Windows, Linux, and More.

    IBM i teams trust JAMS to schedule and orchestrate jobs across every platform in their environment. Centralized visibility, cross-platform dependency management, and alerts that reach the right person before the business feels it.

    Fewer than 5% of IBM i shops run IBM i only. The rest are managing cross-platform dependencies — often without a clear picture of how they connect. JAMS draws that map, enforces those dependencies automatically, and gives your team a single place to monitor, manage, and recover when something goes wrong.

    If you are running hundreds of CL scripts and custom RPG processes, bring them as-is. JAMS runs them exactly as they do today — except now they are visible, monitored, and part of an orchestrated workflow instead of scattered across folders only one person knows about.

    No consumption-based pricing. No surprise bills when your workload spikes. You pay based on how many machines JAMS talks to — that’s it.

    Learn More → https://jamsscheduler.com/lp/ibm-i

    Share this:

    • Share on Reddit (Opens in new window) Reddit
    • Share on Facebook (Opens in new window) Facebook
    • Share on LinkedIn (Opens in new window) LinkedIn
    • Share on X (Opens in new window) X
    • Email a link to a friend (Opens in new window) Email

    Relion Solutions Launches With A Focus On Customer Service Big Blue Finally Unveils First IBM i Tech Refreshes Of 2026

    One thought on “Guru: Analyzing User Session Statistics, Part 1”

    • Nina Triolo says:
      July 20, 2026 at 8:59 am

      Thanks for sharing this, Mike. I can’t wait to give it a try.

      Reply

    Leave a ReplyCancel reply

TFH Volume: 36 Issue: 24

This Issue Sponsored By

  • JAMS Software
  • Maxava
  • JAMS Software
  • WorksRight Software
  • Computer Keyes
  • Manta Technologies

Table of Contents

  • Guru: Analyzing User Session Statistics, Part 1
  • Big Blue Ships Bob 2.0 And Premium Package For IBM i
  • Your IBM i Jobs Don’t Live On An Island Anymore
  • FalconStor Creates Cloud Clean Room To Prove Backup Recoveries Work
  • Talking Git On IBM i With A Bunch Of IBM i Gits
  • IBM i PTF Guide, Volume 28, Number 22

Content archive

  • The Four Hundred
  • Four Hundred Stuff
  • Four Hundred Guru

Recent Posts

  • The Power11 IBM i P05 Entry Machine Finally Arrives
  • Big Blue Finally Unveils First IBM i Tech Refreshes Of 2026
  • Guru: Analyzing User Session Statistics, Part 1
  • Relion Solutions Launches With A Focus On Customer Service
  • IBM i PTF Guide, Volume 28, Numbers 23 And 24
  • Big Blue Ships Bob 2.0 And Premium Package For IBM i
  • Your IBM i Jobs Don’t Live On An Island Anymore
  • FalconStor Creates Cloud Clean Room To Prove Backup Recoveries Work
  • Talking Git On IBM i With A Bunch Of IBM i Gits
  • IBM i PTF Guide, Volume 28, Number 22

Subscribe

To get news from IT Jungle sent to your inbox every week, subscribe to our newsletter.

Pages

  • About Us
  • Contact
  • Contributors
  • Four Hundred Monitor
  • IBM i PTF Guide
  • Media Kit
  • Subscribe

Search

Copyright © 2025 IT Jungle