08-31-2007 3:27 AM
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
08-31-2007 4: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**
08-31-2007 6:36 AM
Hi Vikas,
Given points. Very helpful answer. But still the issue is not completely resolved.
If it is a single plant, then the logic works fine. But if the user enters multiple plants, then the logic works fine if none of the authorisation wins, but if one of the authorisation wins, then I have to display the report for the plant using the join select statement pasted above. In that case, we need to get a tweak in the code to accomodate the logic. Any help is appreciated
Thanks
Ricky
08-31-2007 6:49 AM
Hi Ricky,
I was in an impression that you want to display the report only when user is authorized for all plants..
Anyways.. In that case, if user has both invalid and valid plants, then we can't give the error message.. what we can do is, is there is even a single plant for which the user is authorized, then give an information message and proceed.. else.. give the error message..
DATA : w_count TYPE i,
w_count1 TYPE i.
After the SELECT on t001w, set a counter.. w_count = sy-dbcnt.
or DESCRIBE TABLE tab_werks LINES w_count.
Now, in the validation part, after the loop statement.. put this..
DESCRIBE TABLE tab_werks LINES w_count1.
IF w_count = w_count1.
MESSAGE exxx WITH Message..
ELSE.
MESSAGE ixxx WITH message..
ENDIF..
Use the same code given above, except add these lines at the places i suggested..
Thanks and Best Regards,
Vikas Bittera.
**Reward if useful**
08-31-2007 7:28 AM
Hi Vikas,
Thanks again. The issue here is that when the count is not equal, it displays the information message "no authorisation" unnecessarily which is a flaw in the coding
Pls suggest some other ways
Thanks
Ricky
08-31-2007 7:33 AM
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**
08-31-2007 6: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>
08-31-2007 7:26 AM
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