August 1

0 comments

Get the IBM i System Name using RPGLE or SQLRPGLE

By NickLitten

August 1, 2017

RPG, API, name, SQL, system

Find the IBM i System Name Three Ways

Let’s look at three techniques to find the IBM i System Name

  • A super easy technique using SQL in an SQLRPGLE Program
  • Just as easy in a CLLE prograam
  • Calling the IBM i *API to get the information, an RPGLE program

Let’s dive straight in:

(1) Get Sysname using SQL

The IBM i System Name is not the same thing as the SQL Local DB Server name, although it may be the same by default.

You can retrieve the SQL Local DB Server name using this SQLRPGLE code snippet:

exec sql values current server into :systemName;

If systemName = 'my-ibm-i-system-name';
 // do some stuff...
endif;

(2) Get Sysname using CL

The good old tried and tested technique is to write a simple Control Language Program that looks something like this:

dcl &SysName *char
rtvneta sysname( &SysName )

the main drawback with this simple method is that you have another program out there to be called by any/all programs that want to find the system name.

(3) Get Sysname using IBM API

Most RPG programmers would probably choose to call the IBM *API to Retrieve Network Attributes (QWCRNETA). This has the same affect as calling a CL to retrieve the network attributes, but of course you could also call the *API from the CLP program if you wanted to be uber-tricky 😉

Rpg code snippet ibm i system name using rpgle
// Prototype for the Rtvsysname function D RtvSysName PR 8A // Variable that will hold the system name D MYSYSTEM S 8A // simply add this line of code to get the system name C eval MYSYSTEM = RtvSysName() C eval *inlr = *on // Retrieve System Name Subprocedure P RtvSysName B Export D RtvSysName PI 8A D QWCRNETA PR ExtPgm('QWCRNETA') D RcvVar 32766A OPTIONS(*VARSIZE) D RcvVarLen 10I 0 const D NbrNetAtr 10I 0 const D AttrNames 10A const D ErrorCode 256A // Error code structure D apiError DS 256 // Receiver variable for QWCRNETA D apiData ds D Filler 32A D RtnSystem 8A // Call the *API and return the system name C callp QWCRNETA (apiData : C %size(apiData) : C 1 : C 'SYSNAME' : C apiError ) C return RtnSystem P E

and there you have it…

SMELLY OLD RPG ALERT!!!!

As you can see this little RPG code snippet is written in the old fashioned RPG400 flavour of RPGLE.

Old stuff is never as good as new stuff – unless it’s Whisky, Red Wine or last nights curry.

If you are a more progressive propeller head then lets see what this code would look like if I run it the UPGRPGSRC command to upgrade it to RPGLE/Free. So check out the Modernized version of this same program – in **FREE RPG code

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

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

>