Problem solve Get help with specific problems with your technologies, process and projects.

Finding an IP address for the RPG illiterate

Don't understand RPG? Learn an easy way to retrieve the IP address and display it on your command line screen.

You Can View User Feedback To This Tip

Do you have trouble understanding RPG? The following CL program will retrieve the IP address and display it on your command line screen. If you call it with the only parm being the device name, it will return a message telling you the IP address.
  PGM        PARM(&DEVD)                                            
                                                                   
 DCL        VAR(&DEVINFO) TYPE(*CHAR) LEN(999)                     
 DCL        VAR(&LENVAR) TYPE(*DEC) LEN(3 0) VALUE(999)            
 DCL        VAR(&LENVARBIN) TYPE(*CHAR) LEN(4) VALUE(X'00000000')  
 DCL        VAR(&FRMT) TYPE(*CHAR) LEN(8) VALUE('DEVD0600')        
 DCL        VAR(&DEVD) TYPE(*CHAR) LEN(10)                         
 DCL        VAR(&MSG) TYPE(*CHAR) LEN(50)                          
 DCL        VAR(&ERRORCODE) TYPE(*CHAR) LEN(32) +                  
                  VALUE(X'00000000000000000000000000000000000+     
                                 00000000000000000000000000000')   
 DCL        VAR(&IPADDR) TYPE(*CHAR) LEN(15)                       
                                                                   
 CHGVAR %BIN(&LENVARBIN) &LENVAR                                   
                                                                   
 CALL QDCRDEVD  (&DEVINFO +                                        
                 &LENVARBIN +                                      
                 &FRMT +                                           
                 &DEVD +                                           
                              &ERRORCODE)                                   
              MONMSG     MSGID(CPF2702) EXEC(GOTO CMDLBL(NODEV))            
              CHGVAR &IPADDR   %SST(&DEVINFO 877 15)                        
              CHGVAR     VAR(&MSG) VALUE(&devd *BCAT 'is being used +       
                           by' *BCAT &ipaddr)                               
              SNDPGMMSG  MSGID(CPF9898) MSGF(QCPFMSG) MSGDTA(&MSG) +        
                         TOPGMQ(*PRV) MSGTYPE(*ESCAPE)                      
              GOTO       CMDLBL(END)                                        
 NODEV:       SNDMSG     MSG(&DEVD *BCAT 'is not a known device') +         
                         TOUSR(*SYSOPR)                                     
                                                               
 END:                                                          
              ENDPGM    

==================================
MORE INFORMATION ON THIS TOPIC
==================================

The Best Web Links: tips, tutorials and more.

Ask your systems management questions--or help out your peers by answering them--in our live discussion forums.

Ask the Experts yourself: Our systems management gurus are waiting to answer your technical questions.

USER FEEDBACK TO THIS TIP

  • The position of the IP address is off by one. It should be 878 to 892, not 877 to 891. This tip also has another potential problem: What happens if the device exists but is not active? The answer is that the IP address will contain binary zeroes. Extra code could be added to handle this scenario.— Nick Hobson

This was last published in February 2002

Start the conversation

Send me notifications when other members comment.

By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy

Please create a username to comment.

-ADS BY GOOGLE

SearchDataCenter

Close