SAP R/3 форум ABAP консультантов
Russian ABAP Developer's Club

Home - FAQ - Search - Memberlist - Usergroups - Profile - Log in to check your private messages - Register - Log in - English
Blogs - Weblogs News

Summary of Roles, Profiles and Authorizations by User ID v.2



 
Post new topic   Reply to topic    Russian ABAP Developer's Club Forum Index -> Security and Monitoring
View previous topic :: View next topic  
Author Message
admin
Администратор
Администратор



Joined: 01 Sep 2007
Posts: 1636

PostPosted: Wed Aug 20, 2008 10:04 am    Post subject: Summary of Roles, Profiles and Authorizations by User ID v.2 Reply with quote

Code:
REPORT ZHRKOPAR_SECURITY_2 LINE-SIZE 121
                           NO STANDARD PAGE HEADING  MESSAGE-ID ZZ.
************************************************************************
* Program name     : ZHRKOPAR_SECURITY_2
* Original Author  : James Frazier
* Creation Date    : 09-20-2002
* Description      : Summary of Roles, Profiles and Authorizations by
*                    User ID
*
* Frequency        : Variable
* Project Name     : LIS
************************************************************************
*                          MODIFICATION LOG
************************************************************************
* Change     Change         Change           Change Version
* Author      Date       Description             Number
*----------------------------------------------------------------------*
*
*
*
************************************************************************


************************************************************************
*  TABLES
************************************************************************
TABLES: ADCP,      " Person/Address assignment (central address administ
        ADRP,      " Persons (central address administration)
        AGR_HIER,  " Table for Structure Information for Menu
        AGR_HIERT, " Role menu texts
        AGR_USERS, " Assignment of roles to users
        AGR_TEXTS, " File Structure for Hierarchical Menu - Customer
        DFIES,     " DD Interface: Table Fields for DDIF_FIELDINFO_GET
        HRP1000,   " PD Object Name
        PA0105,    " HR Master Record: Infotype 0105 (Communications)
        PERNR,     "
        USR02,     " Logon data
        USR04,     " User master authorizations
        USR11,     " User Master Texts for Profiles (USR10)
        USR12,     " User master authorization values
        USR21,     " Assign user name address key
        UST04,     " User masters
        TOBJT.     " Texts for Objects in Table TOBJ

************************************************************************
* STANDARD INCLUDES
************************************************************************

*INCLUDE ZHRKOPAIFSTANDARD_HEADER.

************************************************************************
* DATA DECLARATIONS
************************************************************************
DATA: BEGIN OF ITAB-USER OCCURS 10,
          USERID      LIKE  USR04-BNAME,
          USERN       LIKE  USR21-PERSNUMBER,
          AD_ADDRNUM  LIKE  USR21-ADDRNUMBER,
      END   OF ITAB-USER.

DATA: BEGIN OF ITAB_S OCCURS 10,
          AGR_NAME    LIKE  AGR_USERS-AGR_NAME,
      END   OF ITAB_S.

DATA: BEGIN OF ITAB_R OCCURS 10,
          AGR_NAME    LIKE  AGR_USERS-AGR_NAME,
      END   OF ITAB_R.

DATA: BEGIN OF I_TAB OCCURS 10,
          LNAME(25),
          FNAME(20),
          PERNR    LIKE  PERNR-PERNR,
          USERID   LIKE  USR04-BNAME,
          EDATE(10),
          ROLE(40),
          BEGDA(10),
          ENDDA(10),
          POSITION(30),
          WERKS(4),
          ORG(20),
      END OF I_TAB.

DATA: BEGIN OF INTFIELD OCCURS 10,
          FIELDNAME LIKE TOBJ-FIEL1,
          LNG       TYPE I,
          TYPE,
          FTEXT     LIKE DFIES-SCRTEXT_L,
          CONVEXIT  LIKE DFIES-CONVEXIT,
       END OF INTFIELD.

