A CL program (or module) can retrieve the system name this way:
dcl &SysName *char 10
rtvneta sysname( &SysName )
In HLLs such as RPG, the Retrieve Network Attributes (QWCRNETA) API can retrieve the same info. (The API can also be called in CL, but the RTVNETA command is easier.)
You need to be aware that the “system name” is not the same as the system’s host name. To retrieve the host name, use the gethostname() — Retrieve Host Name — API like you would on any system that runs TCP/IP.
Also be aware that a system name isn’t required to be unique. Some other identifier might be better in some cases. System serial number is an example.