2006 Jun 07 4:11 PM
Hi All,
I am creating a custom table and would like to validate the data when user is entering the data thru SM30 manually and display appropiate status or error messages if the data entered is wrong. Also i have to allow only those users that are assigned for that role to access the table and should be able to Add and Update but not delete any record from the table. This is Urgent as i have to get this done real quick and then test my program on it. Any help will be greatly appreciated.
Thanks in advance,
David.
2006 Jun 07 5:42 PM
Hi Manohar,
So in ur sample code u mean that Extract contains all the fields in the table and wat does ur statement Extract+3(4) is exactly checking there??..
Thanks,
David.
2006 Jun 07 4:23 PM
In the function group you have created there will be Custom includes where you can write your authority checks
2006 Jun 07 4:31 PM
David,
For doing validations you need to make use of modification event
<b>01 Before saving the data in the database</b>
Refer to link for list of events available
<a href="http://help.sap.com/saphelp_47x200/helpdata/en/91/ca9f0ea9d111d1a5690000e82deaaa/frameset.htm">Extended Table Maintenance Events</a>
To control with authorization please refer to the link below.
<a href="http://help.sap.com/saphelp_47x200/helpdata/en/a7/5134d2407a11d1893b0000e8323c4f/frameset.htm">Maintain authorization groups</a>
Refer to this blog for event creations
<a href="https://www.sdn.sap.comhttp://www.sdn.sap.comhttp://www.sdn.sap.com/irj/servlet/prt/portal/prtroot/com.sap.km.cm.docs/library/abap/how%20to%20implement%20events%20in%20table%20maintenance.doc">https://www.sdn.sap.comhttp://www.sdn.sap.comhttp://www.sdn.sap.com/irj/servlet/prt/portal/prtroot/com.sap.km.cm.docs/library/abap/how%20to%20implement%20events%20in%20table%20maintenance.doc</a>
Regds
Manohar
2006 Jun 07 4:58 PM
Hi Manohar,
Any examples for that 01 Event how to write the validations in it??..
Thanks in advance,
David.
2006 Jun 07 5:14 PM
David,
You have an example in this link below.
<a href="http://help.sap.com/saphelp_47x200/helpdata/en/91/ca9f0ba9d111d1a5690000e82deaaa/frameset.htm">Event 01: Before Saving the Data in the Database</a>
Code from example
FORM abc.
DATA: F_INDEX LIKE SY-TABIX. "Index to note the lines found
LOOP AT TOTAL.
IF <ACTION> = desired constant.
READ TABLE EXTRACT WITH KEY <vim_xtotal_key>.
IF SY-SUBRC EQ 0.
F_INDEX = SY-TABIX.
ELSE.
CLEAR F_INDX.
ENDIF.
(make desired changes to the line TOTAL)
MODIFY TOTAL.
CHECK F_INDX GT 0.
EXTRACT = TOTAL.
MODIFY EXTRACT INDEX F_INDX.
ENDIF.
ENDLOOP.
SY-SUBRC = 0.
ENDFORM.
Regds
Manohar
2006 Jun 07 5:23 PM
Hi Manohar,
Thanks for ur help so far..when i click on this event, an include program will come up and u mean i should write a routine with all the validations within that routine.
Thanks,
David.
2006 Jun 07 5:37 PM
Yes, In that include program you should start like this,have written sample code
form VALIDATION.
DATA: F_INDX LIKE SY-TABIX. "Index to note the lines found
LOOP AT TOTAL.
IF <ACTION> = 'U' or <ACTION> = 'I'.
READ TABLE EXTRACT WITH KEY <vim_xtotal_key>.
IF SY-SUBRC EQ 0.
F_INDX = SY-TABIX.
ELSE.
CLEAR F_INDX.
ENDIF.
* (make desired changes to the line TOTAL)
MODIFY TOTAL.
CHECK F_INDX GT 0.
EXTRACT = TOTAL.
MODIFY EXTRACT INDEX F_INDX.
ENDIF.
ENDLOOP.
SY-SUBRC = 0.
loop at extract.
if extract+3(4) ne 'Mano'.
message s001(zfin) with 'Invalid entry'.
vim_abort_saving = 'x'.
exit.
endif.
endloop.
endform. "VALIDATION
Regds
Manohar
2006 Jun 07 5:42 PM
Hi Manohar,
So in ur sample code u mean that Extract contains all the fields in the table and wat does ur statement Extract+3(4) is exactly checking there??..
Thanks,
David.
2006 Jun 07 5:50 PM
You can also do this way, as i did for testing purpose
data : l_ytest like ytest.
loop at extract.
l_ytest = extract.
if l_ytest-FIEL1 ne 'Mano'.
message s001(zfin) with 'Invalid entry'.
vim_abort_saving = 'x'.
exit.
endif.
endloop.
Regds
Manohar
2006 Jun 07 6:06 PM
2006 Jun 07 6:27 PM
Hi Srinivas,
I am bit confused with the code..Can you explain me what exactly you are doing in that code..
Thanks in advance,
David.
2006 Jun 07 6:39 PM
Instead of validations as you wanted to do, in my code I am actually filling in the modified by, modified on date/time fields of the table automatically. But the reason for asking you to look at the code is to showcase the structure of the TOTAL and EXTRACT internal tables that are available to you in the events. They are of the structure your Z table plus the "vimtbflags" structure. If you look at the constants I used (aendern or neuer_eintrag), these are actually constants that are already available to you at that point. Replace 'zztable' with your Z table name, and remove the code where I am updating the fields. You can check the other constants.
Another reason for declaring these local variables is to refer to the fields by their field names rather than the offsets.
Regards,
Srinivas
2006 Jun 07 6:44 PM
Check this code for checking if there are blank values for fields of a Z table.
FORM check_for_blank_keyfields.
DATA: l_field_is_blank.
DATA: BEGIN OF s_zztable.
INCLUDE STRUCTURE zztable.
INCLUDE STRUCTURE vimtbflags.
DATA: END OF s_zztable.
LOOP AT total.
CLEAR s_zztable.
MOVE total TO s_zztable.
CHECK s_zztable-vim_action <> neuer_geloescht
AND s_zztable-vim_action <> update_geloescht
AND s_zztable-vim_action <> dummy_geloescht.
IF s_zztable-field1 IS INITIAL OR
s_zztable-field2 IS INITIAL.
l_field_is_blank = 'X'.
EXIT.
ENDIF.
ENDLOOP.
IF l_field_is_blank = 'X'.
MESSAGE i000 WITH 'Both values should be filled in.'.
sy-subrc = 4.
ELSE.
sy-subrc = 0.
ENDIF.
CLEAR l_field_is_blank.
ENDFORM. " CHECK_FOR_BLANK_KEYFIELDS
2006 Jun 07 8:08 PM
Hi Srinivas,
Can yo u tell me like if there is a field ZStart_date in my table ztable. I want to make sure that the user doesn't enter an invalid date that is the date should not be one already passed or it should be 06/07/2006 or above.Can you tell me how we can modify the above code for that.
Thanks alot for all ur help,
David.
2006 Jun 07 8:16 PM
Is this what you are looking for?
FORM check_for_past_date.
DATA: l_date_in_past.
DATA: BEGIN OF s_zztable.
INCLUDE STRUCTURE zztable.
INCLUDE STRUCTURE vimtbflags.
DATA: END OF s_zztable.
LOOP AT total.
CLEAR s_zztable.
MOVE total TO s_zztable.
IF s_zztable-<b>zstart_date</b> < sy-datum.
l_field_is_blank = 'X'.
EXIT.
ENDIF.
ENDLOOP.
IF l_date_in_past = 'X'.
MESSAGE i000 WITH 'At least one record start date is in the past'.
sy-subrc = 4.
ELSE.
sy-subrc = 0.
ENDIF.
CLEAR l_date_in_past.
ENDFORM. " CHECK_FOR_PAST_DATE
Actually you don't need to check whether the user is modifying, inserting deleting or viewing the data. You need this check all the time. So I removed the check statement for those german constants!!!
Message was edited by: Srinivas Adavi
2006 Jun 07 8:27 PM
Hi Srinivas,
Thanks alot for all your help so far..Actually i have to do the following i have to validate fields like G/L Account, start date, enddate and some custom fields just to make sure user doesn't enter any incorrect data. Also i have to restrict the access to table to only those users that are authorized i.e. depending on the role. So my other question is as a developer are we supposed to take care of it or the basis guys will create the authorization group and i need to just use that group.
Thanks alot again for all ur help..I just want to close this topic once i am cleared on these doubts..
Thanks,
David.
2006 Jun 07 8:34 PM
SM30 is a wide open transaction and you cannot restrict to specific table access to specific users. Yes, if your basis team can create a new authorization group that is used specifically by this table and you put that in your table maintenance generator, then you don't need to do anything in the events.
Another alternative that we used is to create a new authorization object (as opposed to group) which also takes a table name as input. Then we used event 25 to check if the user has this authorization for this table using AUTHORITY-CHECK statement. The flexibility we got with this new object is that we can use the same check for all the Z tables and for all actions(display, update etc). Basis will use this object in their roles with the table name and the action, and in the event we check for that authorization.
Srinivas
Message was edited by: Srinivas Adavi
Please don't forget to close the thread.
2006 Jun 07 8:41 PM
Hi Srinivas,
SOrry for bugging you like this..But can you tell me how we can create this authorization object. And also how we can perform this Authorization check using this object within that event 25, may be a sample code if you have.
Thanks a lot and sorry again for so many questions but i am not clear yet..
Thanks,
David.
2006 Jun 07 8:48 PM
David,
You can create authorization groups using transaction SE54.
You have to assign this authorization group to the table.
The basis with create some authorization based on the authorization group and they will assign them to the profiles of the users. Only those users will have access to work with those tables.
If it goes by authorization object, the authorization object have some authorization field. You may have the table name as one of the fields.
The code looks like this
*check authorization
AUTHORITY-CHECK OBJECT 'ZXXXX'
ID 'Z_TABLE' FIELD lv_user
ID 'ACTVT' FIELD lv_activity.
Thanks,
Message was edited by: Naren Somen
2006 Jun 07 8:52 PM
Hi Naren,
Actually i wanted more info on the second option from Srinivas where we can create autorization objects and performs checks on individuals. I am not sure if our Basis guys will create a seperate authorization group for my tables.
Thanks,
David.
2006 Jun 07 9:00 PM
David,
Generally authorization objects will be created by basis team. In the programs we just use those authorization objects using the authorization-check statement as I shown before.
Srinivas might have asked you to include that piece of code in the event 25.
Go to maintainence view of the table, go to envirment -> modifications -> events.
Select event 25, create an include and put the authorization logic in that include.
That is what I think.
To be honest authorisation groups are easy and doesnt invlove any abap coding.
If you need more clarification, let the forum know.
Thanks,
2006 Jun 07 9:01 PM
Even creating the authorization object is your basis group's responsibility. Once they create it, you will use it in your code and do the check.
2006 Jun 07 9:07 PM
Hello Srinivas/Naren,
Just wanted to clarify in the following code
AUTHORITY-CHECK OBJECT 'ZXXXX'
ID 'Z_TABLE' FIELD lv_user
ID 'ACTVT' FIELD lv_activity.
1)we will just write the above code in the include for that event within a routine right??..
2)ZXXXX is the object name that the Basis guys will provide.
3)Should lv_user be added as a field in the custom table??..
4)What is the purpose of lv_user and lv_activity.
I am sure this will clear all my doubts..thanks for all your help so far..
David.
2006 Jun 07 9:15 PM
> Hello Srinivas/Naren,
> Just wanted to clarify in the following code
> AUTHORITY-CHECK OBJECT 'ZXXXX'
> ID 'Z_TABLE' FIELD <u>zztable</u>
> ID 'ACTVT' FIELD lv_activity.
>
> 1)we will just write the above code in the include
> for that event within a routine right??..
<i><b>Yes. You will check the value of sy-subrc after this check and based on that you will issue a message.</b></i>
> 2)ZXXXX is the object name that the Basis guys will
> provide.
<i><b>Yes</b></i>
> 3)Should lv_user be added as a field in the custom
> table??..
<i><b>No, a <u>field</u> in this statement does not mean a field in your table. This is field of the authorization object which should actually be your Z table name, not the user id.</b></i>
> 4)What is the purpose of lv_user and lv_activity.
<i><b>As I said, lv_user should actually be your Z table name, and lv_activity is to further restrict the user by the actions user can perform on the table maintenance(typically 'update' and 'display'</b></i>
>
> I am sure this will clear all my doubts..thanks for
> all your help so far..
>
> David.
Message was edited by: Srinivas Adavi
Message was edited by: Srinivas Adavi
2006 Jun 07 9:22 PM
David....sorry...I forgot to change the lv_user to lv_table.
That is the table name and the lv_activity wiill take some values like for ex:
02 - display
03 - change
etc.
When ever you try to change the table, it will check your profile with the following values
lv_table = 'ur table name'
lv_activity = 03.
For example if you have 02 assigned instead of 03...then you will get an error saying you are not authorised to change the contents of this table.
Thanks,
2006 Jun 07 9:45 PM
Thanks alot guys i think i am done with my questions. And will now try to implement these changes. Once Again thanks for ur patience and time..
2006 Jun 07 9:46 PM
Glad to be of some help. Please don't forget to close once all your issues are answered.
2009 Feb 11 10:47 AM
Hi Srinivas,
In the above code , if are giving some message to user, like both fields should be filled , then how can we put the cursor on that statement , where it has to be filled. I have tried using 'SET CURSOR ' statement but that does not work.
Please help me in achieving this .
Thanks & Regards,
Deepti