Validating Duplicate Entries In itab
Hi All
How to approach for restricting duplicate entries in the Database?
The scene is that I've to enter some data in a table control . and while saving, I've to check whether the same entry already exists in the database or not.
How to approach for this? Awaiting your valuable response.
Thanks in advance
Pradipta
Hai Mishra
DELETE ADJACENT DUPLICATES FROM itab.
Additions
1. ... COMPARING f1 f2 ...
2. ... COMPARING ALL FIELDS
Effect
Deletes neighboring, duplicate entries from the internal table itab . If there are n duplicate entries, the first entry is retained and the other n - 1 entries are deleted.
Two lines are considered to be duplicated if their default keys match.
The return code value is set as follows:
SY-SUBRC = 0 At least one duplicate exists, at least one entry deleted.
SY_SUBRC = 4 No duplicates exist, no entry deleted.
Addition 1
... COMPARING f1 f2 ...
Effect
Two lines of the internal table itab are considered to be duplicates if the specified fields f1 , f2 , .... match.
Addition 2
... COMPARING ALL FIELDS
Effect
Two lines are considered to be duplicates if all fields of the table entries match.
Notes
The DELETE ADJACENT DUPLICATES statement is especially useful if the internal table itab is sorted by fields (whether in ascending or descending order) which were compared during duplicate determination. In this case, the deletion of neighbouring duplicates is the same as the deletion of all duplicates.
If a comparison criterion is only known at runtime, it can be specified dynamically as the content of a field name by using COMPARING ... (name) ... . If name is blank at runtime, the comparison criterion is ignored. If name contains an invalid component name, a runtime error occurs.
Comparison criteria - statistically or dynamically specified - can be further restriced by specifying the offset and/or length.
Note
Performance
Deleting a line from an internal table incurs index maintenance costs which depend on the index of the line to be deleted. The runtime depends on the line width of the table.
For example, deleting a line in the middle of an internal table with 200 entries requires about 10 msn (standardized microseconds).
Deleting a range of entries with " DELETE itab FROM idx1 TO idx2. " deleting a set of entries with " DELETE itab WHERE ... " only incur index maintenance costs once. Compared with a LOOP , which deletes line-by-line, this is much faster.
To delete neighboring, duplicate entries from an internal table, use the variant " DELETE ADJACENT DUPLICATES FROM itab. " instead of LOOP constructions.
Thanks & regards
Sreeni
Similar Messages
-
Delete Duplicate entries in itab
Dear Experts,
My code is Below. my requirement is all the work area fields are modify comparing matnr.
but i am use append duplicates entris allowed.only possible to modify.
loop at it_ekpo into wa_ekpo.
read table it_ekpo3 into wa_ekpo3 with key matnr = wa_ekpo-matnr.
if sy-subrc = 0.
wa_ekpo-matnr = wa_ekpo3-matnr.
wa_ekpo-menge = wa_ekpo3-menge.---->count field
modify it_ekpo from wa_ekpo.
endif.
endloop.
sort it_ekpo.
DELETE adjacent DUPLICATES FROM it_ekpo comparing matnr.
(Duplicates entry is not working) so modify is changed.
reference: -
>it_ekpo in this way
ebeln matnr menge ecp
10 lo45 1 iiii
10 l045 1 uuy
10 lo77 1 hhj
13 li12. 1 jhjh [mainly i join one itab ibn it_ekpo]
reference------>it_ekpo3.
ebeln matnr menge
10 lo45 2
10 lo77 1
13 li12 1
my final output is --->it_ekpo in this way.
ebeln matnr menge ecp
10 lo45 2 iiii
10 lo77 1 hhj
13 li12. 1 jhjh
<removed_by_moderator>
regards,
raj.
Edited by: Julius Bussche on Dec 11, 2008 5:30 PMsort it_ekpo by matnr.
not
sort it_ekpo. -
Validating duplicate entries in form level
Hi I want to validate records whether its duplicate here i am inserting to a table and want to check whether its existing in another table and if not i need to enter the data.I return the following code but its returning error.I already removed the duplicate rows but still getting same error.I need to validate the duplicate entries.If i enter any refno its showing following error.
frm 40735 When Validate Item Trigger raised unhandled exception Ora -01422
declare
refno number(10);
begin
select ref_no into refno from Emp_ref_arch;
if refno = :EMP.REF_NO then
message ('Duplicate Entry Pls enter again');
else
go_item(:EMP.Edet);
end if;
end;
rgds
jyothi
Edited by: user11243021 on Aug 16, 2009 11:48 PMjyothi,
If you are using select into statements to check whether the data exists or not, then you have to use cursor because, when there is no data, it will return error. And you didn't specified the where condition also.
So try this.
DECLARE
Num_RefNo NUMBER(10);
CURSOR Cur_Check IS SELECT REF_NO FROM EMP_REF_ARCH WHERE <your condition>;
BEGIN
OPEN Cur_Check;
FETCH Cur_Check INTO Num_RefNo;
CLOSE Cur_Check;
IF NVL(Num_RefNo, 0) = :EMP.REF_NO THEN
MESSAGE ('Duplicate Entry Pls enter again');
ELSE
GO_ITEM(:EMP.EDET);
END IF;
END;Regards,
Manu.
If this answer is helpful or correct, please mark it. Thanks. -
Counting the duplicate entries without looping itab.
Hi ,
I want to count the duplicate entries in itab without looping
the itab.
can any one help me....If you just want to know the number of duplicate entries:
DATA:
zlt_itab1 TYPE ....
zlt_itab2 LIKE itab1,
zlv_lines TYPE i,
*-Copy table
zlt_itab2 = zlt_itab1
*-Sort on field to count duplicates:
SORT zlt_itab2 BY <field for counting duplicates>
*-Total number of lines:
zlv_lines = LINES( zlt_itab2).
*-Remove duplicates:
DELETE ADJACENT DUPLICATES FROM zlt_itab2.
*-Calculate number of duplicates:
zlv_lines = zlv_lines - LINES(zlt_itab1).
Regards,
John. -
Please go to the following website:-
http://help.sap.com/saphelp_nw04/helpdata/en/06/aafd54fc4011d195280000e8353423/content.htm
and please scroll down to find:-
<b>Deleting Adjacent Duplicate Entries</b>
To delete adjacent duplicate entries use the following statement:
DELETE ADJACENT DUPLICATE ENTRIES FROM <itab>
[COMPARING <f1> <f 2> ...
|ALL FIELDS].
Then please go to the last example where the code is written as :-
DELETE ADJACENT DUPLICATES FROM ITAB COMPARING ALL FIELDS.
IS THIS CORRECT ?
Regards
abaper.learnerHi learner,
<b>Deleting a sequence of lines</b>
DO 101 TIMES.
DELETE TAB_DEST INDEX 450.
ENDDO.
DELETE TAB_DEST FROM 450 TO 550.
<b>Deleting a set of lines</b>
LOOP AT TAB_DEST
WHERE K = KVAL.
DELETE TAB_DEST.
ENDLOOP
DELETE TAB_DEST WHERE K = KVAL.
<b>DELETE ADJACENT DUPLICATES</b>
As with the ORDER BY clause it could be better to avoid using SELECT DISTINCT, if some of the fields are not part of an index. Instead use ABAP SORT + DELETE ADJACENT DUPLICATES on an internal table, to delete duplicate rows.
LOOP AT TAB1.
READ TABLE TAB2 INDEX SY-TABIX.
IF TAB1 <> TAB2.
TAB_DIFFERENT = 'X'. EXIT.
ENDIF.
ENDLOOP.
ENDIF.
IF TAB_DIFFERENT = SPACE. " ...
ENDIF.
IF TAB1[] = TAB2[]. " ...
ENDIF.
Regards,
Kumar. -
Check Duplicate Entries in Dynamic itab.
Hi,
I have a dynamic internal table populated with some records.
This internal table refers to different DDIC structures dynamically.
I'm trying for a logic to check the duplicate entries that exists in this internal table and also to check whether these entries are already existing in another internal table, but i cant reach upto it.
I tried many options but failed.
So please help me in this logic ( just a hint or pseudocode would be enough ) to check the duplicate entries in a dynamic internal table comparing the key fields.
I have the key fields of the internal table for each different structure.
Regards,
Keshav1. Sort table
2. Access to Table line 1 and 2
And now:
clear lv_error.
do.
assign component sy-index of wa1 to <fs1>.
assign component sy-index of wa2 to <fs2>.
"exit if not successfull
if <fs1> ne <fs2>.
lv_error = abap-true.
exit.
endif.
enddo.
if lv_error is initial.
==> duplicate lines
And then do this for line 2 and 3 and so on ....
Regards
André Witt -
Duplicate entry check in Tb control with 6 same fields
actualy i have made a table control with six same fields.
batch1 batch2 batch3 batch4 batch5 batch6
the data type of all fields is same.
i want to assign a check for duplicate entries.
the value entered in batch1 (say bgp000001). then it cannot be entered in any row or column of table control.that means this value bgp000001 cannot be entered again in entire table control.
although i have been able to create a validation for table control current line.
In PAI
loop at i_packcase.
FIELD I_PACKCASE-batch1 MODULE CHECK_CRTNO1_0107.
FIELD I_PACKCASE-batch2 MODULE CHECK_CRTNO2_0107.
FIELD I_PACKCASE-batch3 MODULE CHECK_CRTNO3_0107.
FIELD I_PACKCASE-batch4 MODULE CHECK_CRTNO4_0107.
FIELD I_PACKCASE-batch5 MODULE CHECK_CRTNO5_0107.
FIELD I_PACKCASE-batch6 MODULE CHECK_CRTNO6_0107 .
endloop.
corresponding modules are coded as below:
there is no check in field-batch1( as this is the first entry in table contrl)
module check_crtno2_0107 input.
if i_packcase-batch2 eq i_packcase-batch1.
message v_duplicate type 'E' display like 'I'.
endif.
endmodule.
module check_crtno3_0107 input.
if i_packcase-batch3 eq i_packcase-batch2
or i_packcase-batch3 eq i_packcase-batch1.
concatenate 'CASE' i_packcase-batch3
' ALREADY ENTERED' into v_duplicate.
message v_duplicate type 'E' display like 'I'.
endif.
endmodule.
similarly field-batch6 is checked against all previous 5 fields
this works only for current line of table control.
*now i want to extend this check to all lines of table control.Hi,
Save the entries of each row and column into an internal table containing one field (fieldx) the required data type. Delete adjacaent duplicates for the internal table. If successful, give error message as required.
Loop at i_packcase.
itab-fieldx = i_packcase-batch1.
append itab.
itab-fieldx = i_packcase-batch2.
append itab.
itab-fieldx = i_packcase-batch3.
append itab.
itab-fieldx = i_packcase-batch4.
append itab.
itab-fieldx = i_packcase-batch5.
append itab.
itab-fieldx = i_packcase-batch6.
append itab.
endloop.
delete adjacent duplicates from itab comparing fieldx.
if sy-subrc eq 0.
****appropriate error message****
endif.
Regards,
Konda Sravanthi. -
Remove duplicate entries from dropdownlist in web dynpro abap
How to remove duplicate entries from dropdownlist in web dynpro abap? Can someone please help me
I have maintained the data in the z table wherein the records of particular fields are repeated but when i show that record in the Web Dynpro application dropdown list, the user should only be able to view the unique data for selection of that particular field.Hi,
try this code in init method.
use the
Delete adjacent duplicates.
<set the table>
select <f1> from <table> into TABLE <Itab> whre <condition>.
DELETE ADJACENT DUPLICATES FROM <Itab> COMPARING <f1>.
lo_nd_vbap->bind_table( new_items = <itab> set_initial_elements = abap_true ). -
To avoid duplicate entries in multi row
Hi i need to avoid duplicate entries in multi record form.In the master block i have AGENCY CODE.These are the fields, RATING_CODE(composite primary key alng with AGENCY_CODE in the detail block,but set as hidden) and DESCRIPTION
in the detail block.If AGENCY_CODE is CRISIL,then for that i should not enter duplicate RATING CODES.I have written
DECLARE
L_COUNT2 NUMBER;
l_ret varchar2(20);
BEGIN
SELECT COUNT(*) INTO L_COUNT2 FROM CSTM_AGENCY_CODE_DETAIL
WHERE AGENCY_CODE=:BLK_CSTM_AGENCY_CODE_DETAIL.AGENCY_CODE
AND RATING_CODE=:BLK_CSTM_AGENCY_CODE_DETAIL.RATING_CODE;
IF L_COUNT2 > 0 THEN
l_ret := ovpkcs.fn_dispmsg('AGYCOD-03;',';',';');
Raise Form_Trigger_Failure;
END IF;
END;
in WHEN_VALIDATE_ITEM.
Now when i press the TAB to move next time it gives the message,DUPLICATE RATING CODE.The
problem is when i move back to the previous record by clicking mouse and change it to the already existing value,and while i save the validation is not happening and the message is not shown.Kindly tell me where i should code.
Thank youhy,
you can check whan commit( an save button)
for i = 1 to n-1
check condition (item = item +1)
next_record
end
or by stored insert whit exception return to form program when duplicate key is found
... -
Update db table for duplicate entries.
Hi,
If i want to update a ztable
i have 3 to 5 different ways.
1. UPDATE ztab FROM workarea.
2. UPDATE ztable SET field1 = wa-f1 field2 = wa-f2
WHERE keyf1 = wa-kf1
AND keyf2 = wa-kf2.
3. UPDATE ztable FROM TABLE itab.
4. MODIFY ztable FROM TABLE itable or from wa.
but if i want to update some 2 to 3 fields
by checking with the fields in db table with values in flat file
and when i check the dbtable values with flat file and i find the entries in dbtable are multiple because i am not putting all key fields in where condition
because i know only some of them .
so duplicate entries are available and i wanted to update the same values to all those duplicate records .
then how should i update them.
i don't want to use update between
select and end-select because the records that i am updating are many.
i will store records into itab and then i will compare with values i file
and for all records i want to update the two or three fields with the values in flat file.
help me.Hi Ashish,
Thanks for your help.
If i do this way always it satisfies the first record of the multiple records that are satisfied when we put where condition with some of the key fields.
then always it might update the same record.
I stead i can loop through the itab having the DB table and read the file.
Anyways thanks for the help.
and i am waiting for the correct file, once i get it, then i will try this and update points.
Thanks,
Neetu. -
Eleminating duplicate entries in table
How to remove the duplicate entries from the tables or internal tables.
Thankyou for your time in giving the answers.
Bhaskar.Hi,
For Internal tables use,
DELETE ADJACENT DUPLICATES FROM itab.
If u want to delete the duplicate entries depending on one or 2 columns then u can use
DELETE ADJACENT DUPLICATES FROM itab COMPARING f1 f2.
Rgds,
Prakash -
Duplicate Entries in Table TBO01
Hi All,
i recently have upgrade of ERP 2005. for Info Object 0IOBJSV we
found duplicate entries for "ATY" and "COR".
"ATY" has been solved by implementation of OSS Note # 922685.
We still face problem of duplicate records for "COR".
In R/3 there are two entries "ORD" and "cor". The Extractor (Data
Source: 0IOBJSV_TEXT) pass the data to BW by converting "ORD" to "COR".
That's why we have two entries in BW for "COR" and "cor".
What would be the possible reason for above problem ? and how can i solved this ??
Will appreciate any help.Hello:
We have experienced the same problem. When I look at the table TBO01 contents on the ECC 6 server using SE16, I see one row that have mixed case "Cor" values:
SPRAS OBART OBART_LD TXT10 TXT15 TXT20 TXT60
E J2 Cor Corr.Obj. Correction Obj. Correction Object Real Estate Management - Reserved by RE
And the german one maybe also gets this "Cor" value somehow on the way to BW:
D J2 BER Ber.Objekt Bericht.objekt Berichtigungsobjekt Immobilienverwaltung - Reserved by RE
Message = @5C@ 0IOBJSV : Data record 183 ('0CorD '): Version '0Cor ' is not valid RSDMD 194 @35@
PSA shows =
Request number REQU_45HVMT8E1R8JLXBKBTY3ECQKX
Data packet number 000001
Partition value for 1
data record number 183
Language Key DE
Account Assignment O 0Cor
Medium Description Bericht.objekt
The english side is also messed up =
Request number REQU_45HVMT8E1R8JLXBKBTY3ECQKX
Data packet number 000001
Partition value for 1
Data record number 184
Language Key EN
Account Assignment O 0Cor
Medium Description Correction Obj.
@5C@ Value '0Cor ' for characteristic 0IOBJSV contains invalid characters RRSV 7
@5C@ 0IOBJSV : Data record 184 ('0CorE '): Version '0Cor ' is not valid RSDMD 194 @35@
I wonder if someone can post an OSS note for SAP to investigate
why 0Cor has mixed case values? Did someone who does data entry make
a typographical error?
Thanks,
Chris Mason -
How to check duplicate entries in internal table??
Dear Friends,
How to check duplicate entries in internal table??
Exp: In my internal table if I am having the same records more then ones then I need to print the error message, here I am using steploop for selecting the values from screen, and the values are coming into my internal table if user enter the same value more then ones I need to print the error message.
Thanks,
SridharHi,
After storing the data into internal table say ITAb, move the data into another internal table.
t_dup[] = itab[].
LOOP AT itab.
count1 = count1 + 1.
itab-count1 = count1.
MODIFY itab.
ENDLOOP.
LOOP AT t_dup.
count2 = count2 + 1.
t_dup-count2 = count2.
MODIFY t_dup.
ENDLOOP.
DELETE ADJACENT DUPLICATES FROM itab.
LOOP AT t_dup.
record_dup = 'N'.
READ TABLE itab WITH KEY count1 = t_dup-count2.
IF sy-subrc = 0.
record_dup = 'Y'.
ENDIF.
IF record_dup NE 'Y'.
t_dup-message = 'DUPLICATE ENTRY'.
t_dup-flag = 1.
MODIFY t_dup.
ENDIF.
ENDLOOP.
Use this sample code.
Reward pts if it is helpfull.
Regards
Srimanta -
Hi experts,
In internal table i have many account numbers.
There are some duplicate entries. i have removed all the duplicates using the following code.
but i cannot remove all the duplicate entries.
certain scenarios i should have duplicate elements also in my output.
certain scenario i should remove the duplicates.
is there any way to remove few duplicate entries from internal table.
your furthur clarification i will send the code also.
DELETE ADJACENT DUPLICATES FROM itab_temp COMPARING RI_ACCT_NO .
LOOP AT ITAB_temp.
LOOP AT ITAB WHERE RI_ACCT_NO = ITAB_TEMP-RI_ACCT_NO.
SUM_BETRH = SUM_BETRH + itab-BETRH.
SUM_BETRW = SUM_BETRW + itab-BETRW.
ENDLOOP.
ITAB_ALS = ITAB.
ITAB_ALS-BETRH = SUM_BETRH.
ITAB_ALS-BETRW = SUM_BETRW.
APPEND ITAB_ALS.
CLEAR: SUM_BETRH, SUM_BETRW, ITAB_ALS.
ENDLOOP.
if u know pls send me documents to
[email protected]
its very urgent.
Thank you in advance.
JeyanthiHi
You have add the following statement before the delete duplicate statement
SORT itab_temp BY RI_ACCT_NO.
DELETE ADJACENT DUPLICATES FROM itab_temp COMPARING RI_ACCT_NO .
I think now it will work. Otherwise some problem internal table fields.
Moreover this code not efficient. You are using nested loops, it is performance killer. Instead you can use for all entries. Already u have data in ITAB_TEMP.
Select f1 f2... from XTABLE into table ITAB for all entries in ITAB_TEMP where RI_ACCT_NO = ITAB_TEMP-RI_ACCT_NO .
then u can add addition logic by using one loop and endloop.
Reward me if it is useful -
Hi
I have used an inner join to get data from two tables KNA1 and KNVP. In the result some entries are getting duplicated. How do i restrict it to get unique records???Hi Mayur,
After selecting the datas you can delete the Duplicate Values from your internal Table.
For Internal tables use,
DELETE ADJACENT DUPLICATES FROM itab.
If u want to delete the duplicate entries depending on one or 2 columns then u can use
DELETE ADJACENT DUPLICATES FROM itab COMPARING f1 f2.
Thanks.
Reward If Helpful.
Maybe you are looking for
-
Is it necessary to have pages on mac to have it on iPad?
Hello people! I am thinking of getting pages for iPad and I was wondering if it is necessary to have pages on mac to have it on iPad, because I don't own a mac or a computer with pages on it... Any help.
-
Condition tab (or assigment block) in sales order
Hi all, I have a problem regarding conditions maintenance in my sales order document. My replication scenario is A and PRICINGTYPE parameter is G in SMOFPARFSA table I create a sales order document (with pricing schema determination correctly set up)
-
I've tried this process twice, and I'm still having trouble with Adobe Flash Drive. Do I need to change something in my security settings?
-
What kind of alerts we use?
hi friends, what kind of alerts we create in reporting? Thanking u suneel.
-
New Region does not appear in standard page (Please Your Help).
Hi Experts, I tried to create in javadeveloper a region to have descriptive flexfields shown in standard page with the following structure : Region (stacklayout) Region (messageComponentLayout) Item (messageLayout) Item (flex) Then I used import comm