Posted: Sun Nov 25, 2007 2:14 am Post subject: Delete/lock/display users who haven't logged in for N days
Code:
REPORT ZINACTIV NO STANDARD PAGE HEADING.
************************************************************************
* This program displays, locks or deletes the users, whose last login
* date is older then N days or they have never logged in and they were
* created at least N days ago
************************************************************************
* Atcion input
SELECTION-SCREEN BEGIN OF BLOCK B1 WITH FRAME.
SELECTION-SCREEN BEGIN OF LINE.
SELECTION-SCREEN COMMENT (20) COMMENT0.
SELECTION-SCREEN POSITION 56.
PARAMETERS: DISP RADIOBUTTON GROUP R1.
SELECTION-SCREEN END OF LINE.
SELECTION-SCREEN BEGIN OF LINE.
SELECTION-SCREEN COMMENT (20) COMMENT1.
SELECTION-SCREEN POSITION 56.
PARAMETERS: LOCK RADIOBUTTON GROUP R1.
SELECTION-SCREEN END OF LINE.
SELECTION-SCREEN BEGIN OF LINE.
SELECTION-SCREEN COMMENT (20) COMMENT2.
SELECTION-SCREEN POSITION 56.
PARAMETERS: DELETE RADIOBUTTON GROUP R1.
SELECTION-SCREEN END OF LINE.
SELECTION-SCREEN END OF BLOCK B1.
* User type input
SELECTION-SCREEN BEGIN OF BLOCK B2 WITH FRAME.
SELECTION-SCREEN BEGIN OF LINE.
SELECTION-SCREEN COMMENT (35) COMMENT3.
SELECTION-SCREEN POSITION 56.
PARAMETERS: INAC RADIOBUTTON GROUP R2.
SELECTION-SCREEN END OF LINE.
SELECTION-SCREEN BEGIN OF LINE.
SELECTION-SCREEN COMMENT (35) COMMENT4.
SELECTION-SCREEN POSITION 56.
PARAMETERS: NOLOG RADIOBUTTON GROUP R2.
SELECTION-SCREEN END OF LINE.
SELECTION-SCREEN END OF BLOCK B2.
* Period input
SELECTION-SCREEN BEGIN OF BLOCK B3 WITH FRAME.
SELECTION-SCREEN BEGIN OF LINE.
SELECTION-SCREEN COMMENT (12) COMMENT5.
SELECTION-SCREEN POSITION 16.
PARAMETERS: DAYS(3) TYPE N OBLIGATORY DEFAULT '60'.
SELECTION-SCREEN COMMENT 21(20) COMMENT6.
SELECTION-SCREEN END OF LINE.
SELECTION-SCREEN END OF BLOCK B3.
START-OF-SELECTION.
* Data declaration
TABLES: USR02.
DATA: LAST_DATE TYPE D.
DATA: BEGIN OF USERS OCCURS 50,
BNAME LIKE USR02-BNAME,
TRDAT LIKE USR02-TRDAT,
ERDAT LIKE USR02-ERDAT,
END OF USERS.
data: begin of bdc_tab occurs 100.
include structure bdcdata.
data: end of bdc_tab.
* Calculate the date
LAST_DATE = SY-DATUM.
LAST_DATE = LAST_DATE - DAYS.
* Find the users that fulfill the criterias
SELECT * FROM USR02 WHERE USTYP = 'A'.
IF USR02-TRDAT <= LAST_DATE.
IF USR02-TRDAT = '00000000' AND NOLOG = 'X'.
IF USR02-ERDAT <= LAST_DATE.
MOVE-CORRESPONDING USR02 TO USERS.
APPEND USERS.
ENDIF.
ELSEIF USR02-TRDAT <> '00000000' AND INAC = 'X'.
MOVE-CORRESPONDING USR02 TO USERS.
APPEND USERS.
ENDIF.
ENDIF.
ENDSELECT.
* Depending on the action: display, lock or delete
IF DISP = 'X'.
WRITE: / ' USER LAST LOGIN CREATED'.
SKIP.
LOOP AT USERS.
WRITE: / USERS-BNAME, USERS-TRDAT, USERS-ERDAT.
ENDLOOP.
ELSEIF LOCK = 'X'.
WRITE: / 'LOCKED:'.
WRITE: / ' USER LAST LOGIN CREATED'.
SKIP.
LOOP AT USERS.
WRITE: / USERS-BNAME, USERS-TRDAT, USERS-ERDAT.
SELECT SINGLE * FROM USR02 WHERE BNAME = USERS-BNAME.
USR02-UFLAG = '128'.
MODIFY USR02.
ENDLOOP.
ELSE.
WRITE: / 'DELETED:'.
WRITE: / ' USER LAST LOGIN CREATED'.
SKIP.
LOOP AT USERS.
WRITE: / USERS-BNAME, USERS-TRDAT, USERS-ERDAT.
PERFORM USER_DELETE.
ENDLOOP.
ENDIF.
*---------------------------------------------------------------------*
* FORM USER_DELETE *
*---------------------------------------------------------------------*
FORM USER_DELETE.
PERFORM BDC_FILL USING 'X'
'SAPMS01J'
'0200'.
PERFORM BDC_FILL USING ' '
'BDC_OKCODE'
'DELU'.
PERFORM BDC_FILL USING ' '
'BDC_CURSOR'
'XU200-XUSER'.
PERFORM BDC_FILL USING ' '
'XU200-XUSER'
USERS-BNAME.
PERFORM BDC_FILL USING 'X'
'SAPLSPO1'
'0400'.
PERFORM BDC_FILL USING ' '
'BDC_OKCODE'
'YES'.
PERFORM BDC_FILL USING 'X'
'SAPLSPO1'
'0100'.
PERFORM BDC_FILL USING ' '
'BDC_OKCODE'
'YES'.
PERFORM BDC_FILL USING 'X'
'SAPMS01J'
'0200'.
PERFORM BDC_FILL USING ' '
'BDC_OKCODE'
'BACK'.
PERFORM BDC_FILL USING ' '
'BDC_CURSOR'
'XU200-XUSER'.
PERFORM BDC_FILL USING ' '
'XU200-XUSER'
USERS-BNAME.
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum You cannot attach files in this forum You can download files in this forum
All product names are trademarks of their respective companies. SAPNET.RU websites are in no way affiliated with SAP AG. SAP, SAP R/3, R/3 software, mySAP, ABAP, BAPI, xApps, SAP NetWeaver and any other are registered trademarks of SAP AG. Every effort is made to ensure content integrity. Use information on this site at your own risk.