How to retrieve IBMi (iSeries AS400) operating system version in a CLP program

  • Home
  • /
  • Blog
  • /
  • How to retrieve IBMi (iSeries AS400) operating system version in a CLP program

December 16, 2009

How to retrieve IBMi (iSeries AS400) operating system version in a CLP program

By NickLitten

December 16, 2009

CLP, OS, snippet, version

Get the IBM i Operating System Version in IBM i CL

IBMi (iSeries AS400) operating system version

There are lots of way of checking the operating system version on your IBM i Server.

On your command line type DSPSFWRSC and with F11 you will see the Software Version of all the products installed on your iSeries.

You could also use the DSPPTF command to show the current release as well as the current Cumulative PTF Package (SF99540).

Or you could write a little something and using an IBM API the CLP code is very simple

DCL VAR(&VERSION) TYPE(*CHAR) LEN(6) 
DCL VAR(&RCVR) TYPE(*CHAR) LEN(128)  
DCL VAR(&RCVRLEN) TYPE(*CHAR) LEN(4) VALUE(X'00000080')  
DCL VAR(&FORMAT) TYPE(*CHAR) LEN(8) VALUE('PRDR0100')  
DCL VAR(&PRDINFO) TYPE(*CHAR) LEN(27) + VALUE('*OPSYS *CUR  0000*CODE     ')  
DCL VAR(&APIERROR) TYPE(*CHAR) LEN(4) VALUE(X'00000000')  

CALL PGM(QSZRTVPR) PARM(&RCVR &RCVRLEN &FORMAT + &PRDINFO &APIERROR)  
CHGVAR VAR(&VERSION) VALUE(%SST(&RCVR 20 6))  
SNDPGMMSG MSG('IBMi Version is' *bcat &VERSION)

For example, on my little AS400e iSeries 270 eServer System i Power System running IBMi5.4 this will return a status message saying: Ā» IBMi Version is V5R4M0

