• 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:

    • Reddit
    • Facebook
    • LinkedIn
    • Twitter
    • Email

    Tags:

    Sponsored by
    DRV Tech

    Get More Out of Your IBM i

    With soaring costs, operational data is more critical than ever. IBM shops need faster, easier ways to distribute IBM applications-based data to users more efficiently, no matter where they are.

    The Problem:

    For Users, IBM Data Can Be Difficult to Get To

    IBM Applications generate reports as spooled files, originally designed to be printed. Often those reports are packed together with so much data it makes them difficult to read. Add to that hardcopy is a pain to distribute. User-friendly formats like Excel and PDF are better, offering sorting, searching, and easy portability but getting IBM reports into these formats can be tricky without the right tools.

    The Solution:

    IBM i Reports can easily be converted to easy to read and share formats like Excel and PDF and Delivered by Email

    Converting IBM i, iSeries, and AS400 reports into Excel and PDF is now a lot easier with SpoolFlex software by DRV Tech.  If you or your users are still doing this manually, think how much time is wasted dragging and reformatting to make a report readable. How much time would be saved if they were automatically formatted correctly and delivered to one or multiple recipients.

    SpoolFlex converts spooled files to Excel and PDF, automatically emailing them, and saving copies to network shared folders. SpoolFlex converts complex reports to Excel, removing unwanted headers, splitting large reports out for individual recipients, and delivering to users whether they are at the office or working from home.

    Watch our 2-minute video and see DRV’s powerful SpoolFlex software can solve your file conversion challenges.

    Watch Video

    DRV Tech

    www.drvtech.com

    866.378.3366

    Share this:

    • Reddit
    • Facebook
    • LinkedIn
    • Twitter
    • 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

    Magic Software Still Has The Touch In Q1 IBM Patches Heartbleed Vulnerability in Power Systems Firmware

    Leave a Reply Cancel 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

  • Meet The Next Gen Of IBMers Helping To Build IBM i
  • Looks Like IBM Is Building A Linux-Like PASE For IBM i After All
  • Will Independent IBM i Clouds Survive PowerVS?
  • Now, IBM Is Jacking Up Hardware Maintenance Prices
  • IBM i PTF Guide, Volume 27, Number 24
  • Big Blue Raises IBM i License Transfer Fees, Other Prices
  • Keep The IBM i Youth Movement Going With More Training, Better Tools
  • Remain Begins Migrating DevOps Tools To VS Code
  • IBM Readies LTO-10 Tape Drives And Libraries
  • IBM i PTF Guide, Volume 27, Number 23

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