cancel
Showing results for 
Search instead for 
Did you mean: 

Authorization

Former Member
0 Kudos

Hi All,

I have written a module pool program, However i want Authorization to be set up so that if unauthorized User tries to access the transaction, He shouldn't be able to execute it.

Immediately he should get a message saying You are not authorized to execute this transaction.

Thankx in adv.

Accepted Solutions (0)

Answers (3)

Answers (3)

Former Member
0 Kudos

Hai Sanjay

go through this document

In PAI-100

Write Module MOD1.

AUTHORITY-CHECK OBJECT <Object-Name>

ID 'BUKRS' Field V_BUKRS.

ID 'ACTVT' Field '02' '02'--> for Change.

if sy-subrc <> 0.

Message E001 'Your Not Authorized to Enter this Code'.

endif.

Example :

Object Class : FI Field --> F_BKPF_BUK.

AUTHORITY-CHECK OBJECT 'F_BKPF_BUK'

ID 'BUKRS' Field V_BUKRS.

ID 'ACTVT' Field '02'.

For example:

program an AUTHORITY-CHECK.

AUTHORITY-CHECK OBJECT <authorization object>

ID <authority field 1> FIELD <field value 1>.

ID <authority field 2> FIELD <field value 2>.

...

ID <authority-field n> FIELD <field value n>.

The OBJECT parameter specifies the authorization object.

The ID parameter specifies an authorization field (in the authorization object).

The FIELD parameter specifies a value for the authorization field.

The authorization object and its fields have to be suitable for the transaction. In most cases you will be able to use the existing authorization objects to protect your data. But new developments may require that you define new authorization objects and fields.

-


go through report

-


TABLES: TOBJT.

DATA: OBJECT1 LIKE USR12-OBJCT,

OBJECT2 LIKE USR12-OBJCT,

OBJECT3 LIKE USR12-OBJCT,

AUTH1 LIKE USR12-AUTH,

AUTH2 LIKE USR12-AUTH,

AUTH3 LIKE USR12-AUTH,

IND LIKE SY-INDEX,

FLAG TYPE I.

DATA: BEGIN OF INTTAB OCCURS 30,

OBJECT LIKE USR12-OBJCT,

AUTH LIKE USR12-AUTH,

END OF INTTAB.

DATA: BEGIN OF INTTAB2 OCCURS 30,

OBJECT LIKE USR12-OBJCT,

AUTH LIKE USR12-AUTH,

EXPL LIKE TOBJT-TTEXT,

END OF INTTAB2.

DATA: BEGIN OF TABSET OCCURS 30,

SFIELD LIKE TOBJ-FIEL1,

VON(18),

BIS(18),

END OF TABSET.

*read up the authorizations from the user buffer

CALL 'ANALYSE_USERBUFFER'

ID 'AUTHS' FIELD INTTAB-SYS.

*filter out the multipy authorizatios of the same object

SORT INTTAB BY OBJECT.

DO.

IF SY-INDEX = 1.

OBJECT1 = ''. AUTH1 = ''.

READ TABLE INTTAB INDEX 1.

OBJECT2 = INTTAB-OBJECT .AUTH2 = INTTAB-AUTH.

READ TABLE INTTAB INDEX 2.

OBJECT3 = INTTAB-OBJECT.AUTH3 = INTTAB-AUTH.

ELSE.

OBJECT1 = OBJECT2. AUTH1 = AUTH2.

READ TABLE INTTAB INDEX SY-INDEX.

OBJECT2 = INTTAB-OBJECT .AUTH2 = INTTAB-AUTH.

IND = SY-INDEX + 1.

READ TABLE INTTAB INDEX IND.

IF SY-SUBRC = 0.

OBJECT3 = INTTAB-OBJECT.AUTH3 = INTTAB-AUTH.

ELSE.

OBJECT3 = ''. AUTH3 = ''.

IF OBJECT2 = OBJECT1 OR OBJECT2 = OBJECT3.

INTTAB2-OBJECT = OBJECT2.

INTTAB2-AUTH = AUTH2.

SELECT SINGLE * FROM TOBJT

WHERE LANGU = SY-LANGU

AND OBJECT = OBJECT2.

INTTAB2-EXPL = TOBJT-TTEXT.

ENDIF.

EXIT.

ENDIF.

ENDIF.

IF OBJECT2 = OBJECT1 OR OBJECT2 = OBJECT3.

INTTAB2-OBJECT = OBJECT2.

INTTAB2-AUTH = AUTH2.

