3
votes

I have a custom report with the following selection screen. It allows the user to input value ranges when executing the report.

enter image description here

I want to carryout an authorization check to the inputs that the user has entered.

For this I use AUTHORITY-CHECK OBJECT with the user and the selection field;

  AUTHORITY-CHECK OBJECT 'P_PYEVDOC'
  FOR USER sy-uname
  ID 'BUKRS' FIELD pnpbukrs-low
  .

Where pnpbukrs is the selection field that the user has entered.

How do I do this check properly for all possible combinations that the user might give?

When I provide the direct pnpbukrs field, the Options in the selection field is considered in the auth. check giving errors.

When I user pnpbukrs-low, only a single value is used in the auth. check making a check bypass.

2

2 Answers

5
votes

In case the selection table contains generic entries, intervals, excluded entries or excluded intervals, you should first get the list of companies corresponding to the selection table (with WHERE ... IN selectiontable ; IN will deal with all these kinds of filters), then do an authority-check on each of the real companies.

For instance, I assume that the companies are to be taken from the table T001 :

SELECT bukrs FROM t001 WHERE bukrs IN pnpbukrs INTO TABLE @DATA(companies).

LOOP AT companies ASSIGNING FIELD-SYMBOL(<company>).
  AUTHORITY-CHECK OBJECT 'P_PYEVDOC'
                ID 'BUKRS' FIELD <company>.
  IF sy-subrc <> 0.
    " this company is not authorized, do something
  ENDIF.
ENDLOOP.

PS #1: If the goal is only to select the authorized data from a given table, you may use the class CL_AUTH_OBJECTS_TO_SQL (>= 7.50)

PS #2: for AUTHORITY-CHECK, it's useless to mention FOR USER sy-uname as it's the default setting.

4
votes

For range with any data

Go for @Sandra Rossi answer

For range filled with LOW component only:

Try looping over the select-options field and make an authority check for each iteration:

LOOP AT pnpbukrs ASSIGNING FIELD-SYMBOL(<line>).
    AUTHORITY-CHECK OBJECT 'P_PYEVDOC'
                    FOR USER sy-uname
                    ID 'BUKRS'
                    FIELD <line>-low.
ENDLOOP.