Application Development and Automation Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

Authorization restriction for executing the ABAP queries

Former Member
0 Likes
747

Hi

In ABAP queiries how the restriction can be done for where users should not execute /authorized

of other plant or company code - Projects/ WBS/NWA and its related components. I tried the following methods but not working - seems something is missing .

method 1) restricting based on the profit center ( free coding )

AUTHORITY-CHECK OBJECT 'C_PRPS_PRC'

ID 'PRCTR' FIELD PROJ-PRCTR

ID 'PS_ACTVT' FIELD '02'.

(or)

method 2 -(free coding)

*---Authorization for Company code entered by the users.

*---This code will restrict users to see data for company

*---codes which they are not authorized to.

*---Select all the company codes based upon selection entered by the

*---user

SELECT bukrs

FROM t001

INTO TABLE li_bukrs

WHERE bukrs IN z_bukrs.

IF sy-subrc EQ 0.

*---Clear Screen variable for Company code

CLEAR z_bukrs.

REFRESH z_bukrs.

*---Filter and prepare Select options for Company code table to be

*---passed to query. Table will only have values of company codes he is

*---authorized to for display.

LOOP AT li_bukrs INTO lwa_bukrs.

AUTHORITY-CHECK OBJECT 'F_BKPF_BUK'

ID 'BUKRS' FIELD lwa_bukrs

ID 'ACTVT' FIELD '03'.

IF sy-subrc = 0.

z_bukrs-sign = 'I'.

z_bukrs-option = 'EQ'.

z_bukrs-low = lwa_bukrs.

z_bukrs-high = space.

APPEND z_bukrs.

ELSE.

lv_flag = 'X'.

ENDIF.

ENDLOOP.

*---Give warning message to the user in case he is not authorized to see

*---data for all the company codes that he has entered.

IF lv_flag = 'X'.

MESSAGE ID 'ZF_MSS_FNG' TYPE 'W' NUMBER '015'.

ENDIF.

ENDIF.

Just make sure that Z_BUKRS field is available in selection tab.

Also, declare below mentioned variables in INITIALIZATION.

DATA: li_bukrs TYPE TABLE OF bukrs,

lwa_bukrs TYPE bukrs,

lv_flag TYPE c.

Kindly help if there is missing anything on the above or is there any other alternative.

Regards

PP

Hi

In ABAP queiries how the restriction can be done for where users should not execute /authorized

of other plant or company code - Projects/ WBS/NWA and its related components. I tried the following methods but not working - seems something is missing .

method 1) restricting based on the profit center ( free coding )

AUTHORITY-CHECK OBJECT 'C_PRPS_PRC'

ID 'PRCTR' FIELD PROJ-PRCTR

ID 'PS_ACTVT' FIELD '02'.

(or)

method 2 -(free coding)

*---Authorization for Company code entered by the users.

*---This code will restrict users to see data for company

*---codes which they are not authorized to.

*---Select all the company codes based upon selection entered by the

*---user

SELECT bukrs

FROM t001

INTO TABLE li_bukrs

WHERE bukrs IN z_bukrs.

IF sy-subrc EQ 0.

*---Clear Screen variable for Company code

CLEAR z_bukrs.

REFRESH z_bukrs.

*---Filter and prepare Select options for Company code table to be

*---passed to query. Table will only have values of company codes he is

*---authorized to for display.

LOOP AT li_bukrs INTO lwa_bukrs.

AUTHORITY-CHECK OBJECT 'F_BKPF_BUK'

ID 'BUKRS' FIELD lwa_bukrs

ID 'ACTVT' FIELD '03'.

IF sy-subrc = 0.

z_bukrs-sign = 'I'.

z_bukrs-option = 'EQ'.

z_bukrs-low = lwa_bukrs.

z_bukrs-high = space.

APPEND z_bukrs.

ELSE.

lv_flag = 'X'.

ENDIF.

ENDLOOP.

*---Give warning message to the user in case he is not authorized to see

*---data for all the company codes that he has entered.

IF lv_flag = 'X'.

MESSAGE ID 'ZF_MSS_FNG' TYPE 'W' NUMBER '015'.

ENDIF.

ENDIF.

Just make sure that Z_BUKRS field is available in selection tab.

Also, declare below mentioned variables in INITIALIZATION.

DATA: li_bukrs TYPE TABLE OF bukrs,

lwa_bukrs TYPE bukrs,

lv_flag TYPE c.

Kindly help if there is missing anything on the above or is there any other alternative.

Regards

PP

3 REPLIES 3
Read only

former_member214857
Contributor
0 Likes
611

Hi

You are right, if you proceed as sample below you will check authorization for specific user:

AUTHORITY-CHECK OBJECT 'C_PRPS_PRC'
ID 'PRCTR' FIELD PROJ-PRCTR
ID 'PS_ACTVT' FIELD '02'.

IF sy-subrc NE 0.
  EXIT
ENDIF.

Kind regards

Read only

0 Likes
611

Hi Carlos

I added the logic as u mentioned and set the breakpoint to test the query but the query is not stopping and resulting for all.

Not sure what is missing.

Kindly help to prove this authorization check working.

Regards

PP

Read only

Former Member
0 Likes
611

Hi,

Kindly help if there is missing anything on the above or is there any other alternative.

Carlos is right about the Authorization check.

If you further wants to explore something extra, just visit these links:

1. http://help.sap.com/saphelp_NW70EHP1core/helpdata/en/52/671449439b11d1896f0000e8322d00/frameset.htm

2. http://help.sap.com/saphelp_wp/helpdata/en/52/67129f439b11d1896f0000e8322d00/content.htm

3. http://help.sap.com/crmcg_en/5c/deaa74d3d411d3970a0000e82de14a/content.htm

4. http://www.sap-img.com/bc042.htm

May this information helps you.

Regards.

Deepak Sharma.