Example ABAP Source Code to
Mass Lock/Unlock SAP users
REPORT ZUSR02 NO STANDARD PAGE HEADING LINE-SIZE 120
LINE-COUNT 90(3).
TABLES: USR02,
USR03.
* XCLASS - User Class
* S_CLASS
* XBNAME - User Name
* S_BNAME
* XLOCK - Lock User
* XNLOCK - Unlock User
* Put an unknown default in
case you press the execute button too fast
SELECT-OPTIONS: XCLASS FOR USR02-CLASS DEFAULT 'XXX'.
SELECT-OPTIONS: XBNAME FOR USR02-BNAME.
SELECTION-SCREEN SKIP.
PARAMETERS: XLOCK RADIOBUTTON GROUP X1,
XNLOCK RADIOBUTTON GROUP X1 DEFAULT 'X'.
SELECTION-SCREEN SKIP.
PARAMETERS: S_CLASS RADIOBUTTON GROUP R1,
S_BNAME RADIOBUTTON GROUP R1.
DATA: WCLASS LIKE USR02-CLASS,
WLOCK(6).
IF XNLOCK = 'X'.
UPDATE USR02 SET UFLAG = ''
WHERE BNAME IN XBNAME.
ELSEIF XLOCK = 'X'.
UPDATE USR02 SET UFLAG = ' 64'
WHERE BNAME IN XBNAME
* User not lock (include yours,
just in case)
AND BNAME <> 'SAP*'
AND BNAME <> 'DDIC'.
ENDIF.
IF S_BNAME = 'X'.
PERFORM BNAMERTN.
ELSE.
PERFORM CLASSRTN.
ENDIF.
*---------------------------------------------------------------------*
* FORM BNAMERTN
*
*---------------------------------------------------------------------*
* ........
*
*---------------------------------------------------------------------*
FORM BNAMERTN.
SELECT * FROM USR02 WHERE CLASS IN XCLASS
ORDER
BY BNAME.
IF XLOCK = 'X'.
CHECK USR02-UFLAG = '
64'.
ENDIF.
IF XNLOCK = 'X'.
CHECK USR02-UFLAG = ''.
ENDIF.
IF USR02-UFLAG = '64'.
WLOCK = 'Lock'.
ELSE.
WLOCK = 'Unlock'.
ENDIF.
SELECT SINGLE * FROM USR03 WHERE BNAME
= USR02-BNAME.
IF SY-SUBRC EQ 0.
WRITE:/001 USR02-CLASS,
016 USR02-BNAME,
031 USR03-NAME1,
064 WLOCK,
071(4) USR03-KOSTL,
078 USR03-ABTLG,
093 USR03-ORT01.
ELSE.
WRITE:/001 USR02-CLASS,
016 USR02-BNAME,
064 WLOCK.
ENDIF.
ENDSELECT.
ENDFORM.
*---------------------------------------------------------------------*
* FORM CLASSRTN
*
*---------------------------------------------------------------------*
* ........
*
*---------------------------------------------------------------------*
FORM CLASSRTN.
SELECT * FROM USR02 WHERE CLASS IN XCLASS
ORDER
BY CLASS BNAME.
IF XLOCK = 'X'.
CHECK USR02-UFLAG = '
64'.
ENDIF.
IF XNLOCK = 'X'.
CHECK USR02-UFLAG = ''.
ENDIF.
IF USR02-UFLAG = '64'.
WLOCK = 'Lock'.
ELSE.
WLOCK = 'Unlock'.
ENDIF.
SELECT SINGLE * FROM USR03 WHERE BNAME
= USR02-BNAME.
IF SY-SUBRC EQ 0.
WRITE:/001 USR02-CLASS,
016 USR02-BNAME,
031 USR03-NAME1,
064 WLOCK,
071(4) USR03-KOSTL,
078 USR03-ABTLG,
093 USR03-ORT01.
ELSE.
WRITE:/001 USR02-CLASS,
016 USR02-BNAME,
064 WLOCK.
ENDIF.
ENDSELECT.
ENDFORM.
TOP-OF-PAGE.
WRITE:/ SY-DATUM,SY-UZEIT,
50 'XXX
PTE LTD',
105 'Page',
SY-PAGNO.
WRITE: / SY-REPID, 'SAP User-IDs'.
SKIP.
ULINE.
WRITE: /001 'User Group',
016 'User-ID',
031 'Name',
064 'Sts',
071 'SBU',
078 'Dept',
093 'Location'.
ULINE.
More Function Module
Functions / SAP
Script / ALV
Tables
Database Table
ABAP Books List
ABAP/4 Certification,
Programming, Smartforms, Sapscripts and Object Oriented Programming Books
Smart Forms
SAP Smartforms
ABAP Menu:
ABAP Example Hints
and Tips
Return to Index:-
SAP ABAP/4 Programming,
Basis Administration, Configuration Hints and Tips
(c) www.gotothings.com All material on this site is Copyright.
Every effort is made to ensure the content integrity.
Information used on this site is at your own risk.
All product names are trademarks of their respective
companies. The site www.gotothings.com is in no way affiliated with
SAP AG.
Any unauthorised copying or mirroring is prohibited.
|