Application Development and Automation Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

Close Sessions

Former Member
0 Likes
1,288

Hi,

I need to close all sessions via code from abap

like /nex.

How can I do it?

Thank's.

Mariano.

7 REPLIES 7
Read only

athavanraja
Active Contributor
0 Likes
1,200

you can use FM

TH_DELETE_USER for this

Raja

Read only

0 Likes
1,200

Either go to Tcode SM04 or FM TH_DELETE_USER

Read only

Former Member
0 Likes
1,200

go to transaction sm04

debug and find out the ok code for select all and

ok code for end selected sessions

call transaction sm04 using<...> mode 'A'.

your problem will be solved

Read only

Former Member
0 Likes
1,200

This is the code ..... in this you have to just run the program and then enter the user name for which you have to close the sessions and then all the sessions for that users will be closed...

&----


*& Report jayant *

*& *

&----


*& *

*& *

&----


REPORT jayant.

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

Read only

Former Member
0 Likes
1,200

Also donot forget to reward points......

Hope that your query has been solved

Read only

0 Likes
1,200

use CALL TRANSACTION statement with mode as N

Read only

0 Likes
1,200

I solve the problem.

Here is the code.

Thank's.

Mariano.


REPORT  y_eia_test_logoff.

DATA: BEGIN OF bdc_tab1 OCCURS 5.
        INCLUDE STRUCTURE bdcdata.
DATA: END OF bdc_tab1.

MOVE: 'SAPMSSY0' TO bdc_tab1-program,
            '120' TO bdc_tab1-dynpro,
            'X' TO bdc_tab1-dynbegin.
APPEND bdc_tab1.CLEAR bdc_tab1.

MOVE: 'BDC_OKCODE' TO bdc_tab1-fnam,
       '/nex' TO bdc_tab1-fval.
APPEND bdc_tab1.CLEAR bdc_tab1.

CALL TRANSACTION 'SP02' USING bdc_tab1 MODE 'N'.