Lock and Unlock User IDs
Lock and Unlock User IDs
*eject
*&--------------------------------------------------------------------*& Type-Pool *
*& *
*&--------------------------------------------------------------------TYPE-POOLS: SSCR.
*eject
*&--------------------------------------------------------------------*& Tables and Infotypes *
*& *
*&--------------------------------------------------------------------tables: usr02.
*eject
*&--------------------------------------------------------------------*& Selection-Screen *
*& *
*&--------------------------------------------------------------------SELECTION-SCREEN BEGIN OF BLOCK FRM1 WITH FRAME TITLE TEXT001.
*eject
*&--------------------------------------------------------------------*& Constants *
*& *
*&--------------------------------------------------------------------CONSTANTS: c_X(1)
TYPE c
VALUE 'X'
,
c_1
TYPE i
VALUE '1'
,
c_20
TYPE i
VALUE '20'
,
c_0
TYPE i
VALUE '0'
,
c_eq
LIKE w_ass-op_main VALUE 'EQ'
,
c_s_bname LIKE w_ass-name
VALUE 'S_BNAME'
c_star
LIKE w_ass-sg_main VALUE '*'
,
c_space
LIKE w_ass-sg_addy VALUE ''
,
c_s
LIKE w_ass-kind
VALUE 'S'
,
c_xyz(3) TYPE C
VALUE 'XYZ'
,
c_under(1) TYPE C
VALUE '_'
,
c_flag(8) TYPE C
VALUE 'FLAG_RUN'
,
c_lock(4) TYPE C
VALUE 'LOCK'
,
c_A(1)
TYPE c
VALUE 'A'
.
*eject
*&--------------------------------------------------------------------*& Initialization *
*& *
*&--------------------------------------------------------------------Initialization.
* Hide the ranges
PERFORM f0001_hide_select_option.
*eject
*&--------------------------------------------------------------------*& AT Selection-screen *
*& *
*&--------------------------------------------------------------------at selection-screen output.
if p_unlock eq C_X.
loop at screen.
if screen-group1 = c_XYZ.
SCREEN-INPUT = c_0.
MODIFY SCREEN.
endif.
endloop.
endif.
*eject
*&--------------------------------------------------------------------*& Start-of Selection *
*& *
*&--------------------------------------------------------------------start-of-selection.
*
w_mandt = sy-mandt.
Concatenate sy-uname
c_FLAG
into indxkey1
separated by c_under .
IMPORT w_flag from DATABASE INDX(ST)
client w_mandt
ID
indxkey1.
if w_flag eq c_x
and p_lock eq c_x.
message e016 with 'Unlock the IDs from previous run'(003).
endif.
Concatenate sy-uname
c_lock
into indxkey
separated by c_under .
if p_lock eq C_X.
select bname uflag into table t_usr
from usr02
where ustyp eq c_A
and bname in s_bname
and class in s_usrgp.
if sy-subrc ne c_0.
stop.
endif.
describe table t_usr lines w_lines.
if w_lines eq c_1.
clear t_usr.
read table t_usr index c_1.
if t_usr-bname eq sy-uname.
stop.
endif.
clear t_usr.
endif.
move c_x to w_flag.
EXPORT w_flag to DATABASE INDX(ST)
client w_mandt
ID
indxkey1.
sort t_usr by bname.
delete adjacent duplicates from t_usr comparing bname.
clear w_count.
loop at t_usr.
check t_usr-bname ne sy-uname and
t_usr-uflag eq c_0.
clear w_active.
CALL FUNCTION 'BAPI_USER_LOCK'
EXPORTING
USERNAME = t_usr-bname
TABLES
RETURN = return.
*
if sy-subrc eq c_0.
CALL FUNCTION 'TH_USER_INFO'
EXPORTING
CLIENT
= sy-mandt
USER
= t_usr-bname
IMPORTING
ACT_SESSIONS = w_active.
if not w_active is initial.
CALL FUNCTION 'TH_DELETE_USER'
EXPORTING
USER
= t_usr-bname
CLIENT
= sy-mandt
EXCEPTIONS
AUTHORITY_ERROR = 1
OTHERS
= 2.
if sy-subrc ne c_0.
clear t_error.
t_error-bname = t_usr-bname.
t_error-message = 'Unable to End Active Session for User'(004).
append t_error.
endif.
endif.
add c_1 to w_count.
clear t_memory.
t_memory-bname = t_usr-bname.
append t_memory.
else.
clear t_error.
t_error-bname = t_usr-bname.
t_error-message = 'User not locked'.
append t_error.
endif.
endloop.
elseif p_unlock eq C_X.
clear: t_memory.
refresh t_memory.
IMPORT t_memory from DATABASE INDX(ST)
client w_mandt
ID
indxkey.
if sy-subrc ne c_0.
stop.
else.
move SPACE to w_flag.
EXPORT w_flag to DATABASE INDX(ST)
client w_mandt
ID
indxkey1.
delete from indx where SRTFD eq indxkey.
clear w_count.
clear: return,t_error.
refresh t_error.
loop at t_memory.
CALL FUNCTION 'BAPI_USER_UNLOCK'
EXPORTING
USERNAME = t_memory-bname
TABLES
RETURN = return.
if sy-subrc eq c_0.
add 1 to w_count.
else.
clear t_error.
t_error-bname = t_usr-bname.
t_error-message = 'User not Unlocked'.
append t_error.
endif.
endloop.
endif.
endif.
*eject
*&--------------------------------------------------------------------*& End-of Selection *
*& *
*&--------------------------------------------------------------------end-of-selection.
if p_lock eq C_X.
skip 1.
write:'No of Users Locked:',Space,w_count.
delete from indx where SRTFD eq indxkey.
EXPORT t_memory to DATABASE INDX(ST)
client w_mandt
ID
indxkey.
* Write erroneous users
if not t_error is initial.
skip 1.
write:'Erroneous users:' color 6.
skip 1.
uline 1(57).
perform f0002_output.
endif.
elseif p_unlock eq C_X.
skip 1.
write:'No of Users Unlocked:',Space,w_count.
* Write erroneous users
if not t_error is initial.
skip 1.
write:'Unable to Unlock following users:' color 6.
skip 1.
uline 1(57).
perform f0002_output.
endif.
endif.
*eject
*&---------------------------------------------------------------------*
*&
Form F0001_HIDE_SELECT_OPTION
*&---------------------------------------------------------------------*
FORM F0001_HIDE_SELECT_OPTION .
MOVE c_eq TO w_opt_list-name
.
MOVE c_X TO w_opt_list-options-eq .
APPEND w_opt_list TO w_restrict-opt_list_tab.
MOVE: c_s
TO w_ass-kind ,
c_s_bname TO w_ass-name ,
c_star
TO w_ass-sg_main ,
c_space TO w_ass-sg_addy ,
c_eq
TO w_ass-op_main .
APPEND w_ass TO w_restrict-ass_tab.
* Function module to restrict the range
CALL FUNCTION 'SELECT_OPTIONS_RESTRICT'
EXPORTING
restriction = w_restrict.
ENDFORM.
" F0001_HIDE_SELECT_OPTION
*eject
*&---------------------------------------------------------------------*
*&
Form F0002_OUTPUT
*&---------------------------------------------------------------------*
FORM F0002_OUTPUT .
loop at t_error.
if w_tabix eq c_20.
clear w_tabix.
NEW-PAGE.
endif.
w_tabix = w_tabix + c_1.
write: /1 sy-vline,
15 sy-vline,
57 sy-vline.
write: 2 t_error-bname,
17 t_error-message.
uline /1(57).
endloop.
ENDFORM.
" F0001_OUTPUT