• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1642
  • Last Modified:

Retrieve iSeries Host Name

I have a CL that I am using to monitor system messages and I want to be able to alert our helpdesk with the server name of the issue. Originally I was pulling the System Name value from RTVNETA, but can't do this because we have production and HA failover servers with the same 'system name'.  I want to use the TCP Host Name (configured in the CHGTCPDMN command.

Does anyone know of a way to pull that information within a CL?

I appreciate any help.
Matthew Roessner
Matthew Roessner
3 Solutions
Gary PattersonVP Technology / Senior Consultant Commented:
Use the gethostname() API to get the TCP hostname:


- Gary Patterson

Matthew RoessnerSenior Systems ProgrammerAuthor Commented:
Do you have any examples of how to use this successfully in a CL program? I had previously found this API, but have been unable to get it working. I am sure it is a result of my lack of knowledge regarding APIs...

Thank you again for the help
Jon SnydermanCommented:
With CL, you can simply use QSYS/RTVNETA SYSNAME('&VARIABLE').

Cloud Class® Course: SQL Server Core 2016

This course will introduce you to SQL Server Core 2016, as well as teach you about SSMS, data tools, installation, server configuration, using Management Studio, and writing and executing queries.

Matthew RoessnerSenior Systems ProgrammerAuthor Commented:
I actually found and used a different API. My code is below for anyone who wants to check it out:


/*DECLARE VARIABLES */                                      
         DCL  &name           *CHAR     (10)                
         DCL  &RcvVar         *CHAR     750                
             DCL        VAR(&APIERR) TYPE(*CHAR) LEN(8) +  
             DCL        VAR(&FORMAT) TYPE(*CHAR) LEN(8) +  
         dcl  &RcvVarLen      *CHAR     4                  
     chgvar %Bin(&RcvVarLen) 750                            
     callprc 'QtocRtvTCPA' ( +                              
                            &RcvVar    +                    
                            &RcvVarLen +                    
                            &Format    +                      
    chgvar &name %SST(&rcvvar 177 10)                          
              SNDMSG     MSG('Server Name: ' *BCAT &name) +    
Jon SnydermanCommented:
Glad it worked, but Wow!  Wouldnt the one liner that I listed be a lot cleaner with lower CPU cycles?

Matthew RoessnerSenior Systems ProgrammerAuthor Commented:
The RVTNETA doesn't return the same value as the API I used. We set our 'system name' in the network attributes to be the same as our serial number. We set our TCP name up as the same as our DNS name.  I wanted to retrieve the TCP system name, not the network attribute system name. They are 2 separate things...
Jon SnydermanCommented:
My bad.  Sorry guys.  (back peddling now)  I thought you were looking for the sysname.  Not the TCP host name.

To use gethostname(), code something like this:
   dcl   &hostname    *char  257
   dcl   &size        *int           value( 256 )

   callprc     'gethostname'  ( &hostname (&size *byval) )
   callprc     'strlen'       ( &hostname ) rtnval( &size )

   sndpgmmsg   msg( 'Host name is' *bcat %sst(&hostname 1 &size) )


Open in new window

Compile that example as a *MODULE. Use CRTPGM to bind it as a *pgm while referencing BNDDIR( QC2LE ). The gethostname() API is always available to everything, but strlen() needs to look in the ILE C functions through QC2LE. I can never remember which service program supplies strlen() and related functions, but QC2LE always finds them.

Matthew RoessnerSenior Systems ProgrammerAuthor Commented:
Found a different API to use that worked. Thanks guys
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: MCSA MCSE Windows Server 2012

This course teaches how to install and configure Windows Server 2012 R2.  It is the first step on your path to becoming a Microsoft Certified Solutions Expert (MCSE).

Tackle projects and never again get stuck behind a technical roadblock.
Join Now