Double Factory pattern purposal as replacement for Double Check #2

Hi All,
Here is the code for the pattern proposal, its intended as a replacement for double checked locking, which was proved to be broken in 2001. Here is the code...
public class DoubleFactory {
   private static Object second_reference = null;
   public static Object getInstance() {
      Object toRet = second_reference;
         if (toRet == null) {
            second_reference = CreationFactory.createInstance();
            toRet = second_reference;
      return toRet;
   private DoubleFactory() {}
public class CreationFactory {
   private static Object instance = null;
   public static synchronized Object createInstance() {
      if (instance == null) {
         instance = new Object();
      return instance;
  }Also I have spent several months discussing this with Peter Haggar, who believes that this code is not guaranteed to work. However I have been unable to discern from his message why he believes this will not be guaranteed to work, and I am posting this here to attempt to find a clearer explanation or confirmation that the pattern I am purposing (Double Factory) is guaranteed to work.
Thanks,
Scott
---------------------------- Original Message ----------------------------
Subject: Re: [Fwd: Double Factory replacement for Double Check #2] From:
"Scott Morgan" <[email protected]>
Date: Fri, January 25, 2008 10:36 pm
To: "Peter Haggar" <[email protected]>
Hi Peter,
I appologize if my last response came accross as rude or something. If
my code is not guaranteed to work ok, can you help me understand why. I
am after all looking for a solution for all of us.
If my solution is wrong as you say because the member variables of the
singleton are not up to date. I understand this to mean that the
second_reference pointer is assigned to the memory where the instance
object will get created before the instance object even starts the
creation process (when the jvm allocates memory and then enters the
constructor method of the Singleton). This doesn't seem possible to me.
Can you refrase your statments, to help me understand your points?
If not I am happy to turn to the original wiki for discussion.
Thanks for your effort,
Scott
Thanks for asking my opinion, many times, then telling me I'm
wrong...wonderful. You are a piece of work my friend. For what it'sworth, your email below shows you still don't understand these issues
or what I was saying in my emails. I've been more than patient.
>
All the best. And by the way, your code is not guaranteed to work. It's not just me that's "wrong", it's also the engineers at Sun who
designed Java, the JVM, and the memory model, and countless people who
have studied it. I'm glad you have it all figured out.
>
Peter
"Scott Morgan" <[email protected]>
01/18/2008 12:47 PM
Please respond to
[email protected]
To
Peter Haggar/Raleigh/IBM@IBMUS
cc
Subject
Re: [Fwd: Double Factory replacement for Double Check #2]
Hi Peter,
Thanks I understand your position now. However am I still believe that
it will work and be safe;
1) the Singleton you show would be fully constructed (having exited theSingleton() method) before the createInstance() method would have
returned.
2) The second_reference could not be assigned until the createInstance()
method returns.
3) So by the time second_reference points to Singleton all of the valueswill be set.
>
>
I do understand that if the createInstance method was not synchronized(at the CreationFactory class level) that my logic would be flawed, but
since there is synchronization on that method these points are true, and
your comments about up-to-date values are not accurate.
>
Cheers,
Scott
>In your listing from your latest email T2 does encounter a sync block
on createInstance.
>>>>
No. T2 will call getInstance and see second_reference as non-null.second_reference was made non-null by T1.
>>
>>>>
What are you exactly are you refering to with the phrase 'up-to-datevalues'?
>>>>
Assume my singleton ctor is thus:
public class Singleton
private int i;
private long l;
private String str;
public Singleton()
i = 5;
l = 10;
str = "Hello";
T2 will get a reference to the Singleton object. However, because youaccess second_reference without synchronization it may not see i as 5,
l as 10 and str as "Hello". It may see any of them as 0 or null. This
is not the out of order write problem, but is a general visibility
problem because you are accessing a variable without proper
synchronization.
>>
Peter
"Scott Morgan" <[email protected]>
01/16/2008 11:38 PM
Please respond to
[email protected]
To
Peter Haggar/Raleigh/IBM@IBMUS
cc
Subject
Re: [Fwd: Double Factory replacement for Double Check #2]
Hi Peter,
In your listing from your latest email T2 does encounter a sync blockon createInstance.
>>
What are you exactly are you refering to with the phrase 'up-to-datevalues'?
In this code the Singleton should also be
A) non mutable (as in the instance of class Object in the example).
If the singleton was more complex then the code to populate it'svalues
would go inside the sync of createInstance().
B) mutable with synchronization on it's mutator methods.
In your article you mention out of order writes, which doesn't occurin
this code.
Cheers,
Scott
You read it wrong.
- T1 calls getInstance which in turn calls createInstance.
- T1 constructs the singleton in createInstance and returns to
getInstance.
- T1 sets second_reference to the singleton returned in getInstance. -T1 goes about its business.
- T2 calls createInstance.
- T2 sees second_reference as non-null and returns it
- Since T2 accessed second_reference without sync, there is noguarantee
that T2 will see the up-to-date values for what this object refers to.
- Therefore the code is not guaranteed to work.
>>>
If this is not clear:
- Re-read my email below
- Re-read my article
- If still not clear, google on Double Checked Locking and readanything
from Brian Goetz or Bill Pugh.
Peter
"Scott Morgan" <[email protected]>
01/13/2008 05:26 AM
Please respond to
[email protected]
To
Peter Haggar/Raleigh/IBM@IBMUS
cc
Subject
Re: [Fwd: Double Factory replacement for Double Check #2]
Hi Peter,
Thanks for the reply, I don't see how T2 would see the a referenceto
a
partialy initialized object before the createInstance() method had
returned. If T1 was in createInstance() when T2 entered
getInstance(), T2 would wait on the CreationFactory's class monitor to
wait to enter createInstance().
Or in other words in the line of code ....
second_reference = CreationFactory.createInstance();
The pointer second_reference couldn't be assigned to the singleton
instance when the synchronized createInstance() had fully constructed,initialized and returned the singleton instance. Before that the the
second_reference pointer would always be assigned to null. So any
thread entering getInstance() before createInstance() had returned
(for the first time) would wait on the CreationFactory's class monitor
and enter the createInstance() method.
>>>
So T2 will wait for T1.
Cheers,
Scott
PS I think I am writing requirements for my next project :)
Sorry for the delay...been in all day meetings this week.
You are correct...I had been reading your code wrong, my apologies.
My explanations, although correct, did not exactly correspond to your
code.
However, the code is still not guaranteed to work. Here's why:
Assume T1 calls getInstance() which calls createInstance() and returnsthe
singelton. It then sets second_reference to refer to that singleton.
So
far, so good. Now, T2 executes and calls getInstance(). It can see
second_reference as non-null, so it simply returns it. But, there
was
no
synchronization in T2's code path. So there's no guarantee that even
if
T2 sees an up-to-date value for the reference, that it will seeup-to-date
values for anything else, ie what the object refers to...it's
instance data. If T2 used synchronization, it would ensure that it
read
up-to-date
values when it obtained the lock. Because it didn't, it could see
stale
values for the object's fields, which means it could see a partially
constructed object.
>>>>
In the typical double-checked locking, the mistake is to assume theworst
case is that two threads could race to initialize the object. But
the worst case is actually far worse -- that a thread uses an object
which
it
believes to be "fully baked" but which is in fact not.
Peter
"Scott Morgan" <[email protected]>
01/03/2008 06:33 PM
Please respond to
[email protected]
To
Peter Haggar/Raleigh/IBM@IBMUS
cc
Subject
Re: [Fwd: Double Factory replacement for Double Check #2]
Hi Peter,
Thanks for responding, I am still thinking that your mis
interpreting
the code so I have rewritten it here (Replacing
DoubleFactory.instance with DoubleFactory.second_reference for
clarity). If the T1 burps (gets interrupted) in the createInstance
method it wouldn't have returned so the second_reference pointer
would have never been
assigned
so T2 would just try again upon entering the getInstance method. Orif
it had already entered getInstance it would be waiting to enter
(until T1 releases the lock on CreationFactory.class ) on the
createInstance method.
>>>>
public class DoubleFactory {
private static Object second_reference = null;
public static Object getInstance() {
Object toRet = second_reference;
if (toRet == null) {
second_reference =
CreationFactory.createInstance();
toRet = second_reference;
return toRet;
private DoubleFactory() {}
public class CreationFactory {
private static Object instance = null;
public static synchronized Object createInstance() {
if (instance == null) {
instance = new Object();
return instance;
Does this clear up my idea at all?
second_reference should be always pointing to
null
or
a fully initialized Object
(also referenced by the pointer named 'instance' ), I don't see howit would end up partially initialized.
>>>>
Thanks Again,
Scott
"It" refers to T2.
Your createInstance method is identical to my Listing 2 and is fine
and
will work.
Yes, the problem with your code is in getInstance.
>I don't see how the DoubleFactory getInstance method could bereturning
a partially initialized object at this point. If CreationFactoryalways
returns a fully initialized object and DoubleFactory only assigns a
new
reference/pointer to it how could DoubleFactory getInstance return a
reference/pointer to partially initialized object?
>>>>>>>
>>>>>
The reason it is not guaranteed to work is explained in my previousemails
and in detail in the article. However, I'll try again. Anytime you
access shared variables from multiple threads without proper
synchronization, your code is not guaranteed to work. Threads are
allowed
to keep private working memory separate from main memory. There are
2
distinct points where private working memory is reconciled with main
memory:
- When using a synchronized method or block - on acquisition of thelock
and when it is released.
- If the variable is declared volatile - on each read or write of
that
volatile variable. (Note, this was broken in pre 1.5 JVMs which isthe
reason for the caveat I previously mentioned)
Your createInstance method uses synchronization, therefore, the
reconciliation happens on lock acquisition and lock release. T1 can
acquire the lock in createInstance, make some updates (ie create an
object, run it's ctor etc), but then get interrupted before exiting
createInstance and therefore before releasing the lock. Therefore,
T1
has
not released the lock and reconciled its private working memory withmain
memory. Therefore, you have ZERO guarantee about the state of mainmemory
from another threads perspective. Now, T2 comes along and accesses
"instance" from main memory in your getInstance method. What will
T2
see?
Since it is not properly synchronized, you cannot guarantee that T2sees
the values that T1 is working with since T1 may not have completely
flushed its private working memory back to main memory. Maybe it
did completely flush it, maybe it didn't. Since T1 still hold the
lock,
you
cannot guarantee what has transpired. Maybe your JVM is not usingprivate
working memory. However, maybe the JVM your code runs on does or
will
some day.
Bottom line: Your code is not properly synchronized and is notguaranteed
to work. I hope this helps.
Peter
"Scott Morgan" <[email protected]>
01/03/2008 12:49 PM
Please respond to
[email protected]
To
Peter Haggar/Raleigh/IBM@IBMUS
cc
Subject
Re: [Fwd: Double Factory replacement for Double Check #2]
Hi Peter,
Thanks for your response, I don't follow what 'it' refers to in
the
phrase 'It can see'. So for the same reason that you state that
example 2 from your article I believe this class CreationFactory to
work flawlessly when a client object calls the createInstance
method.
>>>>>
I see this CreationFactory code as identical to your example 2 doyou agree with this?
>>>>>
public class CreationFactory {
private static Object instance = null;
public static synchronized Object createInstance() {
if (instance == null) {
instance = new Object();
return instance;
}Then my rational in the DoubleFactory class is that it can obtain a
reference/pointer to the fully initialized object returned bycalling the above code. I believe you think that the problem with
my code is
in
the DoubleFactorys getInstance method, is this correct?
I don't see how the DoubleFactory getInstance method could bereturning
a partially initialized object at this point. If CreationFactory
always
returns a fully initialized object and DoubleFactory only assigns a
new
reference/pointer to it how could DoubleFactory getInstance return a
reference/pointer to partially initialized object?
>>>>>
Thanks again,
Scott
public static synchronized Singleton getInstance() //0
if (instance == null) //1
instance = new Singleton(); //2
return instance; //3
This above code is fine and will work flawlessly.
Annotating my paragraph:
T1 calls getInstance() and obtains the class lock at //0. T1 "sees"
instance as null at //1 and therefore executes: instance = new
Singleton() at //2. Now, instance = new Singleton() is made up of
several lines of non-atomic code. Therefore, T1 could be
interrupted
after Singleton is created but before Singleton's ctor isrun...somewhere
before all of //2 completes. T1 could also be interrupted after
//2 completes, but before exiting the method at //3. Since T1 has
not
exited
its synchronized block it has not flushed its cache. Now assume T2
then
calls getInstance().
All still true to this point. However, with your code the nextparagraph
is possible, with the code above, it's not. The reason is that T2
would
never enter getInstance() above at //0 because T1 holds the lock. T2will
block until T1 exits and flushes it's cache. Therefore, the code
above
is
properly thread safe.
It can "see" instance to be non-null and thus
return it. It will return a valid object, but one in which its ctor
has
not yet run or an object whose
values have not all been fully flushed since T1 has not exited itssync
block.
"Scott Morgan" <[email protected]>
01/02/2008 06:10 PM
Please respond to
[email protected]
To
Peter Haggar/Raleigh/IBM@IBMUS
cc
Subject
Re: [Fwd: Double Factory replacement for Double Check #2]
Hi Peter,
Thanks for the response I understand the rational for inventing
the
double check anti pattern, I am sorry I still don't understand the
difference between your solution #2 and my CreationFactory class.
>>>>>>
From your article figure 2.public static synchronized Singleton getInstance() //0
if (instance == null) //1
instance = new Singleton(); //2
return instance; //3
If I understand your email correctly this figure 2 is also flawed,since...
>>>>>>
T1 calls getInstance() and obtains the class lock at //0. T1 "sees"
instance as null at //1 and therefore executes: instance = new
Singleton() at //2. Now, instance = new Singleton() is made up ofseveral lines of non-atomic code. Therefore, T1 could be
interrupted
after Singleton is created but before Singleton's ctor isrun...somewhere
before all of //2 completes. T1 could also be interrupted after
//2 completes, but before exiting the method at //3. Since T1 has
not
exited
its synchronized block it has not flushed its cache. Now assume T2
then
calls getInstance(). It can "see" instance to be non-null and thus
return it. It will return a valid object, but one in which its
ctor
has
not yet run or an object whose
values have not all been fully flushed since T1 has not exited itssync
block.
So is #2 is also flawed for this reason?
If so please revise your article, since I interpreted #2 as a
plausible
solution recommended by you (which lead me to the DoubleFactory
idea).
If not please help me understand the difference between #2 and my
CreationFactory class.
>>>>>>
Thanks,
Scott
#2 is in Listing 2 in the article. What I meant was to forget the
DCL
idiom, and just synchronize the method...that's what listing 2
shows.
DCL
was invented to attempt to get rid of the synchronization for 99.9%
of
the
accesses.
The solution I outlined in my email is using the DCL idiom, but on
a
1.5
or later JVM and using volatile.
You solution is not guaranteed to work. Here's why:
public class DoubleFactory {
private static Object instance = null;
public static Object getInstance() {
Object toRet = instance;
if (toRet == null) {
instance =
CreationFactory.createInstance();
toRet = instance;
return toRet;
private DoubleFactory() {}
public class CreationFactory {
private static Object instance = null;
public static synchronized ObjectcreateInstance()
//1
if (instance == null) {
instance = new Object(); //2
return instance;
} //3
}T1 calls createInstance() and obtains the class lock at //1. T1"sees"
instance as null and therefore executes: instance = new Object() at//2.
Now, instance = new Object() is made up of several lines of
non-atomic
code. Therefore, T1 could be interrupted after Object is created
but
before Object's ctor is run...somewhere before all of //2
completes.
T1
could also be interrupted after //2 completes, but before exiting
the
method at //3. Since T1 has not exited its synchronized block ithas
not
flushed its cache. Now assume T2 then calls getInstance(). It can"see"
instance to be non-null and thus return it. It will return a
valid object, but one in which its ctor has not yet run or an
object
whose
values have not all been fully flushed since T1 has not exited itssync
block.
The bottom line is that if you are accessing shared variables
between
multiple threads without proper protection, you are open for aproblem.
Proper protection is defined as: proper synchronization pre 1.5,
and
proper synchronization or proper use of volatile 1.5 or after.
Therefore, if you must use the DCL idiom you have one option: -
Use DCL with volatile on a 1.5 or later JVM.
>>>>>>>
You can also forget about DCL and just use synchronization (listing2
in
my article) or use a static field (listing 10 in my article).
I hope this clears it up.
Peter
"Scott Morgan" <[email protected]>
01/02/2008 04:00 PM
Please respond to
[email protected]
To
Peter Haggar/Raleigh/IBM@IBMUS
cc
Subject
Re: [Fwd: Double Factory replacement for Double Check #2]
Hi Peter,
I apologies for not understanding but I don't see what is
different
between the solution you purposed...
2) Don't use DCL but use synchronization
and the code that I am putting forward. Perhaps I do just notunderstand
but you seem to be contradicting yourself in this email?
I understand that you are saying in #2 that this will always 'work'
with
out any issues...
public static Object instance = null;
public static synchronized Object getInstance() {
if (instance == null) {
instance = new Object();
return instance;
But first you seem to say in the email that if T1 gets
interrupted
it
may leave the instance pointing to a partially initialized object?
So as far as I understand it the createInstance method in my
CreationFactory class should be successful (always retuning a
fully initialized object) for the same reason #2 is successful.
Please keep in mind that there are two different instancepointers
in
the code I sent you, one is part of the DoubleFactory class and
the other is part of the CreationFactory class.
>>>>>>>
Thanks for your time, just looking for better solutions!
Scott
Scott,
Your solution is not guaranteed to work for various reasons
outlined
in
the article. For example, you can still return from your code apartially
initialized object. This can occur if T1 gets interrupted beforeleaving
the synchronized method createInstance() and T2 calls
getInstance().
T2
can "see" toRet/instance as non-null but partially initialized
since
T1
has not fully flushed its values.
As of 1.5, Sun fixed various issues with the memory model that
were
broken. Double Checked Locking will still break unless you usevolatile
(which was fixed in 1.5). Therefore, the following code works:
volatile Helper helper;
Helper getHelper() {
if (helper == null)
synchronized(this) {
if (helper == null)
helper = new Helper();
return helper;
but the original DCL idiom will not work. So, your options are:
1) Use DCL with volatile (above)
2) Don't use DCL but use synchronization
3) Don't use DCL, but use a static field.
#2 and #3 are outlined in my article from 2002.
Hope this helps,
Peter
"Scott Morgan" <[email protected]>
12/26/2007 04:12 PM
Please respond to
[email protected]
To
Peter Haggar/Raleigh/IBM@IBMUS
cc
Subject
[Fwd: Double Factory replacement for Double Check #2]
Hi Peter,
Thanks for the article on the out of order write problem. Whatdo
you
think of this as a solution?
TIA,
Scott
---------------------------- Original Message----------------------------
Subject: Double Factory replacement for Double Check #2
From: "Scott Morgan" <[email protected]>
Date: Wed, December 26, 2007 2:55 pm
To: [email protected]
Hi Ward,
Here is a pattern submission
Double Factory
Lazy initialization of singletons in accepted for a while usingthe
double check pattern. However it has been discovered that the
double
check pattern isn't thread safe because of the out of order write
problem. This problem occurs when Threads entering the Singleton
Factory method return with a fully constructed, but partially
initialized, Singleton object.
>>>>>>>>
Therefore: It makes sense to look for a way to initializeSingletons
in
a Lazy and Thread Safe manor. The following illustrates a fairly
simple
solution...
package foo;
public class DoubleFactory {
private static Object instance = null;
public static Object getInstance() {
Object toRet = instance;
if (toRet == null) {
instance =
CreationFactory.createInstance();
toRet = instance;
return toRet;
private DoubleFactory() {}
public class CreationFactory {
private static Object instance = null;
public static synchronized ObjectcreateInstance()
if (instance == null) {
instance = new Object();
return instance;
This gets around the out of order write problem because all
Threads
waiting on the CreationFactory's Class monitor will have a fully
constructed and initialized instance when they actually exit the
createInstance method.
>>>>>>>>
>>>>>>>>
During runtime while the Singleton instance is getting created(constructed and initialized) there may be a few Threads waiting
on
the
CreationFactory Class's objects monitor. After that period all
the
Treads
accessing
the Singleton will have unsynchronized reads to the instance,
which
will
optimize execution.
References:
http://www.ibm.com/developerworks/java/library/j-dcl.html
Copyright 2007 Adligo Inc.

Scott-Morgan wrote:
Hi All,
Thanks for your comments, here are some more....
jtahlborn you state that
the only way to guarantee that a (non-final) reference assignment is visible across threads is through the use of volatile and synchronized,
From the jvm spec
http://java.sun.com/docs/books/jls/third_edition/html/memory.html
17.4.1 Shared Variables
Memory that can be shared between threads is called shared memory or heap memory.
All instance fields, static fields and array elements are stored in heap memory.
Since both the second_reference and instance fields are both static, they are shared and visible across all threads.Yes, all these things are shared across threads, however, if you keep reading, there is a notion of "correct" sharing. obviously these values may be visible, that's why double-checked locking was used for so long before people realized it was broken. it worked most of the time, except when it didn't, and that's what i'm trying to show. that the only way to correctly share state between threads is via synchronization points, the most common being volatile and synchronized (there are a couple of other less used ones which don't apply here). The articles you linked to below from ibm cover the "visibility" in great depth, this is exactly what i am referring to.
You also state that volatile is a solution, but you seem to rebut your self in stating that the overhead for volatile is almost as great as synchronization.
This article illustrates the solution, and also comments on the overhead of volatile.
http://www.ibm.com/developerworks/library/j-jtp03304/
linked from
http://www.ibm.com/developerworks/java/library/j-dcl.html
volatile is a solution, in that it is correct, and you avoid the appearance of synchronization each time. however, since the semantics of volatile were strengthened in the new memory model, using volatile will perform practically (if not exactly) the same as simply synchronizing each time. the article you link to says exactly this under the heading "Does this fix the double-checked locking problem?".
Also could you be more specific about the example at the end of the jvm memory spec page, like a section number?It's the very last thing on the page, the "discussion" under 17.9, where it mentions that changes to "this.done" made by other threads may never be visible to the current thread.

Similar Messages

  • How to replace one double quotes with two double quotes in XSLT

    How can I replace one double quote to a two double quote in a string in XSLT
    I am passing the parameter string to XSLT template contains the value as
    <xsl:variable name="Description">Hi! "How are you</xsl:variable>
    <xsl:variable name="VQuotes">""</xsl:variable>
    I nead the output as
    Hi! ""How are you.
    Tried with Translate function, but it did not work out
    <xsl:element name="DESCRIPTION_SHORT">
              <xsl:value-of select="translate($Description,'&quot;', VQuotes)" />
            </xsl:element>But it is giving the same result as Hi! "How are you
    When I tried with
    <xsl:element name="DESCRIPTION_SHORT">
              <xsl:value-of select="translate($Description,'&quot;', 'BB')" />
            </xsl:element>
    It gave the result as
    Hi! BHow are you.
    It is replacing only one character with one. how to make it for two characters.
    Am I doing anything wrong in syntax?
    Please help.
    Regards, Vignesh S

    Hi Vignesh,
    Try this.
    Its a two step process:
    Step1: Add the following template would be "called" to do the replacement as your want:
    <xsl:template name="string-replace-all">
    <xsl:param name="text" />
    <xsl:param name="replace" />
    <xsl:param name="by" />
    <xsl:choose>
    <xsl:when test="contains($text, $replace)">
    <xsl:value-of select="substring-before($text,$replace)" />
    <xsl:value-of select="$by" />
    <xsl:call-template name="string-replace-all">
    <xsl:with-param name="text"
    select="substring-after($text,$replace)" />
    <xsl:with-param name="replace" select="$replace" />
    <xsl:with-param name="by" select="$by" />
    </xsl:call-template>
    </xsl:when>
    <xsl:otherwise>
    <xsl:value-of select="$text" />
    </xsl:otherwise>
    </xsl:choose>
    </xsl:template>
    Step2: Call the above templeate in the place where you want to call, like this:
    <!--Define the variables-->
    <xsl:variable name="Description">Hi! "How are you</xsl:variable>
    <xsl:variable name="sQuotes">"</xsl:variable>
    <xsl:variable name="VQuotes">""</xsl:variable>
    <!--Following call the template which you have defined in step1-->
    <xsl:element name="DESCRIPTION_SHORT">
    <xsl:variable name="myVar">
    <xsl:call-template name="string-replace-all">
    <xsl:with-param name="text" select="$Description" />
    <xsl:with-param name="replace" select="$sQuotes" />
    <xsl:with-param name="by" select="$VQuotes" />
    </xsl:call-template>
    </xsl:variable>
    <xsl:value-of select="$myVar" />
    </xsl:element>
    I have tested this and works. And outputs as the following with two-double quote as you want.
    <DESCRIPTION_SHORT>Hi!
    ""How are you</DESCRIPTION_SHORT>
    If this answers your question please mark it accordingly. If this post is helpful, please vote as helpful by clicking the upward arrow mark next to my reply.

  • Check flag for double invoices in AR masterdata

    Hello all,
    Can you please tell me if there is any flag in AR masterdata transaction FD01 similar with the one in AP masterdata transaction FK01 - "check flag for double inv.".?
    Thank you,
    Daniel

    For customer, there is no such mechanism. There is NO TICK in customer for duplicate invoice.
    It is not required because the amount is incoming, where in case of customer the amount will be outgoing.
    Regards,
    Ravi

  • Check Flag for Double Invoices or Credit Memos

    hello
    can i one please explain me the effect of
    "Check Flag for Double Invoices or Credit Memos"
    please explain with explain
    thanks
    vijay

    as terms itself says that u can post the same invoice twice it helps u in posting the same invoice twice
    suppose u have post invoice 1103#
    now by mistake user trys to enter the sam e invoice to release the payment then system dispalys a messge wrning or error
    but to activate it u need to do the settings in spro-mminvoice---incoming invoice
    and mark the check box in vendor master

  • Check for double invoices

    Hi,
    1) Can someone explain me what is meant by "Check for double invoices " field in vendor master and its importance?
    2) I am also confused between  "Check for double invoices " filed in vendor master, and set check for Invoce duplication in "SPRO -> SAP Reference IMG -> Materials Management -> Logistics Invoice Verification -> Incoming Invoice -> Set check for duplicate invoices". Can some one exaplin that too?

    Hi,
    1) Can someone explain me what is meant by "Check for double invoices " field in vendor master and its importance?
    This field for vendor reference while doing MIRO
    2) I am also confused between "Check for double invoices " filed in vendor master, and set check for Invoce duplication in "SPRO -> SAP Reference IMG -> Materials Management -> Logistics Invoice Verification -> Incoming Invoice -> Set check for duplicate invoices". Can some one explain that too?
    here you can define criteria for duplicate invoice including reference field also
    In vendor master press F1 for duplicate invoice indicator ,you will get good info with Example.
    how it work
    check following link also
    [http://help.sap.com/saphelp_470/helpdata/en/ce/4f3e39ea3aee02e10000000a114084/content.htm]
    Regards
    kailas Ugale
    Edited by: kailasugale on Jan 16, 2012 2:43 PM

  • Trouble printing double-sided in Acrobat X Pro for Mac

    I just tried printing for the first time today, and my pages come out single-sided rather than double-sided, though I am using the same settings as before in v. 9. Nothing I do seems to matter. using a Xerox machine (office capacity; don't have the specs handy; a Work-Centre Pro something though). Is anyone experiencing this problem? If so, are there any solutions?
    Many thanks,
    Jim P

    Dear Mamak,
    Many thanks for the note.
    I followed your advice and dowloaded new drivers for my Canon MF4880dw.
    The filename was different than yours, because the model was different.
    However, I noticed that this last version I downloaded is pretty new (released in April), so I was hoping it would fix the problem. Also, it was the same file for all versions of Mac OS X from 10.5 through 10.8.
    Unfortunately, no luck: Acrobat still does not ask me to scan the reverse side. Maybe I should have uninstalled the printer before reinstalling it?
    I more or less solved the problem by scanning double-sided documents on Acrobat 7 for Windows (which I also have installed on my Mac), which is not optimal, but at least works.
    Any thoughts?
    Thank you again,
    Salvatore

  • Class not found for: double

    Does anyone know how to get the class for a primitive double?
    I am trying to invoke a method that has a double parameter and I need the primitive double class.
    java.lang.ClassNotFoundException: double

    http://java.sun.com/j2se/1.5.0/docs/api/java/lang/Doub
    le.html#TYPEThanks for responding but,
    I forgot to add that I am using j2se 1.4.2 so I dont have that class :-(
    I am I am not trying to invoke a method I am actually trying to get a method
    args = Class[]{Class.forName("double")};
    obj.getClass().getMethod(methodName, args)Message was edited by:
    jwstudent
    Message was edited by:
    jwstudent

  • Which number I have to call for double payment for ' document to go' see my bills.Save or print this page for your records. We'll also send you an email confirmation. Case ID: 341915446 You have chosen to call Apple later. When you're ready, call the phon

    Where I have to resolve my problem for double billing for an app I purchased. App under question is ' DOCS TO GO' both normal and premium version.
    Help me
    Thanks

    Where I have to resolve my problem for double billing for an app I purchased. App under question is ' DOCS TO GO' both normal and premium version.
    Help me
    Thanks

  • FK02 - Check Flag for Double Invoices or Credit Memos

    Hi,
    What is the transaction in customizing to set the parameters for check flag for double invoices or credit memos ? (ex: date, reference number, etc.) (so that a warning message will pop-up if  user tries to do such a transaction 2 times)
    The check box check double inv. is already cheked in FK02, but I want to set the different parameters.
    Julien

    OMRDC

  • Java rounding for Double data type

    Hi,
    Is there a way to change the default precision to 2 digits after decimal point for Double data type.

    java.text.DecimalFormat:
    import java.text.DecimalFormat;
    DecimalFormat format = new DecimalFormat("#.00");
    StringBuffer formatted = format.format(Math.PI, new StringBuffer(), new FieldPosition(0));
    System.out.println(formatted); // prints out 3.14Probably as applicable today as it was 3 years ago

  • BDC Ok-Code for Double Click

    Hi ,
    Could anyone let me know the BDC OK Code for Double click.
    I need to select a row by double clicking it in my recording but not able to capture the code for it.
    Please do the needful.
    Thanks in Advance,
    Sowmmya B

    Hi sowmmya,
    1. If the row you are talking about is
       ALV Grid OO concepts,
       then i think there is a problem.
       It won't work with BDC as u are trying.
    2. Well, for getting the code,
       before double clicking go in debug mode /H
       and then double click.
    3. Now in deubbing mode,
      see the value of sy-ucomm.
    regards,
    amit m.

  • Code for double clicking rows  in alvgrido/p and moving it to internal tabl

    hi,
    code for double clicking rows  in alvgrido/p and moving it to internal table

    hi,
          see the following code which uses layout , double_click event in ALVGRID.
    TABLES: mara,marc.
    DATA:obj_custom TYPE REF TO cl_gui_custom_container,
         obj_alv TYPE REF TO cl_gui_alv_grid.
    DATA: it_mara TYPE TABLE OF mara,
          wa_mara TYPE mara,
          wa_layout TYPE lvc_s_layo,
           wa_variant TYPE disvariant,
            x_save.
    DATA:it_marc TYPE TABLE OF marc,
          wa_marc TYPE marc.
    SELECT-OPTIONS: s_matnr FOR mara-matnr DEFAULT 1 TO 500.
    START-OF-SELECTION.
      SELECT * FROM mara INTO TABLE it_mara
        WHERE matnr IN s_matnr.
      CALL SCREEN '100'.
          CLASS cl_dbclick DEFINITION
    CLASS cl_dbclick DEFINITION.
      PUBLIC SECTION.
        METHODS dbl FOR EVENT double_click OF cl_gui_alv_grid
          IMPORTING e_row e_column.
    ENDCLASS.
    DATA: obj1 TYPE REF TO cl_dbclick.
          CLASS cl_dbclick IMPLEMENTATION
    CLASS cl_dbclick IMPLEMENTATION.
      METHOD dbl.
        IF e_row-rowtype = space AND NOT e_row-index IS INITIAL.
          READ TABLE it_mara INDEX e_row-index INTO wa_mara.
        SELECT * FROM marc INTO TABLE it_marc
        WHERE matnr = wa_mara-matnr.
            CALL METHOD obj_custom->free
            EXCEPTIONS
              cntl_error        = 1
              cntl_system_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.
          CALL SCREEN '200'.
        ENDIF.
      ENDMETHOD.                    "dbl
    ENDCLASS.                    "cl_dbclick IMPLEMENTATION
    *&      Module  USER_COMMAND_0100  INPUT
          text
    MODULE user_command_0100 INPUT.
      CALL METHOD obj_custom->free
        EXCEPTIONS
          cntl_error        = 1
          cntl_system_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.
      CASE sy-ucomm.
        WHEN 'BACK'.
          LEAVE PROGRAM.
      ENDCASE.
    ENDMODULE.                 " USER_COMMAND_0100  INPUT
    *&      Module  filldata  OUTPUT
          text
    MODULE filldata OUTPUT.
      CREATE OBJECT obj_custom
        EXPORTING
          container_name = 'CONTROL'.
      CREATE OBJECT obj_alv
        EXPORTING
          i_parent = obj_custom.
      CREATE OBJECT obj1.
      SET HANDLER obj1->dbl FOR obj_alv.
      CALL METHOD obj_alv->set_table_for_first_display
        EXPORTING
       i_buffer_active               =
       i_bypassing_buffer            =
       i_consistency_check           =
          i_structure_name              = 'MARA'
          is_variant                    = wa_variant
          i_save                        = x_save
       i_default                     = 'X'
          is_layout                     = wa_layout
       is_print                      =
       it_special_groups             =
       it_toolbar_excluding          =
       it_hyperlink                  =
       it_alv_graphics               =
       it_except_qinfo               =
       ir_salv_adapter               =
        CHANGING
          it_outtab                     = it_mara
       it_fieldcatalog               =
       it_sort                       =
       it_filter                     =
    EXCEPTIONS
       invalid_parameter_combination = 1
       program_error                 = 2
       too_many_lines                = 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.
    ENDMODULE.                 " filldata  OUTPUT
    *&      Module  STATUS_0100  OUTPUT
          text
    MODULE status_0100 OUTPUT.
      SET PF-STATUS 'STATUS'.
    SET TITLEBAR 'xxx'.
    ENDMODULE.                 " STATUS_0100  OUTPUT
    *&      Module  STATUS_0200  OUTPUT
          text
    MODULE status_0200 OUTPUT.
      SET PF-STATUS 'STATUS'.
    *  SET TITLEBAR 'xxx'.
    SUPPRESS DIALOG.
         SET PARAMETER ID 'MAT' FIELD wa_mara-matnr.
    LEAVE TO LIST-PROCESSING AND RETURN TO SCREEN 0.
    *WRITE:/ wa_mara-matnr,
           wa_mara-mbrsh,
           wa_mara-meins.
      CREATE OBJECT obj_custom
        EXPORTING
          container_name = 'CONTROL'.
      CREATE OBJECT obj_alv
        EXPORTING
          i_parent = obj_custom.
      CALL METHOD obj_alv->set_table_for_first_display
        EXPORTING
       i_buffer_active               =
       i_bypassing_buffer            =
       i_consistency_check           =
          i_structure_name              = 'MARC'
       is_variant                    = wa_variant
       i_save                        = x_save
       i_default                     = 'X'
       is_layout                     = wa_layout
       is_print                      =
       it_special_groups             =
       it_toolbar_excluding          =
       it_hyperlink                  =
       it_alv_graphics               =
       it_except_qinfo               =
       ir_salv_adapter               =
        CHANGING
          it_outtab                     = it_marc
       it_fieldcatalog               =
       it_sort                       =
       it_filter                     =
    EXCEPTIONS
       invalid_parameter_combination = 1
       program_error                 = 2
       too_many_lines                = 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.
    ENDMODULE.                 " STATUS_0200  OUTPUT
    *&      Module  layout  OUTPUT
          text
    MODULE layout OUTPUT.
      wa_layout-grid_title = 'MATERIAL DATA'.
      wa_layout-zebra = 'X'.
    wa_layout-edit = 'X'.
    ENDMODULE.                 " layout  OUTPUT
    *&      Module  variant  OUTPUT
          text
    MODULE variant OUTPUT.
      wa_variant-report = 'ZALV_GRID1'.
      x_save = 'A'.
    ENDMODULE.                 " variant  OUTPUT
    *&      Module  USER_COMMAND_0200  INPUT
          text
    MODULE user_command_0200 INPUT.
      CASE sy-ucomm.
        WHEN 'BACK'.
          CALL METHOD obj_custom->free
            EXCEPTIONS
              cntl_error        = 1
              cntl_system_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.
          LEAVE TO SCREEN '100'.
      ENDCASE.
    ENDMODULE.                 " USER_COMMAND_0200  INPUT
    thanks,
    raji
    reward if helpful

  • Curve 9300 problem ..... Please Help ! (SORRY FOR DOUBLE POST)

    SORRY FOR DOUBLE POST GUYS, it bugged and I don't know how to delete it ! I don't want to get an infraction :/ ..
    Hey Guys ! First of all, I'm new to the community and looking forward to be as active as possible to help people and get help from professionals ! (And sorry for my bad english tho :/..)
    So here's the problem ...... I bought a blackbery Curve 9300 today, and what happens, is when I try to update it, it gave me at first, error 507 (Which means there's no OS in the device I suppose) ... when I tried to update it again, it gets stuck on ''Reconnecting to JVN'' or ''JVM'' can't remember ..... ive been trying to find a solution for hours and stil no luck .... i tried pulling the battery out and putting it back in, but doesnt work ..... a pop up message told me to go to control panel, check for USB Root hub and put a check mark on a certain option, but they were already checked ..... this situation is extremely frustrating because the guy from whom i bought the phone doesn't answer anymore, and I don't really want to take it to a store to repair it for like 60-80 $ or whatever ..... if possible, I'd like to get some help please !!!
    Thank-You in advance guys !

    Hi 12khaled21,
    Welcome to the community.
    Error code 507  comes when there is no OS   installed in your device. 
    Try downloading appropriate OS and install it.
    Check this link KB10144 and reply back.
    Raj
    Click " Like " if you want to Thank someone.
    If Problem Resolves mark the post(s) as " Solution ", so that other can make use of it.

  • How to delete double contact using icloud with pc for iphone4

    hoe to delete double contact using icloud with pc for iphone4

    Delete Contacts from iPhone the Fast Way, All or Individually

  • How to get client side validation for double range and double field in stru

    Hi,
    I have achieved client side validation by using <html:javascript formName=""/>
    All fields shows client side validation but double field and double range field is not shows client side validation but shows server side validation.
    I am using Liferay jboss server.
    Please tell me a way to achieve client side validation for double field and double range.
    Thanks & Regards,
    Brijesh Baser

    I see in the query component there is a QueryListener and a QueryOperationListener. Have you tried letting Jdeveloper create methods for these in some backing bean, and putting in some debug code to see when these methods run? I would think one of them could very well be used to validate the input, somehow; if the input were bad you could just raise an exception and pass your error message, I bet.
    If not...
    I am pretty sure that there is an appendix in the Fusion Developer's Guide for Forms developers turned to Java...you might look at what it says for post query. I know in the 10.1.3.0 equivalent documentation, they gave reference to a method in the ViewObject which fired for each record after a query was run. You could definitely intercept this query return from there. In fact doing something like this may be something like what Frank N. was intending when he mentioned ViewObjects "validation". Not sure though. I am still learning what new features there are in 11g adf/bc.
    Good luck.

Maybe you are looking for