2011年9月14日 星期三

[ABAP] Connection Keeper for network idle

當閒置時間過長連線中斷

有時是因為系統參數 rdisp/gui_auto_logout 的關係,有時是因為網路設備的關係,當閒置時間超過設定時,就會中斷連線。

如果可以的話,修改系統參數、網路設備設定,是最直接有效的。

如果不行的話,可以參考底下的程式。執行時輸入訊息傳輸的間隔秒數,要少於設定斷線的閒置秒數。



*&---------------------------------------------------------------------*
*& Report  YIDLE
*& Copyright (C) 2011 Song Huang<songhuang.tw@gmail.com>
*&
*& This program is open source; you can redistribute it and/or
*& modify it under the terms of the GPL or Artistic License.
*& These licenses are available at http://www.opensource.org
*&
*& This program must be used and distributed in accordance
*& with the law. The author claims no liability for its
*& misuse.
*&
*& This program is distributed in the hope that it will be useful,
*& but WITHOUT ANY WARRANTY; without even the implied warranty of
*& MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
*&---------------------------------------------------------------------*
*& @Author Song Huang
*& @Date   2011/09/07
*& @Info   Connection Keeper for network idle
*&---------------------------------------------------------------------*
report  yidle.

data: lv_mstxt type string,
      lv_perce type n length 2,
      lv_start type tzntstmpl,
      lv_curre type tzntstmpl,
      lv_tsecs type i,              " Total Secs
      lv_tmins type i,              " Total Mins
      lv_hours type n length 2,
      lv_chour type c length 2,
      lv_mins  type n length 2,
      lv_cmins type c length 2,
      lv_secs  type n length 2.

class cl_abap_tstmp definition load.

selection-screen begin of line.
selection-screen comment (23) sspsecs.
selection-screen position 25.
parameters:
    p_secs type i.
selection-screen end of line.

initialization.
  sspsecs = 'Keeper MSG Per Seconds:'.

start-of-selection.
  clear: lv_perce, lv_mins, lv_start, lv_curre.
  get time stamp field lv_start.
  do.
    get time stamp field lv_curre.
    lv_tsecs = cl_abap_tstmp=>subtract( tstmp1 = lv_curre
                                       tstmp2 = lv_start ).
*   Progress Indicator
    lv_hours = lv_tsecs div 3600.
    lv_mins  = ( lv_tsecs mod 3600 ) div 60.
    lv_secs  = ( lv_tsecs mod 3600 ) mod 60.
    lv_mstxt = 'Connection Keeper Running'.
    if lv_hours > 0.
      concatenate lv_mstxt lv_hours 'Hr' into lv_mstxt
          separated by space.
      if lv_hours > 1.
        concatenate lv_mstxt 's' into lv_mstxt.
      endif.
    endif.
    if lv_mins > 0.
      concatenate lv_mstxt lv_mins 'Min' into lv_mstxt
          separated by space.
      if lv_mins > 1.
        concatenate lv_mstxt 's' into lv_mstxt.
      endif.
    endif.
    if lv_secs > 0.
      concatenate lv_mstxt lv_secs 'Sec' into lv_mstxt
          separated by space.
      if lv_secs > 1.
        concatenate lv_mstxt 's' into lv_mstxt.
      endif.
    endif.
    concatenate lv_mstxt '...' into lv_mstxt
        separated by space.
    lv_tmins  = ( lv_tsecs div 60 ) mod 60.
    lv_perce = lv_tmins * '1.666666667' . " 100% / 60min = 1.666666667°
    call function 'SAPGUI_PROGRESS_INDICATOR'
      exporting
        percentage = lv_perce
        text       = lv_mstxt.
    wait up to p_secs seconds.
  enddo.