DATA: BEGIN OF TABPRO OCCURS 500,
          USERID     LIKE  USR04-BNAME,
          PROFILE    LIKE  XU213-PROFILE,
      END OF TABPRO.

DATA: BEGIN OF TABAUTH OCCURS 500,
          USERID     LIKE  USR04-BNAME,      "Userid
          PROFILE    LIKE  XU213-PROFILE,    "Profile
          OBJECT     LIKE  USR12-OBJCT,      "Object
          RULE       LIKE  USR12-AUTH,       "Authorization
      END OF TABAUTH.

DATA: BEGIN OF TABVAL OCCURS 500,
          USERID     LIKE  USR04-BNAME,
          PROFILE    LIKE  XU213-PROFILE,
          OBJECT     LIKE  USR12-OBJCT,
          RULE       LIKE  USR12-AUTH,     "Authorization
          SFIELD     LIKE  TOBJ-FIEL1,     "Field Name
          VON(18),                         "Value From
          BIS(18),                         "Value To
          USED-IN-REPORT-ALREADY,
      END OF TABVAL.


DATA:  USER-NAME      LIKE  USR03-NAME1,
       USER-ID(14),
       WS-TEXT(10),
       SYST_LANGUAGE   VALUE 'D',
       TEMP-USERID     LIKE  USR04-BNAME,
       TEMP-PROFILE    LIKE  XU213-PROFILE,
       MAXCPF          TYPE I VALUE 300,
       MAXPRO          TYPE I VALUE 170,
       FLDLNG          LIKE SY-FDPOS VALUE 10,     "Field
       AUTHLNG         LIKE SY-FDPOS VALUE 12,
       OBJLNG          LIKE SY-FDPOS VALUE 10,     "Object
       PROFLNG         LIKE SY-FDPOS VALUE 12,
       PREV-RULE       LIKE USR12-AUTH,            "Authorization
       PREV-OBJECT     LIKE  USR12-OBJCT,
       PREV-SFIELD     LIKE TOBJ-FIEL1.

DATA: I0001  LIKE P0001 OCCURS 0 WITH HEADER LINE.

DATA: WS-VALID-FL.

FIELD-SYMBOLS:  <TEXT>.

*---> ALV Declarations <---

TYPE-POOLS: slis.

DATA:     header_alv_wa TYPE slis_listheader,
          header_alv    TYPE slis_t_listheader.

DATA: fieldcat                TYPE slis_t_fieldcat_alv,
      fieldcat_ln             LIKE LINE OF fieldcat,

      sortcat                 TYPE slis_t_sortinfo_alv,
      sortcat_ln              LIKE LINE OF sortcat,

      eventcat                TYPE slis_t_event,
      eventcat_ln             LIKE LINE OF eventcat.

DATA: is_layout               TYPE slis_layout_alv.

DATA: col_pos                 TYPE i.

DATA:       g_save(1) TYPE c,
            g_exit(1) TYPE c,
            gx_variant LIKE disvariant,
            g_variant  LIKE disvariant,
            g_repid    LIKE sy-repid.

DATA: gt_titel TYPE lvc_title.

************************************************************************
* SCREEN SELECTION OPTION
************************************************************************
SELECT-OPTIONS BNAME FOR USR02-BNAME DEFAULT SY-UNAME.
PARAMETER PERN  LIKE PA0105-PERNR matchcode object prem .

************************************************************************
* INITIALIZATION
************************************************************************
INITIALIZATION.

SET PARAMETER ID 'PER' FIELD pern.
************************************************************************
* START-OF-SELECTION
************************************************************************
START-OF-SELECTION.

    PERFORM GET-NAME.

END-OF-SELECTION.

Perform Format-Data.

************************************************************************
* FORM PROCESSING
************************************************************************
FORM GET-NAME.

