‎2006 May 24 9:26 AM
Hi All,
I created a table with 2 fields, also created a maintenance generator. Now my requirement is i need to have 1-1 relation with the fields, what i mean is, no value can repeat with in either of the fields.
I need to validate this condition.
Suppose user enters a value 1234 in first field, again if he enters the same, i need to throw a error message.
I went to transaction SE54, the following is the code
PROCESS BEFORE OUTPUT.
MODULE liste_initialisieren.
LOOP AT extract WITH CONTROL
tctrl_zzbank CURSOR nextline.
MODULE liste_show_liste.
ENDLOOP.
*
PROCESS AFTER INPUT.
MODULE liste_exit_command AT EXIT-COMMAND.
MODULE liste_before_loop.
LOOP AT extract.
MODULE liste_init_workarea.
CHAIN.
FIELD zzbank-zzau1.
FIELD zzbank-hbkid.
MODULE set_update_flag ON CHAIN-REQUEST.
ENDCHAIN.
FIELD vim_marked MODULE liste_mark_checkbox.
CHAIN.
FIELD zzbank-zzau1.
MODULE liste_update_liste.
ENDCHAIN.
ENDLOOP.
MODULE liste_after_loop.
<b> MODULE check_dupe.</b>
the line in bold is what i added, how do i proceed from here, could anyone please help.
‎2006 May 24 9:36 AM
Hi,
if I understand right, I think its easier to declare both fields as key fields, so that SAP automatically will not allow saving records that are allready in the table.
Or you mean, one value is not to be accepted in either field, no matter what the value for the other field is ??
FIELD1 FIELD2
111 222
444 555
222 333 <- not valid ??
in that case, user SEARCH in your table for the current value and if SY-SUBRC = 0, then the value exists allready.
Greetings
‎2006 May 24 9:37 AM
Hi,
You ca do this validations in the events part of Table Maintenance.
Chk out this link:
Regards,
Anjali
‎2006 May 24 1:56 PM
goto se54--view name-meny bar-environment-modification...
n write ur piece of code...in the relevant code..
‎2006 May 24 2:38 PM
Hi Deepti,
As Jorge Alonso said, if you declare both fields as key fields then SAP will take care of the validation and raise a error message .
Assuming both fields are key fields, if the records are like this.
111 222
<b>111 222</b>
then SAP will raise a error message.
Otherwise, if you don't want first or second field to be repeated any where again, then include the code in your check_dupe module.
GET CURSOR LINE <lin> or GET CURSOR FIELD <f> LINE <lin>.
select * from ztable into itab.
loop at itab.
if itab-first_field CS table_first_field or itab-first_field CS table_second_field or itab-second_field CS table_first_field or itab-second_field CS table_second_field.
If sy-subrc eq 0.
MESSAGE E0004 WITH 'Duplicate key'.
ENDIF.
ENDIF.
endloop.
Hope this will help you,
Regards,
Vicky
PS: Award points if helpful