2007 May 23 11:35 PM
Hi experts,
We are planning to implement Password reset function to a system, need to copy the existing code from another system...and the BSP code as well from another system for the UI..
Have any advice on how to do this...
Thanks,
Harini
Hi experts,
We are planning to implement Password reset function to a system, need to copy the existing code from another system...and the BSP code as well from another system for the UI..
Have any advice on how to do this...
Thanks,
Harini
2007 May 24 2:28 AM
See the below program and which we will use reset the password...
----
SAP table Declaration
----
tables: usr02, " Logon data
ush02. " Change history for logon data
----
Internal Table Declaration
----
data: int_ush02 like ush02 occurs 0 with header line,
int_ush02_update like ush02 occurs 0 with header line.
data: begin of int_output occurs 0.
data: flag type c.
include structure ush02.
data: end of int_output.
----
Structures Declaration
----
data: lastchange like uschange.
----
Date Field Declaration
----
data: mode(1) type c,
ok_code(1) type n,
user_name like sy-uname.
data: uflag like ush02-uflag.
----
Selection Screen *
----
selection-screen begin of block b00 with frame title text-b00.
selection-screen begin of block b01 with frame title text-b01.
select-options: s_user for usr02-bname no intervals
no-extension,
s_class for usr02-class no intervals
no-extension.
selection-screen skip.
parameter: p_dept as checkbox,
p_rf as checkbox.
selection-screen end of block b01.
selection-screen begin of block b02 with frame title text-b02.
parameter: lock radiobutton group rad1,
unlock radiobutton group rad1.
selection-screen skip.
selection-screen begin of block b03 with frame title text-b03.
selection-screen skip.
select-options: s_luser for usr02-bname no intervals
no-extension
default sy-uname,
s_ldate for sy-datum no intervals
no-extension
default sy-datum.
selection-screen skip.
selection-screen end of block b03.
selection-screen end of block b02.
selection-screen end of block b00.
----
Events
----
initialization.
ok_code = 0.
loop at screen.
gray out radio button for unlock
if screen-name(11) = 'S_LUSER-LOW'.
screen-input = '0'.
endif.
if screen-name(11) = 'S_LDATE-LOW'.
screen-input = '0'.
endif.
modify screen.
endloop.
at selection-screen.
loop at screen.
if unlock = 'X'.
gray out radio button for unlock
if screen-name(11) = 'S_LUSER-LOW'.
screen-input = '0'.
endif.
if screen-name(11) = 'S_LDATE-LOW'.
screen-input = '0'.
endif.
modify screen.
endif.
endloop.
case s_class-low.
when 'SYSTEM'.
perform error_message using '1' 'SYSTEM'.
stop.
when 'SUPER'.
perform error_message using '1' 'SUPER'.
stop.
when 'SERVICE'.
perform error_message using '1' 'SERVICE'.
stop.
when 'COMMUNICATIO'.
perform error_message using '1' 'COMMUNICATIO'.
stop.
when 'FD_ERP'.
perform error_message using '1' 'FD_ERP'.
stop.
endcase.
if unblock mode, user who blcoked the user and the date
should be the same
if unlock = 'X'.
read table s_ldate index 1.
if s_ldate-low = space.
perform error_message using '2' 'Date when lock was done'.
stop..
endif.
read table s_luser index 1.
if s_luser-low = space.
perform error_message using '2' 'User who locked'.
stop..
endif.
endif.
either special user or department user has to be used
if s_user[] is initial and ( p_dept = space and p_rf = space ).
perform error_message using '3'
'Use at least Single User or Checkbox - All Deptartment User'.
stop.
endif.
only special user or department user has to be used
if not s_user[] is initial and
not ( p_dept = space and p_rf = space ).
perform error_message using '3'
'Use only Single User or Checkbox - All Deptartment User'.
ok_code = '1'.
endif.
----
program control
----
start-of-selection.
check ok_code = 0.
Status of user
0 User not locked
32 (Hex 20) Locked by central administrator of CUA
64 (Hex 40) Locked by administrator
128 (Hex 80) Locked due to incorrect messages
set lock/unlock mode
if lock = 'X'.
mode = 'L'.
uflag = '64 '.
else.
mode = 'U'.
uflag = ' 0 '.
endif.
select all department user when box is checked
if p_dept = 'X'.
select bname from usr02
into s_user-low
where class = 'FD_DEP_USER'.
append s_user.
endselect.
elseif p_rf = 'X'.
select bname from usr02
into s_user-low
where class = 'FD_RF_USER'.
append s_user.
endselect.
else.
read table s_user index 1.
if s_class-low = space.
s_class-low = 'FD_DEP_USER'.
endif.
select single * from usr02
where bname = s_user-low
and class = s_class-low.
if sy-subrc = 0.
else.
message i000(zwave) with 'Not allowed to block this user'.
stop.
endif.
endif.
sort s_user by low.
loop at s_user.
change to SAP standart (CHAR -> CHAR12)
user_name = s_user-low.
check last change to unblock only user which are blocked by same user
check status to change only user whioch have to be changed.
clear ush02.
perform check_last_user_change using user_name
changing ush02
usr02.
user not in the system
if ush02 is initial.
int_output-bname = user_name.
int_output-flag = 'U'.
append int_output.
continue.
endif.
int_output-bname = ush02-bname.
user last change and current status not in sink
if usr02-uflag ne ush02-uflag.
int_output-flag = 'S'.
append int_output.
continue.
endif.
lock mode
case mode.
when 'L'.
user allready locked
if ush02-uflag ne ' 0 '.
int_output+1 = ush02.
int_output-flag = 'L'.
append int_output.
continue.
endif.
user for lock in internal table
int_ush02 = ush02.
append int_ush02.
int_output+1 = ush02.
int_output-flag = space.
append int_output.
when 'U'.
user locked by other instance
if ush02-uflag > '128' .
int_output+1 = ush02.
int_output-flag = 'I'.
append int_output.
continue.
endif.
user was locked by different user
read table s_luser index 1.
if ush02-modbe ne s_luser-low and
ush02-modbe ne ush02-MODBE.
int_output+1 = ush02.
int_output-flag = 'N'.
append int_output.
continue.
endif.
user was locked on different date
read table s_ldate index 1.
if ush02-modda ne s_ldate-low.
int_output+1 = ush02.
int_output-flag = 'D'.
append int_output.
continue.
endif.
user for unlock in internal table
int_ush02 = ush02.
append int_ush02.
int_output+1 = ush02.
int_output-flag = space.
append int_output.
endcase.
endloop.
loop at int_ush02.
lock / unlock
call function '/RTC/AS_LOCK_UNLOCK_USER'
exporting
mandt = sy-mandt
user = int_ush02-bname
mode = mode
forced = 'X'
exceptions
no_authorization = 1
wrong_mode = 2
mandt_not_found = 3
user_not_found = 4
lock_user_not_allowed = 5
others = 6.
if sy-subrc = 0.
perform create_change_entry using int_ush02-bname uflag.
else.
message e000(zwave) with
'Lock/Unlock failed with reason ' sy-subrc.
endif.
endloop.
change history
if not int_ush02_update[] is initial.
insert ush02 from table int_ush02_update.
if sy-subrc = 0.
else.
message e000(zwave)
with 'Table update USH02 for change data failed'.
endif.
endif.
commit work.
loop at int_output.
write:/ int_output-bname,
int_output-flag.
case mode.
when 'L'.
case int_output-flag.
when space.
write: 'locked'.
when 'S'.
write: 'Lockstatus and Change history Lockstatus different'.
when 'L'.
write: 'User allready locked'.
endcase.
when 'U'.
case int_output-flag.
when space.
write: 'unlocked'.
when 'S'.
write: 'Lockstatus and Change history Lockstatus different'.
when 'N'.
write: 'User locked by different administrator ',
ush02-modbe.
write: 'To unlock use the field - User who locked',
'on the selection screen'.
when 'D'.
write: 'User locked on different day - locked'.
when 'I'.
write: 'Locked due unknown event'.
when space.
Status of user
if ush02-uflag = '0'.
write: 'User not locked'.
elseif ush02-uflag = '32'.
write: 'Locked by central administrator of CUA'.
elseif ush02-uflag = '64'.
write: 'Locked by administrator'.
elseif ush02-uflag = '128'.
write: 'Locked due to incorrect messages'.
endif.
endcase.
endcase.
endloop.
end-of-selection.
&----
*& Form error_message
&----
text
----
-->P_CLASS text
----
form error_message using value(p_number) value(p_class).
data: titel(40) type c,
txt1(40) type c,
txt2(40) type c,
txt3(40) type c,
txt4(40) type c.
case p_number.
when '1'.
titel = 'Attention - wrong value selected'.
txt1 = ' The selected user group '.
txt2 = p_class.
txt3 = ' cannot be blocked'.
txt4 = ' '.
when '2'.
titel = 'Attention - value needed'.
txt1 = ' The Input Field '.
txt2 = p_class.
txt3 = ' has to be maitained'.
txt4 = ' '.
when '3'.
titel = 'Attention - value needed'.
txt1 = p_class(12).
txt2 = p_class+14(15).
txt3 = p_class+29(31).
txt4 = ' '.
endcase.
call function 'POPUP_TO_INFORM'
exporting
titel = titel
txt1 = txt1
txt2 = txt2
txt3 = txt3
txt4 = txt4.
endform. " error_message
&----
*& Form check_last_user_change
&----
text
----
--> p1 text
<-- p2 text
----
form check_last_user_change using p1_user_name
changing p_ush02
p_usr02.
call function 'SUSR_USER_LASTCHANGE_GET'
exporting
user_name = p1_user_name
importing
user_lastchange = lastchange
exceptions
user_name_not_exist = 1
others = 2.
if sy-subrc <> 0.
exit.
endif.
read last change
select single * from ush02
into p_ush02
where bname = p1_user_name
and modda = lastchange-modda
and modti = lastchange-modti
and modbe = lastchange-modbe.
if sy-subrc <> 0.
exit.
endif.
read current status
select single * from usr02
into p_usr02
where bname = p1_user_name.
if sy-subrc <> 0.
exit.
endif.
endform. " check_last_user_change
&----
*& Form check_last_user_change
&----
text
----
--> p1 text
<-- p2 text
----
form create_change_entry using p2_user_name p_uflag.
User flag
*
Status of user
*
0 User not locked
32 (Hex 20) Locked by central administrator of CUA
64 (Hex 40) Locked by administrator
128 (Hex 80) Locked due to incorrect messages
*
More than one lock can occur at the same time.
In this case the field
contains the sum of the values
*
read table int_ush02 with key bname = p2_user_name.
int_ush02_update = int_ush02.
update the data with current date time user
int_ush02_update-modda = sy-datum.
int_ush02_update-modti = sy-uzeit.
int_ush02_update-modbe = sy-uname.
fake here SU01 because Z transaction name is to long
int_ush02_update-tcode = 'SU01'.
int_ush02_update-repid = sy-repid.
lock / unlock status
int_ush02_update-uflag = p_uflag.
append int_ush02_update.
if sy-subrc = 0.
else.
message e000(zwave) with
'Internal table insert for change data failed'.
endif.
endform.
Reward Points if it is helpful
Thanks
Seshu
Message was edited by:
Seshu Maramreddy
2007 May 24 3:48 AM
Text elements :
LOCK Lock
P_DEPT All Department User
P_RF All RF User
S_CLASS User group
S_LDATE Date when lock was done
S_LUSER User who locked
S_USER Special User
UNLOCK Unlock
________ ______________________________
| User | Count |
|---|---|
| 6 | |
| 2 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 |