ABAP-get the organizational structure permission of a user

Source: Internet
Author: User
Tags format definition

In daily maintenance, you often need a list of organizational structure permissions. in SAP, You need to view permissions in the role, which is inconvenient, therefore, the following is a list of user organizational structure permissions. The Code is as follows (for your reference)

*&---------------------------------------------------------------------*
* & Report zorg_levels_au *
*&*
*&---------------------------------------------------------------------*
*&---------------------------------------------------------------------*
Report zorg_levels_au message-ID Dev.
Type-pools: slis.
Tables: usr02.
Data: Begin of gt_1252 occurs 100,
Agr_name like agr_1251-agr_name.
Include structure pt1252.
Data: End of gt_1252.
Data db_1252 like gt_1252 occurs 100 with header line.

Data: Begin of gt_au_1_occurs 100.
Include structure pt1251.
Data: End of gt_au_end.

* Organization level authorization field text
Data: Begin of orgebenen occurs 30.
Include structure usorg_db.
Data: End of orgebenen,
* Organization level authorization field text
Begin of orgtext occurs 30.
Include structure usorg_db.
Data: End of orgtext.

Data: g_var like orgebenen-varbl,
G_ret like sy-subrc,
G_old_field like pt1251-field.
Data: Begin of gt_result occurs 100,
Agr_name like agr_1251-agr_name.
Include structure tprorg1.
Data: End of gt_result.
Data: gt_field type slis_t_fieldcat_alv.

* Define selection screen
Parameters p_user like usr02-bname obligatory.
Parameters p_date like sy-datum obligatory default sy-datum.

Ranges r_group for agr_define-agr_name.

End-of-selection.

Refresh: db_1252, r_group.
R_group-sign = 'I '.
R_group-option = 'eq '.
* Get user's Roles
Select agr_name into (r_group-low) from agr_users where uname = p_user and to_dat> p_date.
Append r_group.
Endselect.

* Get value of roles 'Organizational levels
Select * From agr_1252 into corresponding fields of table db_1252
Where agr_name in r_group
Order by counter.
If sy-subrc Ne 0.
Message i036. "If no matching data exists, the message is prompted to exit.
Exit.
Endif.
Delete db_1252 where varbl = space.
* Call function 'prgn _ 1252_read_org_levels'
* Exporting
* Activity_group = S_STAT-OBJID
* Tables
* Org_levels = db_storg
* Exceptions
* No_data_available = 1
* Others = 2.
Sort db_1252.
* Auth. Object in user master Maintenance
Select * From agr_1251 into corresponding fields of table gt_au_fld
Where agr_name in r_group
Order by field.
Perform init_orgs.
Loop at gt_au_fld.
If gt_au_fld-field ne g_old_field.
G_old_field = gt_au_fld-field.
Perform is_org using g_old_field g_var g_ret.
If g_ret EQ 0.
Read Table db_1252 with key varbl = g_var.
If sy-subrc = 0.
Loop at db_1252 where varbl = g_var.
Append db_1252 to gt_1252.
Endloop.
If sy-subrc Ne 0.
Clear gt_1252.
Gt_1252-varbl = g_var.
Append gt_1252.
Endif.
Else.
Endif.
Endif.
Endif.
Endloop.

Sort gt_1252.
Loop at gt_1252.
Move-corresponding gt_1252 to gt_result.
Perform read_org_text using gt_1252-varbl gt_result-text.
Read Table orgebenen with key varbl = gt_1252-varbl.
If sy-subrc = 0.
Gt_result-fieldname = orgebenen-field.
Endif.
Append gt_result.
Endloop.
Describe table gt_result lines sy-subrc.
If sy-subrc = 0.
Message i036. "If no matching data exists, the message is prompted to exit.
Exit.
Else.
Perform sub_create_field_cat.
Call function 'reuse _ alv_grid_display'
Exporting
It_fieldcat = gt_field []
Tables
T_outtab = gt_result
Exceptions
Program_error = 1
Others = 2.
Endif.