*  Retrives all Users Ids from selection screen
      SELECT * FROM USR21
        WHERE BNAME IN BNAME.
        MOVE USR21-BNAME        TO ITAB-USER-USERID.
        MOVE USR21-PERSNUMBER   TO ITAB-USER-USERN.
        MOVE USR21-ADDRNUMBER   TO ITAB-USER-AD_ADDRNUM.
        APPEND ITAB-USER.
      ENDSELECT.

* Formats all Valid User Id
     LOOP AT ITAB-USER.
        CLEAR: I_TAB, WS-VALID-FL.
        AT NEW USERID.
        ENDAT.
        CLEAR:   ADCP, ADRP, ITAB_S, ITAB_R,
                 USER-NAME, USER-ID, AGR_TEXTS, USR11.
        REFRESH: ITAB_R.

        IF ITAB-USER-USERN = SPACE.
           MOVE 'User Name NOT Available'  TO USER-NAME.
        ELSE.

* Retrives Department
          SELECT * FROM ADCP
             WHERE ADDRNUMBER EQ ITAB-USER-AD_ADDRNUM.
          ENDSELECT.

* Retrives User Id Name
          SELECT * FROM ADRP
             WHERE PERSNUMBER EQ ITAB-USER-USERN.
          ENDSELECT.
          IF SY-SUBRC EQ 0.
           MOVE ADRP-NAME_LAST   TO I_TAB-LNAME.
           MOVE ADRP-NAME_FIRST  TO I_TAB-FNAME.
           MOVE ITAB-USER-USERID TO I_TAB-USERID.
          ENDIF.
        ENDIF.

        PERFORM GET-PA-DATA.

* Retrives Role Data Based on User ID
       SELECT * FROM AGR_USERS
         WHERE UNAME    EQ ITAB-USER-USERID
           AND FROM_DAT LE SY-DATUM
           AND TO_DAT   GE SY-DATUM.

           MOVE  AGR_USERS-AGR_NAME   TO I_TAB-ROLE.
           WRITE AGR_USERS-FROM_DAT   TO I_TAB-BEGDA.
           WRITE AGR_USERS-TO_DAT     TO I_TAB-ENDDA.
           IF WS-VALID-FL EQ SPACE.
              COLLECT I_TAB.
           ENDIF.
         ENDSELECT.

    ENDLOOP.

ENDFORM.

*----------------*
FORM GET-PA-DATA.

CLEAR:    I0001, PA0105.
REFRESH:  I0001.

  IF NOT ( PERN IS INITIAL ).
     SELECT * FROM PA0105
       WHERE ENDDA GE SY-DATUM
         AND PERNR EQ PERN
         AND USRTY EQ '0001'      "System user name (SY-UNAME)
         AND USRID EQ ITAB-USER-USERID.
     ENDSELECT.
     IF SY-SUBRC NE 0.
        MOVE 'X'  TO WS-VALID-FL.
     ENDIF.
   ELSE.
    SELECT * FROM PA0105
       WHERE ENDDA GE SY-DATUM
         AND USRTY EQ '0001'      "System user name (SY-UNAME)
         AND USRID EQ ITAB-USER-USERID.
    ENDSELECT.
  ENDIF.
  IF SY-SUBRC EQ 0.
     MOVE PA0105-PERNR   TO   I_TAB-PERNR.
     CALL FUNCTION 'HR_READ_INFOTYPE'
       EXPORTING
         PERNR             =  PA0105-PERNR
         INFTY             =  '0001'
         BEGDA             =  SY-DATUM
         ENDDA             =  SY-DATUM
       TABLES
         INFTY_TAB         =  I0001
       EXCEPTIONS
         INFTY_NOT_FOUND   =  1
         OTHERS            =  2.

      IF SY-SUBRC EQ 0.
         LOOP AT I0001.
         ENDLOOP.
           MOVE I0001-PLANS    TO   I_TAB-POSITION.
           MOVE I0001-WERKS    TO   I_TAB-WERKS.
           MOVE I0001-VDSK1    TO   I_TAB-ORG.
           SELECT * FROM hrp1000  WHERE plvar EQ '01'
                             AND   otype EQ 'S'
                             AND   objid EQ I0001-PLANS .
           ENDSELECT.
           IF sy-subrc EQ 0.
              MOVE hrp1000-stext   TO    I_TAB-POSITION.
           ENDIF.
      ENDIF.
  ENDIF.
