
AUTHORITY-CHECK IN ABAP:
Is a concept which enables or allow users to perform certain functions/ activities in the SAP system
So, we will look for an example of such activity:
To create a material or sales order I suppose to have authorization
System checks whether I am authorized for the task or not –then only the system will proceed further
Suppose in a general scenario while talking a leave the manager needs to authorize the request of our leave approval .
What happens in SAP ?
In SAP basis person will assign the authorization object to user id to proceed it further
Terminologies in authority-check.
Here the hierarchy goes like
T-CODES:
OVERVIEW:
The first and foremost thing is we need to check for authorization object class
Which is a container for authorization object
Once we create the object --> we need to assign the filed
Scenario:
Suppose we are using MM01 transaction to create a material, and we get an error
At this moment we can inform BASIS people to check for the authorization in case we need any.
Step;
2.Put breakpoint on statement AUTHORITY-CHECK .
3.If we provide the field in SU20
Or else it will give sy-subrc 12 indicating we are not authorized to create the material
The filed ACTVT has some permitted values—click on the status icon beside ACTVT
01- IT IS CREATE
02- CHANGE
03- DISPLAY
7.So, in the ACTVT we saw 02- for change and same for display
The ACTVT holds value-03 and here we can see the field value
Now let's take real time scenario:
Implementing authorization checks in ABAP program is crucial to ensure that only authorized users can perform operations like INSERT, UPDATE, or DELETE on your cylinder data, which includes delivery charges, stock, and cylinder types. Here's how you can set up and demonstrate an AUTHORITY-CHECK based on the cylinder batch ID:
Steps:
2.Save it
3.Crate the authorization field
4.Select the operation you want to do on DB
.
5.Select the activity and save it
Scenario – in the report we have stock table and particular user can delete update insert Once we are done with auth object—basis person will create a role using t code pfcg
After assigning role
code :
REPORT zpd_rp_auth_chek.
TYPES : BEGIN OF lty_BID,
cylinder_batch_id TYPE zpd_de_batch_id,
END OF lty_BID.
DATA : lwa_data TYPE zpd_t_stock.
DATA : zpd_de_batch_id TYPE TABLE OF lty_BID.
DATA : lwa_bid TYPE lty_BID.
DATA : lt_bid TYPE TABLE OF lty_bid.
TYPES : BEGIN OF lty_display,
delivery_charge TYPE zpd_de_charge,
cylinder_type TYPE zpd_de_cylinder_type,
stock TYPE zpd_de_stock,
END OF lty_display.
DATA : lwa_display TYPE lty_display.
DATA : lv_objectid TYPE cdhdr-objectid.
*DATA : lwa_bid TYPE zpd_t_stock.
PARAMETERS : p_id TYPE zpd_de_batch_id OBLIGATORY.
PARAMETERS : p_charge TYPE zpd_de_charge .
PARAMETERS : p_type TYPE zpd_de_cylinder_type .
PARAMETERS : p_stock TYPE zpd_de_stock MODIF ID a3.
PARAMETERS : p_r1 TYPE c RADIOBUTTON GROUP r1 USER-COMMAND abc .
PARAMETERS : p_r2 TYPE c RADIOBUTTON GROUP r1 .
PARAMETERS : p_r3 TYPE c RADIOBUTTON GROUP r1..
START-OF-SELECTION.
*Insert
IF p_r1 = 'X'.
AUTHORITY-CHECK OBJECT 'ZAUTHBID'
ID 'ACTVT' FIELD '01'.
ENDIF.
IF sy-subrc <> 0 .
MESSAGE e005(zmsg_auth).
lwa_data-cylinder_batch_id = p_id.
lwa_data-delivery_charge = p_charge.
lwa_data-cylinder_type = p_type.
lwa_data-stock = p_stock.
INSERT zpd_t_stock FROM lwa_data.
IF sy-subrc = 0.
WRITE : TEXT-000.
ELSE.
WRITE : TEXT-001.
ENDIF.
ENDIF.
*Delete.
IF p_r2 = 'X'.
AUTHORITY-CHECK OBJECT 'ZAUTHBID'
ID 'ACTVT' FIELD '02'.
ENDIF.
IF sy-subrc <> 0 .
MESSAGE e007(zmsg_auth).
SELECT SINGLE * FROM zpd_t_stock INTO lwa_data WHERE cylinder_batch_id = p_id.
lwa_data-cylinder_batch_id = p_id.
DELETE zpd_t_stock FROM lwa_data.
IF sy-subrc = 0.
WRITE : TEXT-003 , ' :' , p_id.
ENDIF.
ENDIF.
*Update
IF p_r3 = 'X'.
AUTHORITY-CHECK OBJECT 'ZAUTHBID'
ID 'ACTVT' FIELD '06'.
ENDIF.
IF sy-subrc <> 0 .
MESSAGE e006(zmsg_auth).
lwa_data-cylinder_batch_id = p_id.
lwa_data-delivery_charge = p_charge.
lwa_data-cylinder_type = p_type.
lwa_data-stock = p_stock.
UPDATE zpd_t_stock FROM lwa_data.
IF sy-subrc = 0.
WRITE : TEXT-004, ' :' , p_id.
ENDIF.
ENDIF.
AT SELECTION-SCREEN.
IF p_r1 = 'X'.
SELECT cylinder_batch_id
FROM zpd_t_stock
INTO TABLE lt_bid
WHERE cylinder_batch_id = p_id.
IF sy-subrc = 0.
MESSAGE e003(zmsg_auth) WITH p_id.
ENDIF.
ENDIF.
IF p_r2 = 'X'.
SELECT SINGLE cylinder_batch_id
FROM zpd_t_stock
INTO lwa_bid
WHERE cylinder_batch_id = p_id.
IF sy-subrc NE 0.
MESSAGE e004(zmsg_auth) WITH p_id.
ENDIF.
ENDIF.
IF p_r3 = 'X'.
SELECT SINGLE cylinder_batch_id
FROM zpd_t_stock
INTO lwa_bid
WHERE cylinder_batch_id = p_id.
IF sy-subrc NE 0.
MESSAGE e004(zmsg_auth) WITH p_id.
ELSE.
SELECT SINGLE delivery_charge stock
FROM zpd_t_stock
INTO lwa_display
WHERE cylinder_batch_id = p_id.
ENDIF.
ENDIF.
AT SELECTION-SCREEN OUTPUT.
LOOP AT SCREEN.
IF screen-group1 = 'A1' OR screen-group1 = 'A2' OR screen-group1 = 'A3' OR screen-group1 = 'A4'.
screen-active = 0.
MODIFY SCREEN.
ENDIF.
ENDLOOP.
IF p_r3 = 'X'.
p_type = lwa_display-cylinder_type.
p_charge = lwa_display-delivery_charge.
p_stock = lwa_display-stock.
ENDIF.
Same in case of delete ..
So now lets dicuss about the key parameters present in the authorization
SAP_ALL :
Here I have authorization for SAP_ALL means I have sap all system authorization
IN CASE:
Even though I have SAP_ALL authorizations .then why is it not possible to create the records in previous program?
When we created object, we need to add that new object in SAP_ALL
And SAP_ALL has all many predefined authorizations
To add that we need to regenerate SAP_ALL
So once we regenerate it – it will be the part of SAP_ALL
Now if we try to insert a record it will show – sy-subrc will be 0
Suppose I want to assign auth for a custom field delivery charge – only certain people can see the delivery charges change the delivery charges
2.Su20 – create field
3.Su21 create auth obj class—and use already existing class
4.Here I'm providing authorization on displaying the details of delivery charges
Code :
TYPES : BEGIN OF lty_display,
delivery_charge TYPE zpd_de_charge,
cylinder_type TYPE zpd_de_cylinder_type,
stock TYPE zpd_de_stock,
END OF lty_display.
DATA : lt_data TYPE TABLE OF lty_display,
wa TYPE lty_display.
PARAMETERS : p_dc TYPE zpd_de_stock.
START-OF-SELECTION.
SELECT delivery_charge
cylinder_type
stock FROM zpd_t_stock
INTO TABLE lt_data
WHERE delivery_charge = p_dc .
LOOP AT lt_data INTO wa.
WRITE : wa-delivery_charge , wa-cylinder_type , wa-stock .
ENDLOOP.
AT SELECTION-SCREEN .
AUTHORITY-CHECK OBJECT 'ZDELICHRG'
ID 'ACTVT' FIELD '03'
ID 'DELIVCHARG' FIELD P_DC.
IF SY-SUBRC <> 0.
MESSAGE e008(ZMSG_AUTH) WITH p_dc.
ENDIF.
5.We can see that we are getting sy-subrc = 12
6.So when we try to display the records with particular delivery charge we get an error
Here are some simple conclusion points:
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
11 | |
8 | |
5 | |
5 | |
4 | |
4 | |
3 | |
2 | |
2 | |
2 |