Skip to Content
author's profile photo Former Member
Former Member

Authority check in ABAP program

Hello All

I am having some trouble with authority object in ABAP programming

This is the situation.

I have a field "plant" which is a select options in the selection screen.

I have to write an authority-check for this "plant" field in the program and display the report for only the plants for which the user is authorised. There is a select statement in the program which selects all the plants entered. If it is single plant entry and the user is not authorised or the user is not authorised to none of the plants entered for multiple plant entries, an error message should be displayed saying "no authority to display plants x, y, z"

How can I incorporate this logic in the report.

This the current coding

AT SELECTION-SCREEN.

AUTHORITY-CHECK OBJECT 'C_ROUT'

ID 'ACTVT' FIELD '03'

ID 'PLNTY' FIELD 'DUMMY'

ID 'WERKS' FIELD s_werks

ID 'STATU' FIELD 'DUMMY'

ID 'VERWE' FIELD 'DUMMY'.

START-OF-SELECTION.

SELECT amatnr aplnnr aplnal awerks aplnty bstlnr b~stlal INTO TABLE t_mapl FROM mapl AS a INNER JOIN mast AS b

ON amatnr = bmatnr

AND awerks = bwerks

WHERE a~matnr IN s_matnr

AND a~plnnr IN s_plnnr

AND a~plnal IN s_plnal

AND a~werks IN s_werks

AND a~plnty IN s_plnty

AND b~stlnr IN s_stlnr

AND b~stlal IN s_stlal. "(ALT BOM)

Thanks

Ricky

Add a comment
10|10000 characters needed characters exceeded

Assigned Tags

Related questions

2 Answers

  • author's profile photo Former Member
    Former Member
    Posted on Aug 31, 2007 at 03:26 AM

    Hi Ricky,

    to check each individual plant in the selection, you can not use s_plant in the authority chek, here you need to give the value..

    Code like this:

    DATA : BEGIN of t_werks OCCURS 0,

    werks TYPE t001w-werks,

    END OF t_werks.

    DATA : w_text(30) TYPE c.

    AT SELECTION-SCREEN.

    IF NOT s_werks[] IS INITIAL.

    REFRESH t_werks.

    SELECT werks

    FROM t001w

    INTO TABLE t_werks

    WHERE werks IN s_werks.

    IF sy-subrc EQ 0.

    LOOP AT t_werks.

    AUTHORITY CHECK...

    ....

    ID 'WERKS' FIELD t_werks-werks.

    IF sy-subrc EQ 0.

    DELETE t_werks.

    ENDIF.

    ENDLOOP.

    IF NOT t_werks[] IS INITIAL.

    LOOP AT t_werks.

    CONCATENATE t_werks-werks

    ','

    w_text

    INTO w_text.

    ENDLOOP.

    MESSAGE exxx WITH 'No authorisation for '

    w_text.

    ENDIF.

    ENDIF.

    ENDIF.

    Thanks and Best Regards,

    Vikas Bittera.

    **Reward if useful**

    Add a comment
    10|10000 characters needed characters exceeded

    • Former Member Former Member

      Hi Ricky,

      It is not possible to give error message and proceed for further processing too.. this is why i suggested for an information message.. you can use a warning message too..

      Else, the best thing will be, in your report output, display a comment that the user was not authorized for x, y z plants so, report is not displayed for them.. and if user puts all invalid plants, then we have error message to take care of that..

      Thanks and Best Regards,

      Vikas Bittera.

      **Reward if useful**

  • Posted on Aug 31, 2007 at 05:45 AM

    Hi.. RICKY ..

    Check this code. this may be the right one. with Slight changes...

    RANGES : R_WERKS1 FOR T001W-WERKS,

    R_WERKS2 FOR T001W-WERKS.

    AT SELECTION-SCREEN.

    LOOP AT S_WERKS.

    AUTHORITY-CHECK OBJECT 'C_ROUT'

    ID 'ACTVT' FIELD '03'

    ID 'PLNTY' FIELD 'DUMMY'

    ID 'WERKS' FIELD s_werks-LOW

    ID 'STATU' FIELD 'DUMMY'

    ID 'VERWE' FIELD 'DUMMY'.

    IF SY-SUBRC EQ 0.

    APPEND S_WERKS TO R_WERKS1. "plants with authorization

    ELSE.

    APPEND S_WERKS TO R_WERKS2. "plants without authorization

    ENDIF.

    ENDLOOP.

    IF R_WERKS1[] IS INITIAL. "No plant is authorized....

    MESSAGE E100.

    ENDIF.

    START-OF-SELECTION.

    SELECT amatnr aplnnr aplnal awerks aplnty bstlnr b~stlal INTO TABLE t_mapl FROM mapl AS a INNER JOIN mast AS b

    ON amatnr = bmatnr

    AND awerks = bwerks

    WHERE a~matnr IN s_matnr

    AND a~plnnr IN s_plnnr

    AND a~plnal IN s_plnal

    <b>AND a~werks IN R_WERKS1</b>

    AND a~plnty IN s_plnty

    AND b~stlnr IN s_stlnr

    AND b~stlal IN s_stlal. "(ALT BOM)

    <b>reward if Helpful</b>

    Add a comment
    10|10000 characters needed characters exceeded

    • Former Member

      Hi Narayana,

      Your code looks good. But the only issue here is that you are checking the authoriy for s_werks-low only. What about the s_werks-high values.

      If I give a select range as 1000 to 1004, it checks only for 1000 and skips authority check for 1001, 1002, 1003 and 1004 which is not correct

      Thanks

      Ricky

Before answering

You should only submit an answer when you are proposing a solution to the poster's problem. If you want the poster to clarify the question or provide more information, please leave a comment instead, requesting additional details. When answering, please include specifics, such as step-by-step instructions, context for the solution, and links to useful resources. Also, please make sure that you answer complies with our Rules of Engagement.
You must be Logged in to submit an answer.

Up to 10 attachments (including images) can be used with a maximum of 1.0 MB each and 10.5 MB total.