ENDFORM.

*---------------------------*
FORM format-data.

*Last Name
  col_pos = col_pos + 1.
  fieldcat_ln-seltext_s      = 'Last Name'.
  fieldcat_ln-seltext_m      = 'Last Name'.
  fieldcat_ln-seltext_l      = 'Last Name'.

  fieldcat_ln-tabname        = 'I_TAB'.
  fieldcat_ln-fieldname      = 'LNAME'.

  fieldcat_ln-lowercase      = 'X'.
  fieldcat_ln-datatype       = 'CHAR'.
  fieldcat_ln-inttype        = 'C'.
  fieldcat_ln-intlen         =  40.

  fieldcat_ln-key            = space.
  fieldcat_ln-do_sum         = space.
  fieldcat_ln-col_pos        = col_pos.
  fieldcat_ln-qfieldname     = space.
  fieldcat_ln-hotspot        = ' '.

  APPEND fieldcat_ln   TO fieldcat.

  CLEAR: fieldcat_ln.

*First Name
  col_pos = col_pos + 1.
  fieldcat_ln-seltext_s      = 'First Name'.
  fieldcat_ln-seltext_m      = 'First Name'.
  fieldcat_ln-seltext_l      = 'First Name'.

  fieldcat_ln-tabname        = 'I_TAB'.
  fieldcat_ln-fieldname      = 'FNAME'.

  fieldcat_ln-lowercase      = 'X'.
  fieldcat_ln-datatype       = 'CHAR'.
  fieldcat_ln-inttype        = 'C'.
  fieldcat_ln-intlen         =  40.

  fieldcat_ln-key            = space.
  fieldcat_ln-do_sum         = space.
  fieldcat_ln-col_pos        = col_pos.
  fieldcat_ln-qfieldname     = space.
  fieldcat_ln-hotspot        = ' '.

  APPEND fieldcat_ln   TO fieldcat.

  CLEAR: fieldcat_ln.

*Employee Number
  col_pos = col_pos + 1.
  fieldcat_ln-seltext_s      = 'Personel #'.
  fieldcat_ln-seltext_m      = 'Personel #'.
  fieldcat_ln-seltext_l      = 'Personel #'.

  fieldcat_ln-tabname     = 'I_TAB'.
  fieldcat_ln-fieldname   = 'PERNR'.

  fieldcat_ln-key         = space.
  fieldcat_ln-do_sum      = space.
  fieldcat_ln-col_pos     = col_pos.
  fieldcat_ln-qfieldname  = space.
  fieldcat_ln-hotspot     = ' '.

  APPEND fieldcat_ln   TO fieldcat.

  CLEAR: fieldcat_ln.

*User ID
  col_pos = col_pos + 1.
  fieldcat_ln-seltext_s      = 'User ID'.
  fieldcat_ln-seltext_m      = 'User ID'.
  fieldcat_ln-seltext_l      = 'User ID'.

  fieldcat_ln-tabname        = 'I_TAB'.
  fieldcat_ln-fieldname      = 'USERID'.

  fieldcat_ln-lowercase      = 'X'.
  fieldcat_ln-datatype       = 'CHAR'.
  fieldcat_ln-inttype        = 'C'.
  fieldcat_ln-intlen         =  10.

  fieldcat_ln-key            = space.
  fieldcat_ln-do_sum         = space.
  fieldcat_ln-col_pos        = col_pos.
  fieldcat_ln-qfieldname     = space.
  fieldcat_ln-hotspot        = ' '.

  APPEND fieldcat_ln   TO fieldcat.

  CLEAR: fieldcat_ln.

