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!
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.
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 😉
// 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…
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 codeView this code snippet in modern **FREE RPG
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.
Upload a SAVF using IFS and IBM i Access Client Solutions (no FTP)
Using RPGLE to extract invoice numbers from an alpha string
GETSPLF and PUTSPLF – read and write spools to physical files including all Advanced Function Printing Data Stream (AFPDS)
Modernize RPG code for ‘Get the System Name’ for IBM i, iSeries and AS400
How do we Check for Batch or Interactive in CLLE
Developerworks Connections Sunset – How to Extend RDi
Why use IBM i RDi?
How to Install IBM Access Client Solutions (ACS)
IBM i Data Obfuscation – Making Data Foggy Murky and Squinty