SELECT SINGLE * FROM TOBJT

WHERE LANGU = SY-LANGU

AND OBJECT = OBJECT2.

INTTAB2-EXPL = TOBJT-TTEXT.

APPEND INTTAB2.

ENDIF.

ENDDO.

SORT INTTAB2 BY OBJECT AUTH.

*display the authorization and description, the objects, fields and

*field values

FLAG = 0. OBJECT1 = ''.

LOOP AT INTTAB2.

IF OBJECT1 = INTTAB2-OBJECT.

WRITE: / INTTAB2-AUTH COLOR 2.

PERFORM FIELD_VALUES.

LOOP AT TABSET.

WRITE: / TABSET-SFIELD, TABSET-VON, TABSET-BIS.

ENDLOOP.

ELSE.

SKIP.

WRITE: / INTTAB2-OBJECT COLOR 3, INTTAB2-EXPL COLOR 3.

PERFORM FIELD_VALUES.

WRITE: / INTTAB2-AUTH COLOR 2.

LOOP AT TABSET.

WRITE: / TABSET-SFIELD, TABSET-VON, TABSET-BIS.

ENDLOOP.

ENDIF.

OBJECT1 = INTTAB2-OBJECT.

ENDLOOP.

----


  • FORM FIELD_VALUES *

----


  • retrieve the field values of an authorization *

----


FORM FIELD_VALUES.

TABLES: USR12.

FIELD-SYMBOLS .

DATA: INTFLAG TYPE I VALUE 0, OFF TYPE I, VTYP, LNG TYPE I,

CLNG(2), GLNG(2), FLDLNG TYPE I VALUE 10, SETFILL.

SELECT SINGLE * FROM USR12

WHERE AUTH = INTTAB2-AUTH

AND OBJCT = INTTAB2-OBJECT

AND AKTPS = 'A'.

SETFILL = 0.

REFRESH TABSET.

CLEAR TABSET.

OFF = 2.

ASSIGN USR12-VALS+OFF(1) TO .

WRITE TO VTYP.

WHILE VTYP <> ' ' AND OFF < USR12-LNG.

OFF = OFF + 1.

CASE VTYP.

WHEN 'F'.

OFF = OFF + 5.

ASSIGN USR12-VALS+OFF(2) TO .

WRITE TO CLNG.

LNG = CLNG.

IF LNG <= 0.

EXIT.

ENDIF.

OFF = OFF + 2.

ASSIGN USR12-VALS+OFF(FLDLNG) TO .

WRITE TO TABSET-SFIELD.

OFF = OFF + FLDLNG.

WHEN 'E'.

ASSIGN USR12-VALS+OFF(LNG) TO .

WRITE TO TABSET-VON.

IF TABSET-VON = SPACE.

TABSET-VON = ''' '''.

ENDIF.

APPEND TABSET.

SETFILL = SETFILL + 1.

TABSET-VON = SPACE.

TABSET-BIS = SPACE.

OFF = OFF + LNG.

WHEN 'G'.

ASSIGN USR12-VALS+OFF(2) TO .

WRITE TO CLNG.

GLNG = CLNG.

OFF = OFF + 2.

ASSIGN USR12-VALS+OFF(LNG) TO .

IF INTFLAG = 0.

WRITE TO TABSET-VON.

WRITE '*' TO TABSET-VON+GLNG.

ELSE.

WRITE TO TABSET-BIS.

WRITE '*' TO TABSET-BIS+GLNG.

INTFLAG = 0.

ENDIF.

APPEND TABSET.

SETFILL = SETFILL + 1.

TABSET-VON = SPACE.

TABSET-BIS = SPACE.

OFF = OFF + LNG.

WHEN 'V'.

INTFLAG = 1.

ASSIGN USR12-VALS+OFF(LNG) TO .

WRITE TO TABSET-VON.

IF TABSET-VON = SPACE.

TABSET-VON = ''' '''.

ENDIF.

OFF = OFF + LNG.

WHEN 'B'.

INTFLAG = 0.

ASSIGN USR12-VALS+OFF(LNG) TO .

WRITE TO TABSET-BIS.

IF TABSET-BIS = SPACE.

TABSET-BIS = ''' '''.

ENDIF.

APPEND TABSET.

SETFILL = SETFILL + 1.

TABSET-VON = SPACE.

TABSET-BIS = SPACE.

OFF = OFF + LNG.

ENDCASE.

ASSIGN USR12-VALS+OFF(1) TO .

WRITE TO VTYP.