*Security Role
  col_pos = col_pos + 1.
  fieldcat_ln-seltext_s      = 'Security Role'.
  fieldcat_ln-seltext_m      = 'Security Role'.
  fieldcat_ln-seltext_l      = 'Security Role'.

  fieldcat_ln-tabname     = 'I_TAB'.
  fieldcat_ln-fieldname   = 'ROLE'.

  fieldcat_ln-key         = space.
  fieldcat_ln-do_sum      = space.
  fieldcat_ln-col_pos     = col_pos.
  fieldcat_ln-qfieldname  = space.
  fieldcat_ln-hotspot     = ' '.

  fieldcat_ln-lowercase      = 'X'.
  fieldcat_ln-datatype       = 'CHAR'.
  fieldcat_ln-inttype        = 'C'.
  fieldcat_ln-intlen         =  25.

  APPEND fieldcat_ln   TO fieldcat.

  CLEAR: fieldcat_ln.


* Valid From
  col_pos = col_pos + 1.
  fieldcat_ln-seltext_s      = 'Valid From'.
  fieldcat_ln-seltext_m      = 'Valid From'.
  fieldcat_ln-seltext_l      = 'Valid From'.

  fieldcat_ln-tabname     = 'I_TAB'.
  fieldcat_ln-fieldname   = 'BEGDA'.

  fieldcat_ln-key         = space.
  fieldcat_ln-do_sum      = space.
  fieldcat_ln-col_pos     = col_pos.
  fieldcat_ln-qfieldname  = space.
  fieldcat_ln-hotspot     = ' '.

  APPEND fieldcat_ln   TO fieldcat.

  CLEAR: fieldcat_ln.

* Valid To
  col_pos = col_pos + 1.
  fieldcat_ln-seltext_s      = 'Valid To'.
  fieldcat_ln-seltext_m      = 'Valid To'.
  fieldcat_ln-seltext_l      = 'Valid To'.

  fieldcat_ln-tabname     = 'I_TAB'.
  fieldcat_ln-fieldname   = 'ENDDA'.

  fieldcat_ln-key         = space.
  fieldcat_ln-do_sum      = space.
  fieldcat_ln-col_pos     = col_pos.
  fieldcat_ln-qfieldname  = space.
  fieldcat_ln-hotspot     = ' '.

  APPEND fieldcat_ln   TO fieldcat.

  CLEAR: fieldcat_ln.


* Position
  col_pos = col_pos + 1.
  fieldcat_ln-seltext_s      = 'Position'.
  fieldcat_ln-seltext_m      = 'Position'.
  fieldcat_ln-seltext_l      = 'Position'.

  fieldcat_ln-tabname     = 'I_TAB'.
  fieldcat_ln-fieldname   = 'POSITION'.

  fieldcat_ln-key         = space.
  fieldcat_ln-do_sum      = space.
  fieldcat_ln-col_pos     = col_pos.
  fieldcat_ln-qfieldname  = space.
  fieldcat_ln-hotspot     = ' '.

  fieldcat_ln-lowercase      = 'X'.
  fieldcat_ln-datatype       = 'CHAR'.
  fieldcat_ln-inttype        = 'C'.
  fieldcat_ln-intlen         =  20.

  APPEND fieldcat_ln   TO fieldcat.

  CLEAR: fieldcat_ln.

*Pers Area
  col_pos = col_pos + 1.
  fieldcat_ln-seltext_s      = 'Pers Area'.
  fieldcat_ln-seltext_m      = 'Pers Area'.
  fieldcat_ln-seltext_l      = 'Pers Area'.

  fieldcat_ln-tabname        = 'I_TAB'.
  fieldcat_ln-fieldname      = 'WERKS'.

  fieldcat_ln-lowercase      = 'X'.
  fieldcat_ln-datatype       = 'CHAR'.
  fieldcat_ln-inttype        = 'C'.
  fieldcat_ln-intlen         =  4.

  fieldcat_ln-key            = space.
  fieldcat_ln-do_sum         = space.
  fieldcat_ln-col_pos        = col_pos.
  fieldcat_ln-qfieldname     = space.
  fieldcat_ln-hotspot        = ' '.

  APPEND fieldcat_ln   TO fieldcat.

  CLEAR: fieldcat_ln.

