Find the IBMi (iSeries AS400) Operating System Version in a RPGLE program

  • Home
  • /
  • Blog
  • /
  • Find the IBMi (iSeries AS400) Operating System Version in a RPGLE program

May 15, 2022

Find the IBMi (iSeries AS400) Operating System Version in a RPGLE program

By NickLitten

May 15, 2022


Ever wanted to find your IBM i OS Version in RPG?

Following on from this old blog about how to find the OS version from a CL Program (and when I say OLD I mean from back in 2009, when I was still young and crispy.. as opposed to how I am now; old, wrinkled and generally dustier). I decided to quickly convert the same code into RPGLE.

Here is the same code concept (minus all over the old “If the OS is a version from 2004 then do this” bits) written in RPGLE, as a sub-procedure — so you could copy this into a *SRVPGM if you wanted:

// +------------------------------------------------------------------------+
// | rtn_IBMi_Version - RPGLE version of os and Return to calling program   |
// |                   Use QSZRTVPR API to get the current OS release       |
// +------------------------------------------------------------------------+
dcl-proc rtn_IBMi_Version export;
  dcl-pi rtn_IBMi_Version char(10) end-pi;

  dcl-s XPFPRDINF char(27) inz('*OPSYS *CUR  0000*CODE     ');
  dcl-s SLICPRDINF char(27) inz('XXXX999*XXXX 0000*CODE     ');

  dcl-pr RtvPrdInfo extpgm('QSZRTVPR');
    *n char(1) options(*varsize); // RecVar
    *n int(10) const; // RecVarLen
    *n char(8) const; // FormatName
    *n like(XPFPRDINF) const options(*varsize); // ProdInfo
    *n char(32000) options(*varsize); // ErrCode
  end-pr;

  dcl-ds ErrorCode qualified;
    BytesProv int(10) inz(0);
    BytesAvail int(10) inz(0);
  end-ds;

  dcl-s Receiver char(109);

  dcl-s XPFVRM char(6);
  dcl-s XPFLVL char(3);

  dcl-s SLICVRM char(6);
  dcl-s SLICLVL char(3);

  dcl-s rtnvalue char(10);

  // Retrieve IBM OS/400, IBM i5/OS or IBM i (XPF) Release Information
  RtvPrdInfo ( Receiver:
               %len(Receiver):
               'PRDR0100':
               XPFPRDINF:
               ErrorCode);

  XPFVRM = %SUBST(Receiver:20:6);
  XPFLVL = %SUBST(Receiver:106:3);

  %SUBST(SLICPRDINF:1:4) = %SUBST(Receiver:13:4);
  %SUBST(SLICPRDINF:8:6) = '*ONLY ';

  // Retrieve IBM System Licensed Internal Code (SLIC) Release Information
  RtvPrdInfo ( Receiver:
               %len(Receiver):
               'PRDR0100':
               SLICPRDINF:
               ErrorCode);

  SLICVRM = %SUBST(Receiver:20:6);
  SLICLVL = %SUBST(Receiver:106:3);

  RtnValue = SLICVRM + SLICLVL;

  Return RtnValue;

end-proc;

PS: Yes, I know I could have written this in many other ways, but I tried to make this as readable as possible for newbie IBM-i Programmers.

  • If you want the OS Version/Release as a numeric values, such as 730 or 750, etc. you can use the following IBM built-in function to get that info. All the CEExxxx APIs are in-line code so they perform very fast. I use them when navigating code based on which release level the program is running.
    -Cozzi
    dcl-proc getOSVER export;
    dcl-pi getOSVER int(10) end-pi;

    dcl-ds FB_T Qualified Inz TEMPLATE;
    msgsev uns(5);
    msgno uns(5);
    flags char(1);
    Facility_ID char(3);
    Info uns(10);
    end-ds;

    dcl-s osvrm int(10);
    dcl-s platform int(10);
    dcl-ds fb likeDS(FB_T) Inz(*LIKEDS);

    DCL-PR CEEGPID EXTPROC(‘CEEGPID’);
    osRel int(10);
    platform int(10);
    fb likeDS(FB_T);
    END-PR;

    CEEGPID(osvrm : platform : fb);

    return OSVRM;

    end-proc;

  • dcl-s nam varchar(16);
    dcl-s ver varchar(4);
    dcl-s rls varchar(4);
    exec sql
    select os_name, os_version, os_release
    into :nam, :ver, :rls
    from sysibmadm.env_sys_info;
    dsply (nam + ‘:’ + ver + ‘.’ + rls) ‘*EXT’;

  • Other way to know the OS rel. is:
    SELECT substring(DATA_AREA_VALUE, 1, 8) FROM qsys2.data_area_info
    WHERE data_area_library = ‘QUSRSYS’ and data_area_name = ‘QSS1MRI’

  • Legacy non free RPGLE
    D QSS1MRI DS 750
    D Version 1 8
    C *dtaara Define Qss1Mri Qss1mri
    C In qss1mri

    CLLE
    PGM
    DCL VAR(&VER) TYPE(*CHAR) LEN(8)
    RTVDTAARA DTAARA(QSS1MRI (1 8)) RTNVAR(&VER)
    ENDPGM

  • {"email":"Email address invalid","url":"Website address invalid","required":"Required field missing"}

    Join the IBM i Community for FREE Presentations, Lessons, Hints and Tips

    >