Here is the full version from the IBM Sample Code website:

 PGM
 DCL        VAR(&RCVR) TYPE(*CHAR) LEN(109)
 DCL        VAR(&RCVRLEN) TYPE(*CHAR) LEN(4) VALUE(X'0000006D')
 DCL        VAR(&FORMAT) TYPE(*CHAR) LEN(8) VALUE('PRDR0100')
 DCL        VAR(&SLICPRDINF) TYPE(*CHAR) LEN(27) VALUE('XXXX999*XXXX +
                0000*CODE     ')
 DCL        VAR(&XPFPRDINF) TYPE(*CHAR) LEN(27) VALUE('*OPSYS *CUR  +
                0000*CODE     ')
 DCL        VAR(&ERRCODE) TYPE(*CHAR) LEN(8) VALUE(X'0000000000000000')
 DCL        VAR(&SLICVRM) TYPE(*CHAR) LEN(6)
 DCL        VAR(&SLICLVL) TYPE(*CHAR) LEN(3)
 DCL        VAR(&XPFVRM) TYPE(*CHAR) LEN(6)
 DCL        VAR(&XPFLVL) TYPE(*CHAR) LEN(3)
 DCL        VAR(&XPFNAME) TYPE(*CHAR) LEN(6)
 DCL        VAR(&MSGID) TYPE(*CHAR) LEN(7) VALUE('CPF9897')
 DCL        VAR(&MSGF) TYPE(*CHAR) LEN(10) VALUE('QCPFMSG   ')
 DCL        VAR(&MSGFLIB) TYPE(*CHAR) LEN(10) VALUE('*LIBL     ')
 DCL        VAR(&MSGDTA) TYPE(*CHAR) LEN(2000)
 DCL        VAR(&TOMSGQ) TYPE(*CHAR) LEN(10) VALUE('*TOPGMQ   ')
 DCL        VAR(&MSGTYPE) TYPE(*CHAR) LEN(10) VALUE('*INFO     ')

 MONMSG     MSGID(CPC0000 CPD0000 CPF0000 MCH0000) EXEC(GOTO CMDLBL(ERROR))

/* Retrieve IBM OS/400, IBM i5/OS or IBM i (XPF) Release Information */

 CALL       PGM(QSZRTVPR) PARM(&RCVR &RCVRLEN &FORMAT &XPFPRDINF &ERRCODE)

 CHGVAR     VAR(&XPFVRM) VALUE(%SST(&RCVR 20 6))
 CHGVAR     VAR(&XPFLVL) VALUE(%SST(&RCVR 106 3))
 CHGVAR     VAR(%SST(&SLICPRDINF 1 4)) VALUE(%SST(&RCVR 13 4))

 IF         COND(&XPFVRM < 'V3R6') THEN(CHGVAR VAR(%SST(&SLICPRDINF 8 6)) +
                VALUE('*CUR  '))
 ELSE       CMD(CHGVAR VAR(%SST(&SLICPRDINF 8 6)) VALUE('*ONLY '))

 IF         COND(&XPFVRM < 'V5R3M0') THEN(CHGVAR VAR(&XPFNAME) VALUE('OS/400'))
 ELSE       CMD(IF COND(&XPFVRM >= 'V5R3M0' & &XPFVRM < 'V6R1M0') +
                THEN(CHGVAR VAR(&XPFNAME) VALUE('i5/OS ')))
 ELSE       CMD(CHGVAR VAR(&XPFNAME) VALUE('i     '))

/* Retrieve IBM System Licensed Internal Code (SLIC) Release Information */
 CALL       PGM(QSZRTVPR) PARM(&RCVR &RCVRLEN &FORMAT &SLICPRDINF &ERRCODE)

 CHGVAR     VAR(&SLICVRM) VALUE(%SST(&RCVR 20 6))
 CHGVAR     VAR(&SLICLVL) VALUE(%SST(&RCVR 106 3))

/* Write the information on line 24 of the workstation */
 IF         COND(&XPFVRM < 'V4R2M0') THEN(CHGVAR VAR(&MSGDTA) VALUE('IBM +
                System Licensed Internal Code: ' *CAT &SLICVRM *CAT ' | ' +
                *CAT 'IBM ' *CAT &XPFNAME *TCAT ': ' *CAT &XPFVRM *CAT '.'))
 ELSE       CMD(CHGVAR VAR(&MSGDTA) VALUE('IBM System Licensed Internal +
                Code: ' *CAT &SLICVRM *CAT '-' *CAT &SLICLVL *CAT ' | ' +
                *CAT 'IBM ' *CAT &XPFNAME *TCAT ': ' *CAT &XPFVRM *CAT '-' +
                *CAT &XPFLVL *CAT '.'))

 GOTO       CMDLBL(END)

 ERROR:
 RCVMSG     RMV(*YES) MSGDTA(&MSGDTA) MSGID(&MSGID) MSGF(&MSGF) +
                MSGFLIB(&MSGFLIB)
 CHGVAR     VAR(&MSGTYPE) VALUE('*ESCAPE   ')
 END:
 SNDPGMMSG  MSGID(&MSGID) MSGF(&MSGFLIB/&MSGF) MSGDTA(&MSGDTA) +
                TOMSGQ(&TOMSGQ) MSGTYPE(&MSGTYPE)
 ENDPGM 

UPDATE – May 2022 – Want to see the same code in RPGLE? Well, almost the same, I have not coded the handling for archaic version of IBM i we are on V7.4 so really don’t care about the decade old versions like < IBM i V5.. anyway… waffling aside you can look at:

  • Hi Nick – I needed a bit of CL to retrieve the OS level, but unfortunately your snippet has some issues. Your code doesn’t compile (you go from using &version to &release, and the definitions should be *CHAR not CHAR). Once I’d fixed those and got it to compile it failed with run-time errors. In the end I gave up and used this:
    https://www.ibm.com/support/pages/sample-cl-program-uses-retrieve-product-information-qszrtvpr-api

    Cheers
    Paul

    • Thank s Paul, it looks like the ‘*’ was lost when I copied and pasted that code back in 2009. Glad you found an alternative code snippet.

      I think I will update this little post and add a tweaked version of that IBM code example. Thanks!

    • Thanks Paul, it looks like the ‘*’ was lost when I copied and pasted that code back in 2009. Glad you found an alternative code snippet.

      I think I will update this little post and add a tweaked version of that IBM code example. Thanks!

  • Thanks for this. Separately, a ‘host print’ / print screen is a quick & simple way to see the OS version. The OS is on the top of the spooled file – handy if you’re not on the machine and need to get a user to tell you what version they’re on.

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

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

    >