Query Report Tips Part 2 – Mandatory Selection Field And Authorization Check
A small tip on how to set a selection field as mandatory. This is useful when the query report might run on huge database or certain selection field is required in order to get meaningful results.
I show an example below.
In SQ02, click on Extras icon on top, and then go to Selections tab. Click on create button to create a new selection criterion and fill in like below. The extras field need to fill in “OBLIGATORY NO-EXTENSION NO INTERVALS”.
This is what you may see in the report selection. Notice that the field is also set as a single field. If you still want multiple selection field, in the extras, put in parameter “OBLIGATORY” will do.
To add authorization check, as shown in the 1st screen shot, after you create the selection field as mandatory, click on the code icon to write below codes:
AUTHORITY-CHECK OBJECT ‘V_VBAK_VKO’
ID ‘VKORG’ FIELD SALESORG–LOW
ID ‘ACTVT’ FIELD ’03’.
if sy–subrc ne 0.
MESSAGE ‘You are not authorized to Sales Office/Sales Area.’ Type ‘E’.
endif.
AUTHORITY-CHECK OBJECT ‘S_TCODE’
ID ‘TCD’ FIELD ‘VA03’
if sy–subrc ne 0.
MESSAGE ‘You are not authorized to Tcode VA03.’ Type ‘E’.
endif.
Doh! One would think that as an ABAPer I should've guessed myself what 'Extras' is for, but those checkboxes threw me off. It would've been awfully nice of SAP to just provide the checkboxes for this though. Oh well...
Thank you for sharing, it was very helpful!
Hi Alan
I never thought this would be so easy. Once I had to do this and I didn't know this technique so I did this by creating selection screen and then putting some ABAP code 🙂
This is an easy way to make some field mandatory but what if we need to put some authority check logic as well based on this field? Then do we have to stick with ABAP coding?
Thank$
That is easy.
In the 1st screen shot, after you create the selection field as mandatory, click on the code icon to write below codes:
AUTHORITY-CHECK OBJECT 'V_VBAK_VKO'
ID 'VKORG' FIELD SALESORG-LOW
ID 'ACTVT' FIELD '03'.
if sy-subrc ne 0.
MESSAGE 'You are not authorized to Sales Office/Sales Area.' Type 'E'.
endif.
AUTHORITY-CHECK OBJECT 'S_TCODE'
ID 'TCD' FIELD 'VA03'
if sy-subrc ne 0.
MESSAGE 'You are not authorized to Tcode VA03.' Type 'E'.
endif.
Thank you Alan Love. I will try this.
Thank$
Hi Alan,
I am sure this should be known to some guys in the forum but never thought that this could be so useful informative.After reading your post I am sure so many members will be benefited.Thanks for sharing small but powerful tips.
Thanks,
Suman$
Thanks Alan for sharing helpful tool. 🙂
Srinu.
thanks for sharing
Hey Alan,
Its good to know this.. thanks for posting such interesting thing on...
thanks
Best Regards,
Suhaib Bin Aziz
Hi Alan ;
Very useful document, thanks for sharing.
But, is there a control for using of * ? Some genious users benefit from * not to restrict selection.
Regards.
M.Ozgur Unal
Refer to this thread: http://scn.sap.com/thread/589500
Hi,
Very useful information. Thanks for sharing.
Regards,
AKPT