*Org key
  col_pos = col_pos + 1.
  fieldcat_ln-seltext_s      = 'Org Key'.
  fieldcat_ln-seltext_m      = 'Org Key'.
  fieldcat_ln-seltext_l      = 'Org Key'.

  fieldcat_ln-tabname        = 'I_TAB'.
  fieldcat_ln-fieldname      = 'ORG'.

  fieldcat_ln-lowercase      = 'X'.
  fieldcat_ln-datatype       = 'CHAR'.
  fieldcat_ln-inttype        = 'C'.
  fieldcat_ln-intlen         =  10.

  fieldcat_ln-key            = space.
  fieldcat_ln-do_sum         = space.
  fieldcat_ln-col_pos        = col_pos.
  fieldcat_ln-qfieldname     = space.
  fieldcat_ln-hotspot        = ' '.

  APPEND fieldcat_ln   TO fieldcat.

  CLEAR: fieldcat_ln.

  SORT I_TAB BY WERKS LNAME.

  PERFORM fill-header.

  eventcat_ln-name = 'TOP_OF_PAGE'.
  eventcat_ln-form = 'WRITE_HEADERS'.
  APPEND eventcat_ln TO eventcat.

  is_layout-colwidth_optimize = 'X'.

  g_repid = sy-repid.

* Call ABAP List Viewer
  CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
       EXPORTING
            i_callback_program = g_repid
            is_layout          = is_layout
            it_fieldcat        = fieldcat
            i_save             = g_save
            it_events          = eventcat
       TABLES
            t_outtab           = i_tab.

ENDFORM.

*-----------------*
FORM fill-header.

data:    v_system(40),
         v_site(40),
         v_rundate(40),
         v_job(40),
         v_title(40),
         v_runtime(40).

  CONCATENATE 'SID/Client:' sy-sysid '/' sy-mandt INTO v_system
               SEPARATED BY space.

  CONCATENATE sy-uzeit(2) sy-uzeit+2(2) sy-uzeit+4(2) INTO v_runtime
              SEPARATED BY ':'.

  CONCATENATE 'Run Time:' v_runtime INTO v_runtime SEPARATED BY space.


  CLEAR header_alv_wa.
  header_alv_wa-typ         = 'H'.
  header_alv_wa-info        = sy-title.
  APPEND header_alv_wa TO header_alv.

  CLEAR header_alv_wa.
  header_alv_wa-info        = 'Program   : ZHRKOPAR_SECURITY_2'.
  header_alv_wa-typ         = 'A'.
  APPEND header_alv_wa TO header_alv.

  CLEAR header_alv_wa.
  header_alv_wa-typ         = 'A'.
  header_alv_wa-info        = v_system.
  header_alv_wa-info+0(10)  = 'Run Date'.
  WRITE sy-datum TO header_alv_wa-info+12(10).
  header_alv_wa-info+25     = v_runtime.
  APPEND header_alv_wa TO header_alv.

  CLEAR header_alv_wa.
  header_alv_wa-typ         = 'A'.
  header_alv_wa-info        = v_system.
  APPEND header_alv_wa TO header_alv.

ENDFORM.

*-----------------*
FORM write_headers.

  CALL FUNCTION 'REUSE_ALV_COMMENTARY_WRITE'
       EXPORTING
            it_list_commentary = header_alv.

ENDFORM.
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    Russian ABAP Developer's Club Forum Index -> Security and Monitoring All times are GMT + 4 Hours
Page 1 of 1

 
Jump to:  
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.