Wednesday, June 5, 2024

How to Lock and Unlock Users

 REPORT ZUSER_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.

No comments:

Post a Comment