Warning: Declaration of TCB_Menu_Walker::walk($elements, $max_depth) should be compatible with Walker::walk($elements, $max_depth, ...$args) in /home/nicklit/www/www/wp-content/plugins/thrive-visual-editor/inc/classes/class-tcb-menu-walker.php on line 620

Warning: session_start(): Cannot start session when headers already sent in /home/nicklit/www/www/wp-content/plugins/userpro/includes/class-userpro.php on line 222
Get the IBM i System Name using RPGLE or SQLRPGLE - Nick Litten is IBM-i, AS400 iSeries RPG Programmer and Nerd

Get the IBM i System Name using RPGLE or SQLRPGLE

IBM i

Aug 01

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;

* updated with code Correction from Steve Croy. Thanks!

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.

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…

STOP - 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 UPGSRCMBR command to upgrade it to RPGLE/Free. So check out the Modernized version of this same program – in **FREE RPG code

View this code snippet in modern **FREE RPG
Follow

About the Author

IBM i Software Developer, Digital Dad, AS400 Anarchist, RPG Modernizer, Alpha Nerd and Passionate Eater of Cheese and Biscuits. Nick Litten Dot Com is a mixture of blog posts that can be sometimes serious, frequently playful and probably down-right pointless all in the space of a day. Enjoy your stay, feel free to comment and in the words of the most interesting man in the world: Stay thirsty my friend.