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

Trap that disconnection error

Add a subroutine to automatically clean up disconnection errors in interactive programs.

John Kohan

One thing I've noticed over the years is often interactive programs don't trap for disconnection errors. When any type of maintenance is being done on a file, it's crucial to perform proper clean up. This issue can arise from a user simply terminating his telnet session. If SQL commitment control isn't being used, it can be time-consuming to verify files and potentially have to clean them up.

If you're developing a Radio Frequency (RF) application, the possibility of loosing connection with the device during the program cycle is greater than when you are dealing with a normal workstation. If the program you're writing has multiple communications with the user, it may be necessary to properly "cleanup" the process if its connection with the user is lost.

A simple solution is to add an indicator on the EXFMT in the LO column. Immediately after the EXFMT, check for that indicator to be *ON and execute a subroutine. That subroutine should be written to do any necessary clean up and shut down the program clean. And if necessary, send a message to the appropriate person, depending on the level of the program's importance.


C                     EXFMTCONTROL                88 
C     *IN88     CASEQ'1'                     $S900           

C** $S900 - Screen Error Cleanup                                 
C           $S900     BEGSR                                      
C**Add any processing you wish here
C                     CALL 'XXXXXXXX'               Physical Disconnect
C                     EXSR $S001                      Exit       
C                     ENDSR                                      

About the author: John Kohan is a senior programmer analyst at CT Codeworks.


  • Top 10 programmer tips We let your votes do the talking as we selected the top tips for January and February. These tips were selected based on your ratings as of March 6. Check them out and see if you agree with how they were rated.
  • The Best Web Links on Development: Tips, tutorials and more.
  • Ask your programmer questions -- or help out your peers by answering them -- in our live discussion forums.

Dig Deeper on iSeries CL programming

Start the conversation

Send me notifications when other members comment.

Please create a username to comment.