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 May 2016 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 ;)