• The Four Hundred
  • Subscribe
  • Media Kit
  • Contributors
  • About Us
  • Contact
Menu
  • The Four Hundred
  • Subscribe
  • Media Kit
  • Contributors
  • About Us
  • Contact
  • Interpreting Stream File Timestamps

    May 14, 2014 Ted Holt

    Fortunately, IBM i has an Integrated File System (IFS), into which you can store any kind of data your heart desires. Fortunately, IBM provides an API that your programs can use to retrieve information about IFS stream files. Unfortunately, this API is rooted in the Unix world. Unfortunately, timestamps are stored in what I would call a bizarre manner. Fortunately, you are intelligent enough to learn how this API works.

    When you need to know programmatically about a stream file, you can use the stat API. Like many things UNIX, stat is idiosyncratic, especially in the way that it reports the last time a file was accessed, the last time the contents were changed, and the last time the status changed. These times are reported in epoch time.

    Epoch time is the number of seconds that have elapsed since January 1, 1970, UTC, not counting leap seconds. Since epoch time is represented as a four-byte signed integer, the range of permissible dates is December 13, 1901, through January 19, 2038.

    The following example of excellence in programming illustrates the process you must go through to find out when a file was last accessed or changed.

    H dftactgrp(*no) actgrp(*new)
    H option(*srcstmt: *nodebugio) bnddir('QC2LE')
    
    D g_UTC_Offset    s             10i 0
    
    D StmfInfo        ds                  qualified inz
    D   Mode                        10u 0
    D   ID                          10u 0
    D                                5u 0
    D                                5u 0
    D   UserID                      10u 0
    D   GroupID                     10u 0
    D   Size                        10i 0
    D   AccessTime                  10i 0
    D   ContentChangeTime...
    D                               10i 0
    D   StatusChangeTime...
    D                               10i 0
    D                               10u 0
    D   BlockSize                   10u 0
    D   AllocationSize...
    D                               10u 0
    D   ObjectType                  11a
    D                                1a
    D   CodePage                     5u 0
    D   CCSID                        5u 0
    D   DeivceID                    10u 0
    D   NumberOfLinks...
    D                               10u 0
    D   DeviceID                    20u 0
    D   FileSystemID                20u 0
    D                               36a
    D   Generation_ID...
    D                               10u 0
    
    D stat            pr            10i 0 extproc('stat')
    D   path                          *   value options(*string)
    D   buffer                            likeds(StmfInfo)
    
    D StmfName        s            256a   varying
    D FileStatus      s             10i 0
    
    D AccessTime      s               z
    D ContentChangeTime...
    D                 s               z
    D StatusChangeTime...
    D                 s               z
    
     /free
         *inlr = *on;
         Get_UTC_Offset ();
         //    UTC_Offset = -18,000 seconds
    
         StmfName = 'cdcatalog.xml';
         FileStatus = stat (StmfName: StmfInfo);
    
         if FileStatus >= *zero;
            AccessTime        = ToTime (StmfInfo.AccessTime);
            ContentChangeTime = ToTime (StmfInfo.ContentChangeTime);
            StatusChangeTime  = ToTime (StmfInfo.StatusChangeTime);
         endif;
    
         return;
     /end-free
     * ==============================================================
    P Get_UTC_Offset  b
    D                 pi
    
    D CEEUTCO         pr                  extproc('CEEUTCO')
    D   Hours                       10i 0
    D   Minutes                     10i 0
    D   Seconds                      8f
    D   FC                          12a   options(*omit)
    
    D UTC_Hours       s             10i 0
    D UTC_Minutes     s             10i 0
    D UTC_Seconds     s              8f
    
     /free
         CEEUTCO (UTC_Hours: UTC_Minutes: UTC_Seconds: *omit);
         g_UTC_Offset = %int(UTC_Seconds);
     /end-free
    P                 e
     * ===============================================================
    P ToTime          b
    D                 pi              z
    D  inSeconds                    10i 0 value
     *** locals
    D Epoch           s               z   inz(z'1970-01-01-00.00.00')
     /free
         return Epoch + %seconds(inSeconds) + %seconds(g_UTC_Offset);
    /end-free
    P                 e
    

    The program first calls the Get Offset from Universal Time Coordinated to Local Time (CEEUTCO) API to determine the system offset to UTC in seconds.

    D g_UTC_Offset    s             10i 0
    
    P Get_UTC_Offset  b
    D                 pi
    
    D CEEUTCO         pr                  extproc('CEEUTCO')
    D   Hours                       10i 0
    D   Minutes                     10i 0
    D   Seconds                      8f
    D   FC                          12a   options(*omit)
    
    D UTC_Hours       s             10i 0
    D UTC_Minutes     s             10i 0
    D UTC_Seconds     s              8f
    
     /free
         CEEUTCO (UTC_Hours: UTC_Minutes: UTC_Seconds: *omit);
         g_UTC_Offset = %int(UTC_Seconds);
     /end-free
    P                 e
    

    CEEUTCO loads three parameters:

    • The number of hours of offset.
    • The number of additional minutes of offset.
    • The total number of seconds offset.

    I ignore a fourth, omissible parameter. I also ignore the first two parameters. I only use the third one. Since my shop is in the Central Time Zone, which is five hours behind UTC, CEEUTCO loads -18000 into the third parameter. The program copies this value into global variable g_UTC_Offset. As a rule I avoid global variables, but global variables are good for unchangeable values such as this one.

    Next the program runs the stat API to retrieve information about a stream file.

    D StmfInfo        ds                  qualified inz
    D   Mode                        10u 0
    D   ID                          10u 0
    D                                5u 0
    D                                5u 0
    D   UserID                      10u 0
    D   GroupID                     10u 0
    D   Size                        10i 0
    D   AccessTime                  10i 0
    D   ContentChangeTime...
    D                               10i 0
    D   StatusChangeTime...
    D                               10i 0
    D                               10u 0
    D   BlockSize                   10u 0
    D   AllocationSize...
    D                               10u 0
    D   ObjectType                  11a
    D                                1a
    D   CodePage                     5u 0
    D   CCSID                        5u 0
    D   DeivceID                    10u 0
    D   NumberOfLinks...
    D                               10u 0
    D   DeviceID                    20u 0
    D   FileSystemID                20u 0
    D                               36a
    D   Generation_ID...
    D                               10u 0
    
    D stat            pr            10i 0 extproc('stat')
    D   path                          *   value options(*string)
    D   buffer                            likeds(StmfInfo)
    
    D StmfName        s            256a   varying
    D FileStatus      s             10i 0
    
     /free
         StmfName = 'cdcatalog.xml';
         FileStatus = stat (StmfName: StmfInfo);
    

    Now the program must convert the three timestamps from epoch format to the timestamp data type.

    AccessTime = ToTime (StmfInfo.AccessTime);
    
    P ToTime          b 
    D                 pi              z
    D  inSeconds                    10i 0 value
     *** locals
    D Epoch           s               z   inz(z'1970-01-01-00.00.00')
     /free
         return Epoch + %seconds(inSeconds) + %seconds(g_UTC_Offset);
    /end-free
    P                 e
    

    This table shows the timestamp values for the example file.




    Field

    Epoch time

    Timestamp

    Access
    time

    1397513743

    2014-04-14-17.15.43

    Content
    change time

    1380124596

    2013-09-25-10.56.36

    Status
    change time

    1380125525

    2013-09-25-11.12.05

    It may seem a bit odd to store timestamps this way, but if every little factory in Mississippi had been running Unix machines instead of System/34s in the 1980s, I would undoubtedly be very familiar with epoch time and consider it normal.



                         Post this story to del.icio.us
                   Post this story to Digg
        Post this story to Slashdot

    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:

    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

    Sponsored Links

    Symtrax:  SAP Webinar: Go Paperless with ePayslips for SAP - 13th of May, 4pm EDT
    LANSA:  Webinar: Mobile and the IBM i: Why Should You Care? May 21, 9 am PT/11 am CT/Noon ET
    RJS Software Systems:  Webinar: Learn how WebForms can save time and money. May 27.

    More IT Jungle Resources:

    System i PTF Guide: Weekly PTF Updates
    IBM i Events Calendar: National Conferences, Local Events, and Webinars
    Breaking News: News Hot Off The Press
    TPM @ EnterpriseTech: High Performance Computing Industry News From ITJ EIC Timothy Prickett Morgan

    Using Built-In Global Variables In DB2 For i 7.2 Admin Alert: When Journaling Slows Down Your System, And What To Do About It

    Leave a ReplyCancel reply

Volume 14, Number 11 -- May 14, 2014
THIS ISSUE SPONSORED BY:

ProData Computer Services
PowerTech
WorksRight Software

Table of Contents

  • Using Built-In Global Variables In DB2 For i 7.2
  • Interpreting Stream File Timestamps
  • Admin Alert: When Journaling Slows Down Your System, And What To Do About It

Content archive

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

Recent Posts

  • IBM i PTF Guide, Volume 28, Number 28: A Crazy Number of Security Vulnerability Patches
  • Inside The Encryption Key Management Changes In IBM i 7.6
  • FalconStor Moved To The Blue Lagoon, And Is Poised For Growth Because Of It
  • Guru: Claude’s SQL Tip
  • Astera Makes Extracting Legacy Report Data an AI Specialty
  • IBM i PTF Guide, Volume 28, Number 27
  • Welcoming The New IBM i Chief Architect And Other New Top Brass
  • A Deep Dive Into That Power S1112 Entry Power11 Server
  • Guru: Beyond Three-Part Naming – Running SQL Across Remote IBM i Systems
  • How IBM Bolstered IBM i Resilience In The Summer Tech Refreshes

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