*&---------------------------------------------------------------------*
* & Form sub_create_field_cat
*&---------------------------------------------------------------------*
* Text
*----------------------------------------------------------------------*
Form sub_create_field_cat.
Refresh gt_field.
Perform sub_field_des using:
'''''Agr _ name''' ''x' ''' role name''' 20''' gt_field [],
'''''Varbl''' ''x' ''' org. Level ''10''' gt_field [],
'''''Text''' ''' org. Des. ''40''' ''' gt_field [],
''''''Low''' '''''''''''low value' '40''' ''''gt_field [],
'''''High''' ''' high vlaue ''40''' ''' gt_field [].
Endform. "sub_create_field_cat
*----------------------------------------------------------------------*
* Form: sub_field_des
*----------------------------------------------------------------------*
* Description: Set the fields which will be displayed
*----------------------------------------------------------------------*
* Parameter description *
*---------------------------------------------------------------------*
* Im_ref_field --- Must upper case *
* Im_ref_table --- internal table name *
* Im_fieldname --- Must upper case *
* Im_tabname --- internal table name *
* Im_key --- column with key-color and frozen *
* Im_checkbox --- the column is checkbox *
* Im_dosum --- total, if total, the field must be sumed *
* Im_seltex_l --- column long description of title *
* Im_outputlen --- column output Length
* Re_field: Field Format definition table
*----------------------------------------------------------------------*
* Modification log :*
* Date programmer correction Number *
*-08-10 dev01 add control zero value to show Control Parameters
* Dev01 added controls to check whether control parameters are displayed.
*----------------------------------------------------------------------*
Form sub_field_des using im_ref_field Type C
Im_ref_table Type C
Im_fieldname Type C
Im_tabname Type C
Im_key Type C
Im_checkbox Type C
Im_dosum Type C
Im_seltex_l Type C
Im_outputlen type I
Im_zero Type C
Im_out Type C
Re_field type slis_t_fieldcat_alv.
Data: wa_fieldcat type slis_fieldcat_alv.
Clear wa_fieldcat.
Wa_fieldcat-ref_fieldname = im_ref_field.
Wa_fieldcat-ref_tabname = im_ref_table.
Wa_fieldcat-fieldname = im_fieldname.
A wa_fieldcat-tabname = im_tabname.
Wa_fieldcat-key = im_key.
Wa_fieldcat-checkbox = im_checkbox.
Wa_fieldcat-do_sum = im_dosum.
Wa_fieldcat-no_zero = im_zero.
Wa_fieldcat-no_out = im_out.
The wa_fieldcat-seltext_l = im_seltex_l.
The wa_fieldcat-seltext_m = im_seltex_l.
The wa_fieldcat-seltext_s = im_seltex_l.
Wa_fieldcat-outputlen = im_outputlen.
* Wa_fieldcat-col_pos = im_colpos.
Append wa_fieldcat to re_field.
Endform. "sub_field_des
*&---------------------------------------------------------------------*
* & Form init_orgs
*&---------------------------------------------------------------------*
* Text
*----------------------------------------------------------------------*
Form init_orgs.
Statics: org_init.
If org_init = space.
Org_init = 'x '.
Select * From usorg_db into Table orgebenen.
Sort orgebenen.
Orgtext [] = orgebenen [].
Sort orgtext by Langu varbl.
Endif.
Endform. "init_org
*&---------------------------------------------------------------------*
* & Form is_org
*&---------------------------------------------------------------------*
* Text
*----------------------------------------------------------------------*
* --> Field text
* --> Var text
* --> RET text
*----------------------------------------------------------------------*
Form is_org using field var ret.
Read Table orgebenen with key field = field binary search.
If sy-subrc = 0.
Ret = 0.
Var = orgebenen-varbl.
Else.
Ret = 4.
Clear var.
Endif.
Endform. "is_org

* Text zu einer variablen (orgebene) liefern
Form read_org_text using name like usvart-varbl
Text.
Read Table orgtext with key Langu = sy-Langu varbl = Name
Binary Search.
If sy-subrc = 0.
TEXT = orgtext-vtext.
Else.
Read Table orgtext with key Langu = 'D' varbl = Name
Binary Search.
If sy-subrc = 0.
TEXT = orgtext-vtext.
Else.
TEXT = Name.
Endif.
Endif.
Endform. "read_org_text

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.