How to Lock and Unlock Users


REPORT ZUSR_LOCK.
TABLES USR02.
DATA: Z_USR02 LIKE USR02 OCCURS 0 WITH HEADER LINE.
DATA: ZCOUNT TYPE I,
       DEST(72).

*-- Select-Options 
-----------------------------------------------------
SELECTION-SCREEN BEGIN OF BLOCK 1 WITH FRAME TITLE TEXT-100.
SELECT-OPTIONS: S_BNAME FOR USR02-BNAME NO INTERVALS.
*                S_CLASS FOR USR02-CLASS NO INTERVALS.
PARAMETER: ZTEST AS CHECKBOX DEFAULT 'X'.
selection-screen end of block 1.

SELECTION-SCREEN BEGIN OF BLOCK 2 WITH FRAME TITLE TEXT-110.
PARAMETERS: ZUFLAG_L RADIOBUTTON GROUP RADI,
            ZUFLAG_U RADIOBUTTON GROUP RADI.
SELECTION-SCREEN END OF BLOCK 2.
*-- Select-Options 
-----------------------------------------------------
AT SELECTION-SCREEN.
  IF SY-SUBRC NE 0.
    MESSAGE I001(CJ) WITH TEXT-001.
    EXIT.
  ENDIF.
  IF S_BNAME IS INITIAL.
* and    S_CLASS IS INITIAL.
    MESSAGE E001(CJ) WITH TEXT-003.
  ENDIF.

START-OF-SELECTION.

IF ZUFLAG_L EQ 'X'.
  SELECT * FROM USR02 INTO TABLE Z_USR02 WHERE BNAME IN S_BNAME
*                                           AND CLASS IN S_CLASS
                                           AND UFLAG EQ ' '.
ENDIF.

IF ZUFLAG_U EQ 'X'.
  SELECT * FROM USR02 INTO TABLE Z_USR02 WHERE BNAME IN S_BNAME
*                                           AND CLASS IN S_CLASS
                                           AND UFLAG EQ '64'.
  ENDIF.
  IF SY-SUBRC ?> 0.
    MESSAGE I001(CJ) WITH TEXT-002.
    EXIT.
  ELSE.
    IF ZTEST EQ ' '.
      LOOP AT Z_USR02.
        SELECT SINGLE * FROM USR02 WHERE BNAME EQ Z_USR02-BNAME.
        IF ZUFLAG_L EQ 'X'.
          USR02-UFLAG = '64'.
        ENDIF.
        IF ZUFLAG_U EQ 'X'.
          USR02-UFLAG = '0'.
        ENDIF.
        MODIFY USR02.
        IF SY-SUBRC EQ 0.
          ZCOUNT = ZCOUNT + 1.
*          z_usr02-zbvmaster = 'X'.
          MODIFY Z_USR02.
        ENDIF.
      ENDLOOP.
    ENDIF.
  ENDIF.
END-OF-SELECTION.

*Write result
  IF NOT ZCOUNT IS INITIAL.
    IF ZUFLAG_L EQ 'X'.
      WRITE TEXT-200 TO DEST(40).
      WRITE ZCOUNT TO DEST+41(3).
    ENDIF.
    IF ZUFLAG_U EQ 'X'.
      WRITE: TEXT-300 TO DEST(40).
      WRITE ZCOUNT TO DEST+41(3).
    ENDIF.
  ELSE.
    WRITE: TEXT-400.
  ENDIF.

  LOOP AT Z_USR02.
    WRITE: /3 Z_USR02-BNAME.
  ENDLOOP.

TOP-OF-PAGE.
  WRITE: /1 DEST COLOR 3.
ABAP Tips by :  Manas Ranjan Panda

Fast Links:
Ways to Lock and Unlock SAP Users
Different methods to Lock or unlock SAP users

Get help for your ABAP problems
Do you have a ABAP Question?

SAP Books
SAP Certification, Functional, Basis Administration and ABAP Programming Reference Books

ABAP Tips
ABAP Forum for Discussion and Samples Program Codes for Abapers

Best regards,
SAP Basis, ABAP Programming and Other IMG Stuff
http://www.erpgreat.com

All the site contents are Copyright © www.erpgreat.com and the content authors. All rights reserved.
All product names are trademarks of their respective companies.  The site www.erpgreat.com is in no way affiliated with SAP AG.
Every effort is made to ensure the content integrity.  Information used on this site is at your own risk.
 The content on this site may not be reproduced or redistributed without the express written permission of
www.erpgreat.com or the content authors.