‎2010 Mar 19 12:24 PM
I have 2 columns for table controls <col1> <col2> for which i need to input values
I can have multiple same values for col1 and cols 2 seperately but not together , means both in combination shud form a unique key if not then need to display messgae
col1 col2
a b
a c
d b
a c -
> Not allowed (display msg when save is pressed in table control)
How to do it???
‎2010 Mar 19 12:34 PM
Try declaring your internal table with UNIQUE KEY.
Regards,
Kiran
‎2010 Mar 19 12:40 PM
‎2010 Mar 19 12:45 PM
what kiran meant was to declare the internal table as sorted type with unique key ( your two fields).
‎2010 Mar 19 12:42 PM
if you are validating it in a chain statement, then read the same internal table with the values 'a' and 'c'.
read itab with key f1 = 'a' f2 = 'b' transporting no fields.
if sy-subrc = 0.
Then the value exists.
else.
valid.
endif.
‎2010 Mar 19 12:46 PM
I cannot expicilt provide values as it can be for many combination or i dont know before hand which values are repeated
‎2010 Mar 19 12:51 PM
HI Karan,
In PAI,
loop at itab.
chain.
field : itab-col1, itab-col2.
module validate on request.
module validate.
endchain.
module update_tc.
endloop.
in Program
module validate.
read table itab with key col1 = itab-col1 " This is newly entered Value in Table Control
col2 = itab-col2. " This is newly entered Value in Table Control
if sy-subrc = 0.
message 'These values are already Entered' Type 'E'.
endif.
endmodule.
module update_tc.
describe table itab lines tc-lines.
if tc-current_line > tc-lines.
append itab. " You pass newly enterd Row into Internal table in the Program
else.
modify itab index tc-current_line. " Or Modify the Existing row in the Program Itab
endif.
"Here you update the Values back to Program Internal Table
endmoduleCheerz
Ram
‎2010 Mar 19 12:54 PM
You no need to provide the values explicitly, that was just a logic.
‎2010 Mar 19 12:59 PM
requirement is pretty tricky ..
Im substituting ur column to field f1 and f2.
report zvij57.
data: begin of itab occurs 0,
f1(10) type c,
f2(10) type c,
end of itab.
*populate itab for say db
itab-f1 = 'a'. itab-f2 = 'b'. append itab.
itab-f1 = 'a'. itab-f2 = 'c'. append itab.
itab-f1 = 'd'. itab-f2 = 'c'. append itab.
itab-f1 = 'a'. itab-f2 = 'c'. append itab.
itab-f1 = 'd'. itab-f2 = 'c'. append itab.
sort itab by f1 f2.
data : lv_flag type c,
lv_cnt type i,
lv_val(10) type c.
loop at itab .
at new f1.
lv_flag = 'X'.
ENDAT.
if lv_flag eq 'X'.
lv_val = itab-f2.
lv_flag = ''.
endif.
if lv_val = itab-f2.
add 1 to lv_cnt .
else.
lv_val = itab-f2.
endif.
if lv_cnt ge 2.
write :/ 'duplicate entry for', itab-f1 ,itab-f2.
endif.
at end of f1.
clear : lv_flag, lv_val, lv_cnt.
endat.
endloop.
Execute this and check if this meets your requirement.
Br,
Vijay.
‎2010 Mar 19 1:31 PM
i have to refine further this logic and now it looks fine to me .
REPORT Zvij57.
data: begin of itab occurs 0,
f1(10) type c,
f2(10) type c,
f3 type i,
end of itab.
*populate itab for say db
itab-f1 = 'a'. itab-f2 = 'e'. append itab.
itab-f1 = 'a'. itab-f2 = 'b'. append itab.
itab-f1 = 'a'. itab-f2 = 'c'. append itab.
itab-f1 = 'd'. itab-f2 = 'c'. append itab.
itab-f1 = 'a'. itab-f2 = 'c'. append itab.
itab-f1 = 'd'. itab-f2 = 'c'. append itab.
itab-f1 = 'a'. itab-f2 = 'd'. append itab.
itab-f1 = 'b'. itab-f2 = 'c'. append itab.
itab-f1 = 'a'. itab-f2 = 'g'. append itab.
sort itab by f1 f2.
data : lv_flag type c,
lv_cnt type i,
lv_val(10) type c.
loop at itab.
write :/ itab-f1 , 15 itab-f2.
endloop.
skip 10 .
write :/ sy-uline(30).
loop at itab .
at new f2.
lv_flag = 'X'.
ENDAT.
if lv_flag eq 'X'.
lv_val = itab-f2.
lv_flag = ''.
endif.
if lv_val = itab-f2.
add 1 to lv_cnt .
endif.
itab-f3 = lv_cnt.
modify itab index sy-tabix.
if lv_cnt eq 2.
write :/ 'duplicate entry for', itab-f1 ,itab-f2, itab-f3.
endif.
at end of f2.
clear : lv_cnt.
endat.
endloop.
occurance 2 should throw an error message before the save in the PAI . any occurance of 2 will stop the entry into DB ..
Br,
Vijay.