Application Development and Automation Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

Validate data when user enters data thru SM30

Former Member
0 Likes
5,602

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.

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
3,697

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.

18 REPLIES 18
Read only

Former Member
0 Likes
3,697

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

Read only

former_member181966
Active Contributor
0 Likes
3,697

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 this’ll give you idea!!

<b>Pl... award the points.</b>

Good luck

Thanks

Saquib Khan

"Some are wise and some are otherwise"

Read only

Former Member
0 Likes
3,698

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.

Read only

Former Member
0 Likes
3,697

Check this for sample code.

Read only

0 Likes
3,697

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.

Read only

0 Likes
3,697

It seems to be OK, also you need to do validation here.

Is it not working as u expected?

Read only

0 Likes
3,697

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

Read only

0 Likes
3,697

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

Read only

0 Likes
3,697

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.

Read only

0 Likes
3,697

Which event are you using? I used 01 for the second code I gave you.

Read only

0 Likes
3,697

Also check whether your Function group is active.

Regds

Manohar

Read only

0 Likes
3,697

Your previous event 25 will trigger only if you press SAVE. That is why changing the SY-SUBRC is so important.

Read only

0 Likes
3,697

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.

Read only

0 Likes
3,697

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.

Read only

0 Likes
3,697

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.

Read only

0 Likes
3,697

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.

Read only

0 Likes
3,697

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.

Read only

Former Member
0 Likes
3,697

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.