‎2007 May 23 6:15 AM
friends i have scenario in which
i have to make sure there are no two entries in itab2 ie.
for every name entry in itab1 ,
check that a corresponding UNIQUE entry for that name exists in itab2. ie.
if itab1 has an entry john in name field, then itab should have exactly one entry as john in name entry.
not zero not 2, but exactly one.
i thought of following code. does any one have a better idea, with read or anything else.
count = 0.
loop at itab1.
loop at itab2 where name EQ itab1-name.
count = count +1.
endloop.
endloop.
if count >1.
write:/ ' error'.
endif.
‎2007 May 23 6:19 AM
Hi Saritha,
i Find thats fine.
count = 0.
loop at itab1.
loop at itab2 where name EQ itab1-name.
count = count +1.
if count >1.
count = 0.
write:/ ' error'.
exit.
endif.
endloop.
endloop.
Try this and reward points if helpful.
Regards,
Ravi G
‎2007 May 23 6:19 AM
Hi,
YOu can try this way...
Loop at ITAB1.
Read table ITAB2 where name = ITAB1-NAME.
if sy-subrc NE 0.
write:\ ' Error'.
Endif.
Endloop.
Regards,
sachin
‎2007 May 23 6:20 AM
hi,
chk this. will improve perfromance.
count = 0.
clear count.
loop at itab1.
loop at itab2 where name EQ itab1-name.
count = count +1.
<b>if count >1.
exit.
endif.</b>
endloop.
endloop.
if count >1.
write:/ ' error'.
endif.
Rgds
Anver
‎2007 May 23 6:20 AM
hi saritha,
one small change
count = 0.
loop at itab1.
loop at itab2 where name EQ itab1-name.
count = count +1.
endloop.
endloop.
if count >1 and count = 0. " (u said know ther shuld be 1 not 0 & 2 )
write:/ ' error'.
endif.
With regards,
S.Barani
‎2007 May 23 6:25 AM
sort itab2 by name
sort itab1 by name
loop at itab1 into wa_area1.
read table itab2 into wa_area2 where name = wa_area1-name binary search.
clear v_index.
move sy-tabix to V_index.
if sy_subrc = 0. " i.e. 1 record exists.
-- read table itab2 into wa_area2 index v_index.
-
if sy_subrc = 0. " i.e 2nd record exists.
-
<b>error msg or watever</b>
-
else. " i.e. only 1 record exists.
-
<b>do processing</b>
-
endif.
else. " i.e. no record exists.
--<b>error msg or watever</b>
endif.
Regards,
Sooness.
‎2007 May 23 6:28 AM
hi, there's a small error:
.
.
if sy_subrc = 0. " i.e. 1 record exists.
V_index2 = V_index + 1.
-- read table itab2 into wa_area2 index <b>v_index2</b>.
-
if sy_subrc = 0. " i.e 2nd record exists.
.
.
‎2007 May 23 6:26 AM
Hi,
You have to maintain a flag in itab1 for unique entry & make it X if there is corresponding 1 entry in itab2.
count = 0.
sort itab2 by name.
loop at itab1.
loop at itab2 where name EQ itab1-name.
count = count +1.
if count > 1.
exit.
endif.
endloop.
if count ne 1.
itab-flag = 'X'.
modify itab1.
endif.
clear : count,itab1,itab2.
endloop.
Thanks
Sandeep
Reward if helpful
‎2007 May 23 6:30 AM
Hi Saritha,
The way u choose is ok. Let me tell u one more way.
You can use one more itab just for this purpose. Eg itab3.
then do a read to the itab3 with ur key, if u find Your record, delete that entry, then do a read again in itab3. At this stage u can decide the multiple occurance of the record.
Hope this will help u to avoid the looping.
Regards
Sarath
‎2007 May 23 6:37 AM
hi saritha,
report xxx message-id msg1.
data:count type i value 0.
loop at itab1.
loop at itab2 where name EQ itab1-name.
if sy-subrc eq 0.
count = count +1.
endif.
else.
if count >1.
message e000 with ' error'.
endif.
endloop.
endloop.
if helpful reward some points.
with regards,
suresh babu aluri.