如何编程实现删除一个sap的在线用户

REPORT ZKICK.

** Data ****************************************************************
DATA: OPCODE TYPE X VALUE 2.
DATA: BEGIN OF usr_tabl OCCURS 10.
        INCLUDE STRUCTURE uinfo.
DATA: END OF usr_tabl.
DATA TEMP_TEXT LIKE SM04DIC-POPUPMSG.
DATA: BEGIN OF fields OCCURS 10.
        INCLUDE STRUCTURE help_value.
DATA: END OF fields.
DATA: BEGIN OF valuetab OCCURS 10,
        line(80),
      END OF valuetab.
DATA: TMPUNAME LIKE SY-UNAME.

** Selection Screen ****************************************************
* Kick Off User/s
SELECTION-SCREEN BEGIN OF BLOCK B1 WITH FRAME TITLE TEXT-001.
* User Name
SELECT-OPTIONS: UNAME FOR SY-UNAME OBLIGATORY.
* Client
PARAMETERS: CLIENT LIKE T000-MANDT DEFAULT SY-MANDT OBLIGATORY.
SELECTION-SCREEN SKIP.
* Time To Kick User Off Until
PARAMETERS: TIME LIKE SY-UZEIT DEFAULT SY-UZEIT OBLIGATORY,
* Interval Between Logoffs
            INTERVAL(2) TYPE N DEFAULT 1 OBLIGATORY,
* Warn User Before Kicking Off?
            WARN AS CHECKBOX.
SELECTION-SCREEN END OF BLOCK B1.

** At Selection Screen *************************************************
AT SELECTION-SCREEN ON VALUE-REQUEST FOR UNAME-LOW.
  PERFORM F4_HELP_CHECK_UNAME USING UNAME-LOW.

** Start of Selection **************************************************
START-OF-SELECTION.

  DO.
    REFRESH USR_TABL.

* Get the list of logged on users
    CALL 'ThUsrInfo' ID 'OPCODE' FIELD opcode
        ID 'TAB' FIELD usr_tabl-*sys*.

    LOOP AT USR_TABL WHERE BNAME IN UNAME.
*     If user/s must be warned
      IF NOT WARN IS INITIAL.

        CONCATENATE 'You will be logged off from client'
                    CLIENT
                    'in 10 seconds.' INTO TEMP_TEXT SEPARATED BY SPACE.
        CALL FUNCTION 'TH_POPUP'
             EXPORTING
                  CLIENT         = CLIENT
                  USER           = USR_TABL-BNAME
                  MESSAGE        = TEMP_TEXT
             EXCEPTIONS
                  USER_NOT_FOUND = 1
                  OTHERS         = 2.

*       Wait 10 seconds after warning user/s
        WAIT UP TO 10 SECONDS.
      ENDIF.

* Kick off user/s
      CALL FUNCTION 'TH_DELETE_USER'
           EXPORTING
                USER            = USR_TABL-BNAME
                CLIENT          = CLIENT
           EXCEPTIONS
                AUTHORITY_ERROR = 1
                OTHERS          = 2.
    ENDLOOP.

* Once the specified time is reached, stop logging user/s off.
    IF SY-UZEIT >= TIME.
      EXIT.
    ENDIF.

* Wait the specified time before logging off user/s again.
    WAIT UP TO INTERVAL SECONDS.
  ENDDO.

** Forms ***************************************************************
*&---------------------------------------------------------------------*
*&      Form  F4_HELP_CHECK_UNAME
*&---------------------------------------------------------------------*
*       This is to show only logged on users when F4 is pressed on
*       user name.
*----------------------------------------------------------------------*
*      -->P_UNAME_LOW  text
*----------------------------------------------------------------------*
FORM F4_HELP_CHECK_UNAME USING P_UNAME.
  CLEAR fields.
  REFRESH fields.
  CLEAR valuetab.
  REFRESH valuetab.
  CLEAR usr_tabl.
  REFRESH usr_tabl.

* Fill the structure table
  fields-tabname = 'ZTSTSTRC'.
  fields-fieldname = 'NAME'.
  fields-selectflag = 'X'.
  APPEND fields.
  CLEAR fields.

  fields-tabname = 'ZTSTSTRC'.
  fields-fieldname = 'CLIENT'.
  APPEND fields.
  CLEAR fields.

* Get the list of logged on users
  CALL 'ThUsrInfo' ID 'OPCODE' FIELD opcode
      ID 'TAB' FIELD usr_tabl-*sys*.

  DELETE USR_TABL WHERE BNAME = SY-UNAME AND MANDT = SY-MANDT.
  DELETE USR_TABL WHERE BNAME IS INITIAL.
  SORT usr_tabl BY mandt bname.
  DELETE ADJACENT DUPLICATES FROM USR_TABL COMPARING BNAME MANDT.

* Fill the value table
  LOOP AT USR_TABL.
    valuetab-line = usr_tabl-bname.
    APPEND valuetab.
    valuetab-line = usr_tabl-mandt.
    APPEND valuetab.
  ENDLOOP.

* Call the help value screen
  CALL FUNCTION 'HELP_VALUES_GET_WITH_TABLE'
  EXPORTING
               TITLE_IN_VALUES_LIST = ''
               titel = 'Online Users'
  IMPORTING
                SELECT_VALUE  = TMPUNAME
  TABLES
                fields   = fields
                valuetab = valuetab.
  P_UNAME = TMPUNAME.

* Change the client number to correspond with what user name the
* user selects.
  CLEAR CLIENT.
  READ TABLE USR_TABL WITH KEY BNAME = TMPUNAME.
  CLIENT = USR_TABL-MANDT.
ENDFORM.                               " f4_help_check_uname 

posted on 2006-12-06 17:16  毛小娃  阅读(168)  评论(0编辑  收藏  举报

导航