ENDWHILE.

ENDFORM.

-


go through this link

http://www.thespot4sap.com/Articles/SAP_ABAP_Queries_Authorizations.asp

also go through this Document

AUTHORITY-CHECK OBJECT object

ID name1 FIELD f1

ID name2 FIELD f2

...

ID name10 FIELD f10.

Effect

Explanation of IDs:

object Field which contains the name of the object for which the authorization is to be checked.

name1 ... Fields which contain the names of the name10 authorization fields defined in the object.

f1 ... Fields which contain the values for which the f10 authorization is to be checked.

AUTHORITY-CHECK checks for one object whether the user has an authorization that contains all values of f (see SAP authorization concept).

You must specify all authorizations for an object and a also a value for each ID (or DUMMY ).

The system checks the values for the ID s by AND-ing them together, i.e. all values must be part of an authorization assigned to the user.

If a user has several authorizations for an object, the values are OR-ed together. This means that if the CHECK finds all the specified values in one authorization, the user can proceed. Only if none of the authorizations for a user contains all the required values is the user rejected.

If the return code SY-SUBRC = 0, the user has the required authorization and may continue.

The return code is modified to suit the different error scenarios. The return code values have the following meaning:

4 User has no authorization in the SAP System for such an action. If necessary, change the user master record.

8 Too many parameters (fields, values). Maximum allowed is 10.

12 Specified object not maintained in the user master record.

16 No profile entered in the user master record.

24 The field names of the check call do not match those of an authorization. Either the authorization or the call is incorrect.

28 Incorrect structure for user master record.

32 Incorrect structure for user master record.

36 Incorrect structure for user master record.

If the return code value is 8 or possibly 24, inform the person responsible for the program. If the return code value is 4, 12, 15 or 24, consult your system administrator if you think you should have the relevant authorization. In the case of errors 28 to 36, contact SAP, since authorizations have probably been destroyed.

Individual authorizations are assigned to users in their respective user profiles, i.e. they are grouped together in profiles which are stored in the user master record.

Note

Instead of ID name FIELD f , you can also write ID name DUMMY . This means that no check is performed for the field concerned.

The check can only be performed on CHAR fields. All other field types result in 'unauthorized'.

Example

Check whether the user is authorized for a particular plant. In this case, the following authorization object applies:

Table OBJ : Definition of authorization object

M_EINF_WRK

ACTVT

WERKS

Here, M_EINF_WRK is the object name, whilst ACTVT and WERKS are authorization fields. For example, a user with the authorizations

M_EINF_WRK_BERECH1

ACTVT 01-03

WERKS 0001-0003 .

can display and change plants within the Purchasing and Materials Management areas.

Such a user would thus pass the checks

AUTHORITY-CHECK OBJECT 'M_EINF_WRK'

ID 'WERKS' FIELD '0002'

ID 'ACTVT' FIELD '02'.

AUTHORITY-CHECK OBJECT 'M_EINF_WRK'

ID 'WERKS' DUMMY

ID 'ACTVT' FIELD '01':

but would fail the check

AUTHORITY-CHECK OBJECT 'M_EINF_WRK'

ID 'WERKS' FIELD '0005'

ID 'ACTVT' FIELD '04'.

Thanks & Regards

Sreenivasulu P

Former Member
0 Kudos

depends on what parameter u want the authorization to be done. Say for ex; Sales office (VKBUR) the SAP standard authorization object would be V_VBKA_VKO.

Syntax for authorization check is.

AUTHORITY-CHECK OBJECT object

ID name1 FIELD f1

ID name2 FIELD f2

...

ID name10 FIELD f10.

you should do this before any processing is done so that user gets this message at the very begining of execution of report.

former_member181962
Active Contributor
0 Kudos

use this statement:

AUTHORITY-CHECK OBJECT object

ID name1 FIELD f1

ID name2 FIELD f2

...

ID name10 FIELD f10.

if sy-subrc = 4.

message <your message>.

endif.

Former Member
0 Kudos

Hi Ravi,

Do you mean that i have to create a new authorization object which would be as follows

AUTHORITY-CHECK OBJECT 'XYZ'.

ID TCODE FIELD SY-TCODE

ID ACTVT FIELD '16'.

IF SS-SUBRC <> 0.

ENDIF .

former_member181962
Active Contributor
0 Kudos

Hi sanjay,

It depends on your requirement.

If you are trying to authorize the maintennace of some z table, then you need to create a new authority object or else some standard object will be there.

regards,

Ravi