Duplicate Keys in Hashmap
The following code and output illustrate the core of my prolems using HashMap. I've created a simple key class wrapping a string and implementing equals, hashcode and compareTo. Entries can only be accessied via iterators and duplicates appear. Using a TreeMap instead works fine, but I need the speed of hashmap for now.:
import java.util.*;
import java.io.*;
import java.awt.event.*;
import java.awt.*;
class GenericGraphKey implements Comparable{
private String val="";
public GenericGraphKey(String value){ val=value; }
public boolean equals(GenericGraphKey k){
System.out.println("equals()");
return val.equals(k.val);
public int hashCode() {
System.out.println("hashCode():"+val.hashCode());
return val.hashCode();
public int compareTo(Object o) {
System.out.println("compareTo()");
GenericGraphKey n=(GenericGraphKey)o;
return val.compareTo(n.val);
public String toString(){ return ("["+val+"]"); }
public class TestApp {
public static void main(String[] args) {
HashMap t=new HashMap();
System.out.print("A:");
GenericGraphKey k1=new GenericGraphKey("John");
System.out.println("Put "+k1+",a :"+(String)t.put(k1,"a") );
System.out.print("B:");
GenericGraphKey k2=new GenericGraphKey("John");
System.out.println("Get "+k2+":"+(String)t.get(k2));
System.out.print("C:");
GenericGraphKey k3=new GenericGraphKey("John");
System.out.println("Put "+k3+",b :"+(String)t.put(k3,"b"));
System.out.print("D:");
GenericGraphKey k4=new GenericGraphKey("John");
System.out.println("Get "+k4+":"+(String)t.get(k4));
System.out.print("E:");
GenericGraphKey k5=new GenericGraphKey("Jane");
System.out.println("Put "+k5+",c :"+(String)t.put(k5,"c"));
System.out.print("F:");
GenericGraphKey k6=new GenericGraphKey("Jane");
System.out.println("Get "+k6+":"+(String)t.get(k6));
System.out.print("G:");
GenericGraphKey k7=new GenericGraphKey("Allan");
System.out.println("Put "+k7+",d :"+(String)t.put(k7,"d"));
System.out.print("H:");
GenericGraphKey k8=new GenericGraphKey("Allan");
System.out.println("Put "+k8+",e :"+(String)t.put(k8,"e"));
System.out.print("I:");
GenericGraphKey k9=new GenericGraphKey("Allan");
System.out.println("Get "+k9+":"+(String)t.get(k9));
System.out.println();
Map.Entry e=null;
for (Iterator i=t.entrySet().iterator(); i.hasNext();){
e = (Map.Entry) i.next();
System.out.print("{"+(String)e.getValue()+"}");
System.out.println();
System.out.println(t.keySet());
Output:
A:hashCode():2314539
Put [John],a :null
B:hashCode():2314539
Get [John]:null
C:hashCode():2314539
Put [John],b :null
D:hashCode():2314539
Get [John]:null
E:hashCode():2301262
Put [Jane],c :null
F:hashCode():2301262
Get [Jane]:null
G:hashCode():63353198
Put [Allan],d :null
H:hashCode():63353198
Put [Allan],e :null
I:hashCode():63353198
Get [Allan]:null
{c}{e}{d}{b}{a}
[[Jane], [Allan], [Allan], [John], [John]]
Thanks to anyone who can get things moving on again.
Hombre below is an illustration of what Chrisboy and jverd are telling you.
If the parent class has a method with the same signature as one in an interface which the child class implements then your IDE and javac will not say anything about you not haveing implemented the class in the interface.
The following code compiles and at least Netbeans also has no problems with it.
public class NewClass
public NewClass()
public void someMethod()
public interface NewInterface
public void someMethod();
public class NewClass2 extends NewClass implements NewInterface
public NewClass2()
}
Similar Messages
-
Hi,
I have a class I created, call it MyClass. It looks like this:
public String myString;
public final String toString() {
return myString;
public boolean equals(MyClass mc) {
return (mc != null && myString.equalsIgnoreCase(mc.toString()));
}When I use objects of type MyClass as the keys to a HashMap when doing a put(), duplicate keys seem to be allowed. And when I query, knowing that I have an entry for a key, I get null. However, when I change my get() and put() to use MyClass.toString() as the key, everything works fine.
It seems to me that the JVM must be assuming that different instances of objects of type MyClass are different and thus a new key+value is created when "putting" instead of the old value being overwritten. But MyClass has an equals() method, so when putting, why doesn't it tell the JVM that the key already exists?
Thanks,
JeffTrue, I missed that.
Were you thinking that the HashMap is going to use the equals you provide that takes MyClass as an arg? It won't. It uses the one that takes Object, which means you'll be using Object's equals, which compares references, so no MyClass can ever be equal to another.
You need to override equals (with the Object argument) and override hashCode. -
Duplicate keys in Hashmap - any alternative?
Hi,
I'm using a HashMap that I have now unfortunately discovered may have duplicate keys & the method I use to call the HashMap only calls one a of the key-value pairs - is there any alternative I can use?
Thanks,
CThis is how I interpret the question.
I'm using a HashMap Ok, he has a HashMap, and a problem with it.
that I have now
unfortunately discovered may have duplicate keys The problem is that he now has found out that he might need to bind several values to one key.
the method I use to call the HashMap only calls one
a of the key-value pairsThat's because only one is stored in the map.
- is there any alternative
I can use?See the link that I posted. -
How to store duplicate keys in HashMap
Hi,
sun guys,
please any one guide me how to store duplicate values in the haspmap.
i think we need override the equals and hash code methods. am i right??
if so guide me how to do it??
thanks in advance,
nagaraju.uppala wrote:
Hi,Hi,
sun guys,Most of the people who answer questions here, aren't from Sun.
please any one guide me how to store duplicate values in the haspmap.
i think we need override the equals and hash code methods. am i right??
if so guide me how to do it??Associate the key with a list or a set, and place the values in that list/set.
A put will then mean that you first call get to see if a list already is associated with the key. Place the value in the list in that case. Otherwise create a new list. Place the value in the list, and then call put with the list as value.
Kaj -
HashMap type object that allows multiple duplicate keys
Hello all,
I need an object that will allow me to have a key/value similar to a HashMap except that it will allow me to have duplicate keys.
ie....
//set(Key,Value)
set("Apple","red")
set("Apple","green")
set("Apple","brown")Any Ideas?
TIA!Nevermind,
I figured it out.
if(!map.containsKey(key))
ArrayList arraylist = new ArrayList();
arraylist.add(value);
map.put(key,arraylist);
else
ArrayList arraylist = (ArrayList) map.get(key);
arraylist.add(value);
}Thanks. -
Putting Duplicate Keys in a Hashtable.Please assist
Folks,
I wud like to put duplicate keys into a Hashtable,so that the Hashtable looks like:
Entertainment,Video;
Entertainment,Pictures;
Entertainment,Camera;
where Entertainment is the key:
So I am using the flwg code:
public class TestHashTable {
public static void main(String[] args){
Hashtable balance = new Hashtable();
HashMap hm = new HashMap();
Enumeration names;
String str;
balance.put("Entertainment",helperMethodAddToList(hm, "Entertainment", "Camera"));
balance.put("Entertainment",helperMethodAddToList(hm, "Entertainment", "Video"));
balance.put("Entertainment",helperMethodAddToList(hm, "Entertainment", "Pictures"));
names = balance.keys();
while(names.hasMoreElements()){
str = (String)names.nextElement();
System.out.println(str + ":" + balance.get(str));
} // End of main.
private static List helperMethodAddToList(Map m, String key, String value) {
List vals = (List)m.get(key);
if (vals == null) {
vals = new LinkedList();
m.put(key, vals);
vals.add(value);
return vals;
}The output comes this way:
Entertainment:[Camera, Video, Pictures]
I dont want it this way but as shown on 1st Line
Is this possible? Am I missing something?import java.util.*;
public class X {
public static void main(String[] args) {
HashMap map = new HashMap();
map.put("a", toList(new String[] {"alabama", "arkansas", "alaska"}));
map.put("n", toList(new String[] {"nevada", "new mexico", "north dakota"}));
map.put("w", toList(new String[] {"wyoming", "west virgina"}));
dump(map);
static List toList(String[] strings) {
return new ArrayList(Arrays.asList(strings));
static void dump(Map map) {
for(Iterator i = map.entrySet().iterator(); i.hasNext(); ) {
Map.Entry entry = (Map.Entry) i.next();
System.out.print("key=" + entry.getKey() + ", values=");
List values = (List) entry.getValue();
for(Iterator j=values.iterator(); j.hasNext(); ) {
String state = (String) j.next();
System.out.print(state + ", ");
System.out.println();
} -
I come across a problem when handling duplicate keys retrieved from query result.
It is not hard I believe, but I can not find solution
the problem is:
I have a query that will retrieve the rows like structure
product_A, aaa
product_A, bbb
product_A, ccc
product_A, ddd
product_A, eee
product_B, 111
product_B, 222
product_B, 33
product_B, 334
product_C, 212
product_C, 411
In jsp page, I can do iteratoring to get each element like product_x and number display row by row in table
Now the requirement is changed to get no duplicate key(product_X) displayed in page, but all the number that belongs to same product key should be displayed alongside product key display.
that means to display like this:
product_A aaa bbb ccc ddd eee
product_B 111 222 33 334
product_C 212 411
The condition is i can not change the original query, what i need to do reorganize the each row object and change the display like above
I was trying to add each elements include product key and number to the hashmap as key value pair
and then plan to do data structure change. But the hashmap does not support duplicate keys. Now i have no idea of implemeting this
Any of you has solution to it?
Appreciated!
Very junior programmerMy testing code according to what you guys suggest as below:
Hashtable map = new Hashtable();
String[] strArray1 = { "PRODUCT_A","PRODUCT_A","PRODUCT_A","PRODUCT_A","PRODUCT_A","PRODUCT_A",
"PRODUCT_B","PRODUCT_B","PRODUCT_B","PRODUCT_B","PRODUCT_B","PRODUCT_B",
"PRODUCT_C","PRODUCT_C","PRODUCT_C","PRODUCT_C","PRODUCT_C","PRODUCT_C",
String[] strArray2 = { "1000","1001","1002","1003","1004","1005",
"2000","2001","2002","2003","2004","2005",
"3000","3001","3002","3003","3004","3005"};
for (int i = 0; i < strArray1.length; i++) {
String productKey = strArray1;
String productNumber = strArray2[i];
List list = (ArrayList) map.get(productKey);
if (list == null)
map.put(productKey, list = new ArrayList());
list.add(productNumber);
System.out.println(" map.size(): " + map.size());
Enumeration emuKey = map.keys();
while(emuKey.hasMoreElements()){
String productKey = (String)emuKey.nextElement();
System.out.println("PRODUCT: " + productKey);
ArrayList list = (ArrayList)map.get(productKey);
for(int i=0; i<list.size();i++){
System.out.println("list["+i+"]: " + (String)list.get(i));
output:
map.size(): 3
PRODUCT: PRODUCT_C
list[0]: 3000
list[1]: 3001
list[2]: 3002
list[3]: 3003
list[4]: 3004
list[5]: 3005
PRODUCT: PRODUCT_B
list[0]: 2000
list[1]: 2001
list[2]: 2002
list[3]: 2003
list[4]: 2004
list[5]: 2005
PRODUCT: PRODUCT_A
list[0]: 1000
list[1]: 1001
list[2]: 1002
list[3]: 1003
list[4]: 1004
list[5]: 1005
With all your suggestion, it finally works. thanks! -
Map that allows duplicate keys
Is there a map that allows duplicate keys? The get(Object key) method will then return a Collection.
Thanks, I made my own class with some help from previous threads.
private class DuplicateMap {
private Map map = new HashMap();
public void put(Object key, Object value) {
List existing = (List)map.get(key);
if (existing == null) {
List list = new ArrayList();
list.add(value);
map.put(key, list);
} else {
existing.add(value);
public List get(Object key) {
List returnValue = (List)map.get(key);
if (returnValue == null) {
returnValue = new ArrayList();
return returnValue;
} -
Allow duplicate key & value in collection
Hello Experts,
I have once scenario where I have to store duplicate keys (string) and values (string) in Map. I tried with MultiHashMap (Apache) but it's very specific to datatype. It will only allow "string" key and "integer" value.
How can I do it? Any help will be appreciated.
Regards,
SomnathStupid question perhaps, but a regular HashMap with a String as a key and an ArrayList as a value doesn't cut it? You really NEED duplicate keys also?
EDIT: yes that is a stupid suggestion; of course you need duplicate keys when it is in fact a duplicate key/value pair that we're talking about.
It will only allow "string" key and "integer" value.When I look at the Javadoc I see it is controlled by generics, just like the regular Map type. Here, even in this very old javadoc:
http://commons.apache.org/collections/api-2.1.1/org/apache/commons/collections/MultiHashMap.html
You can see that put() takes two Object values, not a String and an Integer. -
Error in Executing a Interface -- Index Duplicate Keys
Hi All,
I ran my Interface 2 times , it was working fine..... but after that when I ran I got these Error...where I am doing the mistake.............
KM I used :
LKM SQL to ORACLE
IKM ORACLE INCREEMENTAL UPDATE
CKM ORACLE
The Step I am getting this Error is : Create Unique Index on Flow Table
1452 : 72000 : java.sql.SQLException: ORA-01452: cannot CREATE UNIQUE INDEX; duplicate keys found
java.sql.SQLException: ORA-01452: cannot CREATE UNIQUE INDEX; duplicate keys found
at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:125)
at oracle.jdbc.driver.T4CTTIoer.processError(T4CTTIoer.java:316)
at oracle.jdbc.driver.T4CTTIoer.processError(T4CTTIoer.java:282)
at oracle.jdbc.driver.T4C8Oall.receive(T4C8Oall.java:639)
at oracle.jdbc.driver.T4CPreparedStatement.doOall8(T4CPreparedStatement.java:185)
at oracle.jdbc.driver.T4CPreparedStatement.execute_for_rows(T4CPreparedStatement.java:633)
at oracle.jdbc.driver.OracleStatement.doExecuteWithTimeout(OracleStatement.java:1086)
at oracle.jdbc.driver.OraclePreparedStatement.executeInternal(OraclePreparedStatement.java:2984)
at oracle.jdbc.driver.OraclePreparedStatement.executeUpdate(OraclePreparedStatement.java:3057)
at com.sunopsis.sql.SnpsQuery.executeUpdate(SnpsQuery.java)
at com.sunopsis.dwg.dbobj.SnpSessTaskSql.execStdOrders(SnpSessTaskSql.java)
at com.sunopsis.dwg.dbobj.SnpSessTaskSql.treatTaskTrt(SnpSessTaskSql.java)
at com.sunopsis.dwg.dbobj.SnpSessTaskSqlI.treatTaskTrt(SnpSessTaskSqlI.java)
at com.sunopsis.dwg.dbobj.SnpSessTaskSql.treatTask(SnpSessTaskSql.java)
at com.sunopsis.dwg.dbobj.SnpSessStep.treatSessStep(SnpSessStep.java)
at com.sunopsis.dwg.dbobj.SnpSession.treatSession(SnpSession.java)
at com.sunopsis.dwg.cmd.DwgCommandSession.treatCommand(DwgCommandSession.java)
at com.sunopsis.dwg.cmd.DwgCommandBase.execute(DwgCommandBase.java)
at com.sunopsis.dwg.cmd.e.i(e.java)
at com.sunopsis.dwg.cmd.g.y(g.java)
at com.sunopsis.dwg.cmd.e.run(e.java)
at java.lang.Thread.run(Unknown Source)
Thanks
AK
Message was edited by:
AnandaHi Anand-
This is completely data issue, when executing the unique index step it will create unique index with the column name you mentioned.
When you ran the first two loads there was no duplicate keys found in the data that's why you didn't get the error but the third run you got the problem.
Check your data records and made changes in the KM as Bouch told if you don't want to create unique index.
Thanks & Regards,
Saravanan Rajavel -
Db adaptor for insert- SQLException: [SQL0803] Duplicate key value specified
While invoking db adaptor for insert on table 1 selecting values form another table, i am gtting error ; before3 insert i am updating table 2nd using db adaptor
QUERY insert into CRPDTA.F5504579 (SELECT * FROM CRPDTA.F5504571 WHERE PAHDC=#v_updatedRecord_HDC)
Error :
Non Recoverable System Fault :
<bpelFault><faultType>0</faultType><bindingFault xmlns="http://schemas.oracle.com/bpel/extension"><part name="summary"><summary>Exception occured when binding was invoked. Exception occured during invocation of JCA binding: "JCA Binding execute of Reference operation 'insert_Ledger_F5504579' failed due to: Pure SQL Exception. Pure SQL Execute of insert into CRPDTA.F5504579 (SELECT * FROM CRPDTA.F5504571 WHERE PAHDC=?) failed. Caused by java.sql.SQLException: [SQL0803] Duplicate key value specified.. The Pure SQL option is for border use cases only and provides simple yet minimal functionality. Possibly try the "Perform an operation on a table" option instead. This exception is considered not retriable, likely due to a modelling mistake. To classify it as retriable instead add property nonRetriableErrorCodes with value "--803" to your deployment descriptor (i.e. weblogic-ra.xml). To auto retry a retriable fault set these composite.xml properties for this invoke: jca.retry.interval, jca.retry.count, and jca.retry.backoff. All properties are integers. ". The invoked JCA adapter raised a resource exception. Please examine the above error message carefully to determine a resolution. </summary></part><part name="detail"><detail>[SQL0803] Duplicate key value specified.</detail></part><part name="code"><code>-803</code></part></bindingFault></bpelFault>
Please suggest....Easter1976 wrote:
Hi please can you help me. I think I am having problems with tranactions. I am deleting from a table and then inserting in the same table with the same key that I have just deleted. Simple then - don't do that. It suggests a flaw in the design. Either use a new key or do an update.
Note that you would get a duplicate key error if the table is set up such that it doesn't
actually delete but doesn't something such as creating a log entry with a delete flag set. -
We have been seeing the following 'warnings' in the event log of our BizTalk machine since upgrading to BTS 2006. They seem to occur randomly 6 or 8 times per day.
Does anyone know what this means and what needs to be done to clear it up? we have only one BizTalk server which is running on only one machine.
I am new to BizTalk, so I am unable to find how many tracking host instances running for BizTalk server. Also, can you please let me know that we can configure only one instance for one server/machine?
Source: BAM EventBus Service
Event: 5
Warning Details: Execute batch error. Exception information: TDDS failed to batch execution of streams. SQLServer: bizprod, Database: BizTalkDTADb.Cannot insert duplicate key row in object 'dta_MessageFieldValues'
with unique index 'IX_MessageFieldValues'. The statement has been terminated..Other than ensuring that there exists a separate and single tracking host instance, you're getting an error about duplicate keys.. which implies that you're trying to Create a BAM Activity twice with the same data.
I suggest you have a in-depth examination of the BAM (TPE or API) associated with the orchestration. In TPE ensure that the first binding you select is the "Instance Id" or "Message Id" before going ahead to map the ports or others.
Regards. -
The record has duplicate key values - "Include in Unique Index" checkbox missing
I have a Silverlight client app that I'm developing in Lightswitch in VS2013 Ultimate Update 1, and have run into a problem when adding records.
I am working against an external SQL Server 2008 database, and the table in question only has the primary key constraint, meaning that the ID field is an identity field, set as the primary key.
When I try and add records to the table from the app, I get an error "The Shiur record has duplicate key values." This seems to happen when I add a row that has the same Speaker as an existing one. If I add one with a new Speaker then
it inserts OK.
Whilst searching for information on this error, I saw many comments around about there being a problem in earlier releases with the "Include in Unique Index" not working properly. This looked like my problem, except for two points...
1) This table doesn't have anything in a unique index (as far as I know), as I never set it up to have any. You can see the details here...
This looks to me like there is only the one index, which is the primary key one.
2) The "Include in Unique Index" checkbox doesn't appear on my Properties panel at all. If I open the table in the designer, then click in the Speaker row, I don't see "Include in Unique Index" at all...
Actually, I don't see "Include in Unique Index" at all, irrespective of what I click. It's just not there.
So, I don't seem to have a unqiue constraint to violate, and VS doesn't show me the "Include in Unique Index" to allow me to check this, but I still get the error on insert. Anyone any ideas what's going on here?
Thanks
FREE custom controls for Lightswitch! A collection of useful controls for Lightswitch developers.
Download from the Visual Studio Gallery.
If you're really bored, you could read about my experiments with .NET and some of Microsoft's newer technologies at
http://dotnetwhatnot.pixata.co.uk/Hi Alan,
'Include in Unique Index' is for intrinsic database entity properties.
Ah, that explains why I can't see it then :)
Is LightSwitch or SQL throwing the error?
Ah, you're a genius! Well, not quite, but your question led me to the answer.
For some odd reason, the primary key fields on my tables seem to have lost their identity setting, so when it tried to insert a new record, the ID wasn't automatically increased, so was going in as zero. This worked fine for the first insert, as there wasn't
a record with zero ID, but failed for the second.
Changed the ID fields to be identity, and all works fine now :)
Thanks very much.
FREE custom controls for Lightswitch! A collection of useful controls for Lightswitch developers.
Download from the Visual Studio Gallery.
If you're really bored, you could read about my experiments with .NET and some of Microsoft's newer technologies at
http://dotnetwhatnot.pixata.co.uk/ -
Inbound IDOC processing, error duplicate key
We want to retrieve certain order-idocs in our system, before they are processed, to change AND insert segment data.
Flow we use in our current program
- DOC_STATUS_WRITE_TO_DATABASE
to change the status of the idoc (ok) (status 69)
- EDI_DOCUMENT_OPEN_FOR_EDIT (ok)
- EDI_CHANGE_DATA_SEGMENTS (ok)
- EDI_DOCUMENT_CLOSE_EDIT => not ok
This program gives SAPSQL error
Via debugging, we see that a new idoc number is
called (save as backup idoc ?), but we want the
current IDOC to be processed.
The system wants to insert in EDID4 => dump :
"Use an ABAP/4 Open SQL array insert only if you
are sure that none of the records passed already
exists in the database."
( I prefer to use these standard functions, in stead of just deleting and inserting into "EDID4" )
regards,
answers will be rewarded.
code extract
INCLUDE ZBE01458_TOP.
INITIALIZATION.
V_EDIT_STATUS = '69'.
V_PROCESSED_STATUS = '32'.
start-of-selection.
clear t_edidc. refresh t_edidc.
SELECT * FROM EDIDC into table t_edidc
WHERE DOCNUM in S_docnum
and mestyp in S_mestyp
and idoctp in S_idoctp
and credat in S_credat
and rcvpor in S_rcvpor
and rcvprt in S_rcvprt
and rcvprn in S_rcvprn
and sndpor in S_sndpor
and sndprt in S_sndprt
and sndprn in S_sndprn
and status in S_status.
loop at t_edidc.
move t_edidc-docnum to v_docnum.
refresh v_status.
V_STATUS-docnum = V_DOCNUM.
V_STATUS-status = V_EDIT_STATUS.
clear EDIDS.
select single * from EDIDS where docnum = v_docnum.
if sy-subrc = 0.
MOVE EDIDS-STACOD to V_STATUS-STACOD.
endif .
APPEND V_STATUS.
PERFORM CHANGE_IDOC_STATUS tables V_STATUS USING V_DOCNUM.
changing part for DEDIDD "idoc data
PERFORM OPEN_IDOC_FOR_CHANGE.
PERFORM CHANGE_IDOC.
PERFORM CLOSE_IDOC_FOR_CHANGE.
refresh v_status.
V_STATUS-docnum = V_DOCNUM.
V_STATUS-status = V_PROCESSED_STATUS.
APPEND V_STATUS.
PERFORM CHANGE_IDOC_STATUS tables V_STATUS
USING V_DOCNUM.
endloop.
*& Form OPEN_IDOC_FOR_CHANGE
text
--> p1 text
<-- p2 text
FORM OPEN_IDOC_FOR_CHANGE.
CALL FUNCTION 'EDI_DOCUMENT_OPEN_FOR_EDIT'
EXPORTING
DOCUMENT_NUMBER = V_DOCNUM
ALREADY_OPEN = 'N'
IMPORTING
IDOC_CONTROL =
TABLES
IDOC_DATA = DEDIDD
EXCEPTIONS
DOCUMENT_FOREIGN_LOCK = 1
DOCUMENT_NOT_EXIST = 2
DOCUMENT_NOT_OPEN = 3
STATUS_IS_UNABLE_FOR_CHANGING = 4
OTHERS = 5
IF SY-SUBRC <> 0.
MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
ENDFORM. " OPEN_IDOC_FOR_CHANGE
*& Form CHANGE_IDOC
text
--> p1 text
<-- p2 text
FORM CHANGE_IDOC.
CALL FUNCTION 'EDI_CHANGE_DATA_SEGMENTS'
TABLES
IDOC_CHANGED_DATA_RANGE = DEDIDD
EXCEPTIONS
IDOC_NOT_OPEN = 1
DATA_RECORD_NOT_EXIST = 2
OTHERS = 3.
IF SY-SUBRC <> 0.
MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
ENDFORM. " CHANGE_IDOC
*& Form CLOSE_IDOC_FOR_CHANGE
text
--> p1 text
<-- p2 text
FORM CLOSE_IDOC_FOR_CHANGE.
CLEAR t_EDI_DS40.
t_edi_ds40-docnum = v_docnum.
t_edi_ds40-status = '51'.
t_edi_ds40-repid = sy-repid.
t_edi_ds40-tabnam = 'EDI_DS'.
t_edi_ds40-mandt = sy-mandt.
t_edi_ds40-stamqu = 'SAP'.
t_edi_ds40-stamid = 'B1'.
t_edi_ds40-stamno = '999'.
t_edi_ds40-stapa1 = 'Changes made to idoc ...'.
t_edi_ds40-stapa2 = t_new_kunnr.
t_edi_ds40-logdat = sy-datum.
t_edi_ds40-logtim = sy-uzeit.
APPEND t_edi_ds40.
CALL FUNCTION 'EDI_DOCUMENT_CLOSE_EDIT'
EXPORTING
DOCUMENT_NUMBER = V_DOCNUM
DO_COMMIT = 'X'
DO_UPDATE = 'X'
WRITE_ALL_STATUS = 'X'
TABLES
STATUS_RECORDS = t_EDI_DS40
EXCEPTIONS
IDOC_NOT_OPEN = 1
DB_ERROR = 2
OTHERS = 3
IF SY-SUBRC <> 0.
MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
ENDFORM. " CLOSE_IDOC_FOR_CHANGE
*& Form CHANGE_IDOC_STATUS
text
--> p1 text
<-- p2 text
FORM CHANGE_IDOC_STATUS tables P_IDOC_STATUS structure V_IDOC_STATUS
USING P_DOCNUM.
CALL FUNCTION 'IDOC_STATUS_WRITE_TO_DATABASE'
EXPORTING
IDOC_NUMBER = p_docnum
IDOC_OPENED_FLAG = ' '
NO_DEQUEUE_FLAG = 'X'
IMPORTING
IDOC_CONTROL =
TABLES
IDOC_STATUS = P_IDOC_STATUS
EXCEPTIONS
IDOC_FOREIGN_LOCK = 1
IDOC_NOT_FOUND = 2
IDOC_STATUS_RECORDS_EMPTY = 3
IDOC_STATUS_INVALID = 4
DB_ERROR = 5
OTHERS = 6
IF SY-SUBRC <> 0.
MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
else.
commit work.
ENDIF.
ENDFORM. " CHANGE_IDOC_STATUSUrmila,
I tried this sequence : code extract follows...
I got the duplicate key errors again.
what about delete first and then insert again in EDID4 table ?
source code extract:
INCLUDE ZBE01458_TOP.
INITIALIZATION.
V_EDIT_STATUS = '69'.
V_PROCESSED_STATUS = '32'.
V_SAPCODE = 'SAPE0184'.
start-of-selection.
clear t_edidc. refresh t_edidc.
SELECT * FROM EDIDC into table t_edidc
WHERE DOCNUM in S_docnum
and mestyp in S_mestyp
and idoctp in S_idoctp
and credat in S_credat
and rcvpor in S_rcvpor
and rcvprt in S_rcvprt
and rcvprn in S_rcvprn
and sndpor in S_sndpor
and sndprt in S_sndprt
and sndprn in S_sndprn
and status in S_status.
loop at t_edidc.
move t_edidc-docnum to v_docnum.
move-corresponding T_EDIDC to WA_EDIDC.
V_STA-docnum = v_docnum.
V_STA-status = '51'.
V_STA-repid = sy-repid.
V_STA-tabnam = 'EDI_DS'.
V_STA-mandt = sy-mandt.
V_STA-stamqu = 'SAP'.
V_STA-stamid = 'B1'.
V_STA-stamno = '999'.
V_STA-stapa1 = 'Changes made to idoc ...'.
t_edi_ds40-stapa2 = t_new_kunnr.
V_STA-logdat = sy-datum.
V_STA-logtim = sy-uzeit.
V_STA-STACOD = V_SAPCODE.
PERFORM OPEN_FOR_PROCESS.
PERFORM SET_IDOC_STATUS USING V_DOCNUM V_STA.
PERFORM CLOSE_IDOC_FOR_PROCESS.
PERFORM OPEN_IDOC_FOR_CHANGE.
PERFORM PROCESS_IDOC_STRUCTURE.
PERFORM CHANGE_IDOC.
PERFORM CLOSE_IDOC_FOR_CHANGE.
refresh v_status.
V_STATUS-docnum = V_DOCNUM.
V_STATUS-status = V_EDIT_STATUS.
V_STATUS-STACOD = V_SAPCODE.
clear EDIDS.
select single * from EDIDS where docnum = v_docnum.
if sy-subrc = 0.
MOVE EDIDS-STACOD to V_STATUS-STACOD.
endif .
APPEND V_STATUS.
PERFORM CHANGE_IDOC_STATUS tables V_STATUS USING V_DOCNUM.
endloop.
*& Form OPEN_IDOC_FOR_CHANGE
text
--> p1 text
<-- p2 text
FORM OPEN_IDOC_FOR_CHANGE.
CALL FUNCTION 'EDI_DOCUMENT_OPEN_FOR_EDIT'
EXPORTING
DOCUMENT_NUMBER = V_DOCNUM
ALREADY_OPEN = 'N'
IMPORTING
IDOC_CONTROL = WA_EDIDC
TABLES
IDOC_DATA = DEDIDD
EXCEPTIONS
DOCUMENT_FOREIGN_LOCK = 1
DOCUMENT_NOT_EXIST = 2
DOCUMENT_NOT_OPEN = 3
STATUS_IS_UNABLE_FOR_CHANGING = 4
OTHERS = 5
IF SY-SUBRC <> 0.
MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
ENDFORM. " OPEN_IDOC_FOR_CHANGE
*& Form CHANGE_IDOC
text
--> p1 text
<-- p2 text
FORM CHANGE_IDOC.
CALL FUNCTION 'EDI_CHANGE_DATA_SEGMENTS'
TABLES
IDOC_CHANGED_DATA_RANGE = DEDIDD
EXCEPTIONS
IDOC_NOT_OPEN = 1
DATA_RECORD_NOT_EXIST = 2
OTHERS = 3.
IF SY-SUBRC <> 0.
MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
ENDFORM. " CHANGE_IDOC
*& Form CLOSE_IDOC_FOR_CHANGE
text
--> p1 text
<-- p2 text
FORM CLOSE_IDOC_FOR_CHANGE.
CLEAR t_EDI_DS40.
t_edi_ds40-docnum = v_docnum.
t_edi_ds40-status = '69'.
t_edi_ds40-repid = sy-repid.
t_edi_ds40-tabnam = 'EDI_DS'.
t_edi_ds40-mandt = sy-mandt.
t_edi_ds40-stamqu = 'SAP'.
t_edi_ds40-stamid = 'B1'.
t_edi_ds40-stamno = '999'.
t_edi_ds40-stapa1 = 'Changes made to idoc ...'.
t_edi_ds40-stapa2 = t_new_kunnr.
t_edi_ds40-logdat = sy-datum.
t_edi_ds40-logtim = sy-uzeit.
APPEND t_edi_ds40.
CALL FUNCTION 'EDI_DOCUMENT_CLOSE_EDIT'
EXPORTING
DOCUMENT_NUMBER = V_DOCNUM
DO_COMMIT = 'X'
DO_UPDATE = 'X'
WRITE_ALL_STATUS = 'X'
TABLES
STATUS_RECORDS = t_EDI_DS40
EXCEPTIONS
IDOC_NOT_OPEN = 1
DB_ERROR = 2
OTHERS = 3.
IF SY-SUBRC <> 0.
MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
ENDFORM. " CLOSE_IDOC_FOR_CHANGE
*& Form CHANGE_IDOC_STATUS
text
--> p1 text
<-- p2 text
FORM CHANGE_IDOC_STATUS tables P_IDOC_STATUS structure V_IDOC_STATUS
USING P_DOCNUM.
CALL FUNCTION 'IDOC_STATUS_WRITE_TO_DATABASE'
EXPORTING
IDOC_NUMBER = p_docnum
IDOC_OPENED_FLAG = ' '
NO_DEQUEUE_FLAG = 'X'
IMPORTING
IDOC_CONTROL =
TABLES
IDOC_STATUS = P_IDOC_STATUS
EXCEPTIONS
IDOC_FOREIGN_LOCK = 1
IDOC_NOT_FOUND = 2
IDOC_STATUS_RECORDS_EMPTY = 3
IDOC_STATUS_INVALID = 4
DB_ERROR = 5
OTHERS = 6
IF SY-SUBRC <> 0.
MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
else.
commit work.
ENDIF.
ENDFORM. " CHANGE_IDOC_STATUS
*& Form OPEN_FOR_PROCESS
text
--> p1 text
<-- p2 text
FORM OPEN_FOR_PROCESS.
CALL FUNCTION 'EDI_DOCUMENT_OPEN_FOR_PROCESS'
EXPORTING
DB_READ_OPTION = DB_READ
DOCUMENT_NUMBER = V_DOCNUM
ENQUEUE_OPTION = SYNCHRONOUS
IMPORTING
IDOC_CONTROL = WA_EDIDC
EXCEPTIONS
DOCUMENT_FOREIGN_LOCK = 1
DOCUMENT_NOT_EXIST = 2
DOCUMENT_NUMBER_INVALID = 3
DOCUMENT_IS_ALREADY_OPEN = 4
OTHERS = 5
IF SY-SUBRC <> 0.
MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
ENDFORM. " OPEN_FOR_PROCESS
*& Form SET_IDOC_STATUS
text
--> p1 text
<-- p2 text
FORM SET_IDOC_STATUS USING P_DOCNUM P_STA.
CALL FUNCTION 'EDI_DOCUMENT_STATUS_SET'
EXPORTING
DOCUMENT_NUMBER = P_DOCNUM
IDOC_STATUS = P_STA
IMPORTING
IDOC_CONTROL = WA_EDIDC
EXCEPTIONS
DOCUMENT_NUMBER_INVALID = 1
OTHER_FIELDS_INVALID = 2
STATUS_INVALID = 3
OTHERS = 4
IF SY-SUBRC <> 0.
MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
ENDFORM. " SET_IDOC_STATUS
*& Form CLOSE_IDOC_FOR_PROCESS
text
--> p1 text
<-- p2 text
FORM CLOSE_IDOC_FOR_PROCESS.
CALL FUNCTION 'EDI_DOCUMENT_CLOSE_PROCESS'
EXPORTING
DOCUMENT_NUMBER = V_DOCNUM
BACKGROUND = NO_BACKGROUND
NO_DEQUEUE = ' '
IMPORTING
IDOC_CONTROL = WA_EDIDC
EXCEPTIONS
DOCUMENT_NOT_OPEN = 1
FAILURE_IN_DB_WRITE = 2
PARAMETER_ERROR = 3
STATUS_SET_MISSING = 4
OTHERS = 5
IF SY-SUBRC <> 0.
MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
ENDFORM. " CLOSE_IDOC_FOR_PROCESS -
Duplicate message and Duplicate key error in Moni and RWB
Hi,
I am getting very frequent issues of Duplicate messages in production system moni and RWB.
Moni error: (IDOC to JMS) Errors are coming in call adapter step:
com.sap.engine.interfaces.messaging.api.exception.MessagingException: Could not insert message 005056aa-730e-1ed4-a6c9-a01ee2b86cb3(INBOUND) into duplicate check table. Reason: com.sap.sql.exception.OpenSQLException: Connection reset by peer: socket write error OpenSQLExceptionCategories: [RECOVERABLE]
RWB error: (File toIdoc) Errors are coming in sender channel.
MP: exception caught with cause com.sap.engine.interfaces.messaging.api.exception.DuplicateMessageException: Message Id a6d559cf-b00c-11e4-b786-00000daf354a(OUTBOUND) already exists in duplicate check table: com.sap.sql.exception.OpenSQLIntegrityConstraintViolationException: Violation of PRIMARY KEY constraint 'PK__BC_MSG_D__99C1915D3DE9247A'. Cannot insert duplicate key in object 'SAPPGXDB.BC_MSG_DUP_CHECK'. The duplicate key value is (a6d559cf-b00c-11e4-b786-00000daf354a, OUTBOUND). OpenSQLExceptionCategories: [NON_TRANSIENT, INTEGRITY_CONSTRAINT_VIOLATION
Moni errors are manually reprocessed and RWB are automatic.
Can you please let me know if there is any solution available for these issues?
Thanks
Navneet.I'm getting the same issue at my current client:-
Putting message into send queue failed, due to: com.sap.engine.interfaces.messaging.api.exception.DuplicateMessageException: Message Id e1d4a31b-f0cc-11e4-c7fb-0000029706f7(OUTBOUND) already exists in duplicate check table: com.sap.sql.exception.OpenSQLIntegrityConstraintViolationException: ORA-00001: unique constraint (SAPSR3DB.SYS_C00188646) violated OpenSQLExceptionCategories: [NON_TRANSIENT, INTEGRITY_CONSTRAINT_VIOLATION]
I've tried restarting the SOAP channel but this has not resolved the problem.
Just read on another thread that this may be a misleading error message (see last post on the link). It may be an idea to increase the trace level temporarily and look for any other issues that may be the cause.
So far I've not seen any post that describes the error on the SOAP channel - only seeing it for JDBC & File. However it seems to be a common problem across a number of sender channels.
Maybe you are looking for
-
How do i set up "print to iPhoto" from pages
How do i set up "print to iPhoto" from pages
-
PS CS4 crash when attempting to view preferences
Hi all, I'm running Photoshop CS4 on Windows XP (32bit). Photoshop itself seems to work fine, but if I try to view certain menus such as preferences, it will display the "CS4 has encountered an error and needs to close" message before crashing out.
-
How do I freeze the screen so I can use a recipe?
How do I freeze the screen so I can set the ipad on a counter and use a recipe that's on the screen?
-
When to upgrade DAC to 10.1.3.4 during new multi-source OBIA implementation
I want to take advantage of the multi-source capabilities of DAC 10.1.3.4 on OBIA 7.9.5 as I need to bring in data from several production EBS instances. Do I need to create the Data Warehouse tables via DAC 7.9.5 or upgrade the Windows DAC client an
-
Illustrator for PC will not download. All other apps, no problem
Illustrator for PC will not download. All other apps, no problem