2006 Jul 06 5:52 PM
Hi All,
I have the following requirement i have to validate the data when user enters it at SM30. Actually the requirement is when the user enters data he has to accordingly set 2 custom flags. So what i have to do is i have to do validations on the primary key(to find out whether it is an existing entry or a new entry) and if he sets the flags wrongly i have to raise an error message. Is there any way this can be achieved..
Thanks in advance,
David.
2006 Jul 06 5:57 PM
Yes, you can achive that through events of table maintenance. Go to SE54, enter your table name and in the menu 'Environment--> Events'. Click through the pop-up message and in the next screen, click on 'New Entries'. Enter '01' as the event, some name for the routine and enter. A source code icon will appear. Click on that to create the routine in an include. In that source code, you can enter your validations.
Hi All,
I have the following requirement i have to validate the data when user enters it at SM30. Actually the requirement is when the user enters data he has to accordingly set 2 custom flags. So what i have to do is i have to do validations on the primary key(to find out whether it is an existing entry or a new entry) and if he sets the flags wrongly i have to raise an error message. Is there any way this can be achieved..
Thanks in advance,
David.
2006 Jul 06 5:56 PM
The primary key check is present in SM30 by default. Any other validations have to be written in the PAI module.
If my screen field name id FLD and I need to check that FLD should never be equal to A I will write the below code in the PAI module
field FLD module check_fld.
double click on check_fld to create the module.
In the module write
if fld = 'A'.
message e000 with message
endif.
-Kiran
2006 Jul 06 5:56 PM
Is it a standard table or custom table ? if it is standard you can see the user exit SUSR0001 or if its custom table , then you can program it in flow logic...
FYI
primary key check is there by defualt in SM30
Hope thisll give you idea!!
<b>Pl... award the points.</b>
Good luck
Thanks
Saquib Khan
"Some are wise and some are otherwise"
2006 Jul 06 5:57 PM
Yes, you can achive that through events of table maintenance. Go to SE54, enter your table name and in the menu 'Environment--> Events'. Click through the pop-up message and in the next screen, click on 'New Entries'. Enter '01' as the event, some name for the routine and enter. A source code icon will appear. Click on that to create the routine in an include. In that source code, you can enter your validations.
2006 Jul 06 6:01 PM
2006 Jul 06 7:01 PM
Hi Srinivas,
I am doing the following for my requirement..Is it the right way to do it..I am creating this routine within the include
READ TABLE extract WITH KEY l_total.
IF sy-subrc EQ 0.
f_index = sy-tabix.
ELSE.
CLEAR f_index.
ENDIF.
MOVE-CORRESPONDING s_record TO l_total.
MODIFY total FROM l_total.
CHECK f_index GT 0.
MODIFY extract INDEX f_index FROM l_total.
ENDIF.
ENDLOOP.
Thanks,
David.
2006 Jul 06 7:38 PM
It seems to be OK, also you need to do validation here.
Is it not working as u expected?
2006 Jul 06 7:53 PM
Hi there,
Actually i am doing the following is it the right way??..
form validate_data.
DATA: f_index LIKE sy-tabix.
DATA: BEGIN OF l_total.
INCLUDE STRUCTURE ztable,
INCLUDE STRUCTURE vimtbflags,
END OF l_total.
DATA: s_record TYPE ztable.
LOOP AT total INTO l_total.
IF l_total-vim_action = aendern OR
l_total-vim_action = neuer_eintrag.
MOVE-CORRESPONDING l_total TO s_record.
if s_record-zzgeoloc = ztable-zzprimary and zgeoloc-zzflag2 = 'X'.
Message e001(z_msg).
elseif s_record-zzprimary = zgeoloc-zzprimary and zgeoloc-zzflag1 ne 'X'.
Message e002(z_msg).
Endif.
if s_record-primary ne ztable-zzprimary.
s_record-zzflag1 = 'X'.
s_record-zzflag2 = ''.
Endif.
READ TABLE extract WITH KEY l_total.
IF sy-subrc EQ 0.
f_index = sy-tabix.
ELSE.
CLEAR f_index.
ENDIF.
MOVE-CORRESPONDING s_record TO l_total.
MODIFY total FROM l_total.
CHECK f_index GT 0.
MODIFY extract INDEX f_index FROM l_total.
ENDIF.
ENDLOOP.
Thanks,
David
2006 Jul 06 8:00 PM
Here is a small example where I check for blank values in the key fields. May be this is much simpler to understand.
*---------------------------------------------------------------------*
* FORM CHECK_FOR_BLANK_KEYFIELDS *
*---------------------------------------------------------------------*
* ........ *
*---------------------------------------------------------------------*
form check_for_blank_keyfields.
data: l_field_is_blank.
data: begin of s_table.
include structure ztable.
include structure vimtbflags.
data: end of s_ztable.
loop at total.
clear s_ztable.
move total to s_ztable.
check s_ztable-vim_action <> neuer_geloescht
and s_ztable-vim_action <> update_geloescht
and s_ztable-vim_action <> dummy_geloescht.
if s_ztable-keyfield1 is initial or
s_ztable-keyfield2 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. <-- this is important
else.
sy-subrc = 0.
endif.
clear l_field_is_blank.
endform. " CHECK_FOR_BLANK_KEYFIELDS
2006 Jul 06 9:22 PM
Hi Srinivas,
I created the routine like this but when its not working. I put a breakpoint and its not even triggering when i am adding some data using SM30. Any idea what went wrong here..
form validate_data.
DATA: f_index LIKE sy-tabix.
DATA: BEGIN OF s_ztable.
INCLUDE STRUCTURE zgeoloc.
INCLUDE STRUCTURE vimtbflags.
data: end of s_ztable.
DATA: l_field_is_blank.
loop at total.
clear s_ztable.
move total to s_ztable.
check s_ztable-vim_action <> neuer_geloescht
and s_ztable-vim_action <> update_geloescht
and s_ztable-vim_action <> dummy_geloescht.
if s_ztable-zzenabled_flag eq ''.
l_field_is_blank = 'X'.
exit.
endif.
endloop.
if l_field_is_blank = 'X'.
message i001 with 'Both values should be filled in.'.
sy-subrc = 4. "this is important
else.
sy-subrc = 0.
endif.
clear l_field_is_blank.
endform. " CHECK_FOR_BLANK_KEYFIELDS
Thanks,
David.
2006 Jul 06 9:24 PM
Which event are you using? I used 01 for the second code I gave you.
2006 Jul 06 9:25 PM
Also check whether your Function group is active.
Regds
Manohar
2006 Jul 06 9:27 PM
Your previous event 25 will trigger only if you press SAVE. That is why changing the SY-SUBRC is so important.
2006 Jul 06 9:37 PM
Hi Srinivas,
I am using the event 01 and the code as i pasted in my earlier reply. Its now trigerring when i am saving in SM30 but when i am debugging i see that what i am entering thru SM30 is not shown in the structure s_ztable contents. Do i need to refresh something here, also when it goes to the Message thing it gives me the popup that information function is not supported..
Thanks a lot for all ur help so far i would definitely reward you with necessary points..
Thanks,
David.
2006 Jul 06 9:57 PM
I am not sure why you are getting this. I don't have get it for my table. Event 01 is triggered when you press SAVE. With regards to your popup, can you please give me the exact text of the message and the number and id?
Instead of looking at the entire structure of s_ztable, try to look for individual field values in debugging to see if they are what you entered in the initial screen. Also, please check if you need all the checks for VIM_ACTION field. You can double click on those constants and see what they mean. Also, there is very good documentation in that screen. You can read it by clicking on the blue 'I' icon. That will give you an idea.
Please let me know how it goes.
2006 Jul 06 10:13 PM
Hi Srinivas,
Actually the only problem now what i saw is it is always taking the first entry in SM30 only even though if it is previously saved one. So do i have to refresh total or something like that..
Thanks,
David.
2006 Jul 06 10:38 PM
Hi Srinivas,
Hurray that seems to be working now its giving me the appropiate message i guess i will have to use some popup function module instead as it is kicking me out with the error message. But i have one more question for you for instance i have to change some of the non-primary fields for a record manually how can we do that in SM30??..when i enter the primary key and alter the non-primary fields it doesnt allow me to save it and gives error that "a key already exists"..Do you have any idea??..
Thanks alot in advance and i have rewarded you with points so far once we are done with this i will mark it complete.
David.
2006 Jul 07 9:51 PM
Hmm! that is interesting. Do you have two screen maintenance or single screen maintenance? Either way, it should not restrict you from changing the values of an existing record. Did you, by any chance, click on 'copy' and changed only the non-key fields? For changing non-key fields, all you have to do is change them where they are displayed.
2006 Jul 06 6:45 PM
Hi david,
For doing validations you need to make use of modification event
01 Before saving the data in the database
Refer to link for list of events available
Extended Table Maintenance Events
To control with authorization please refer to the link below.
Maintain authorization groups
Refer to this blog for event creations
https://www.sdn.sap.com/irj/servlet/prt/portal/prtroot/com.sap.km.cm.docs/library/abap/how to implement events in table maintenance.doc
regards,
keerthi.