Hi
Even Though there is a BADI (GOS_SRV_REQUEST) which does gets called when we select "Start Workflow" (Filter Value 'WF_START'). We can Raise the exception REJECTED (of the BADI Method START_SERVICE ) after checking for existing running instances (object key and business object is in parameter IS_LPOR);
However, system really ignores that exception and calls FM SWU_START_WITH_OBJECT to give the list of the workflows. Pressing the START on the WF list directly calls FM SWW_WI_START. There is no exit in between (not that I know of !!!).
So, in your case, it would be best to put a check inside your workflow as a first step, if there is a duplicate instance, use a Process Control step to cancel the current instance.
Make sure you EXCLUDE the current instance from the check. So the code will have to be changed a bit in the method which you will call as the first step.
Before the READ, remove the current instance from the Worklist:
Sort lt_worklist by WI_ID.
delete lt_worklist where WI_ID = WI ID of the WORKFLOW Which just started
Then use the Read table
READ TABLE lt_worklist TRANSPORTING NO FIELDS
WITH KEY wi_stat = 'STARTED'.
If SY-SUBRC = 0 - pass a flag to workflow - use process control step to self terminate.
regards,
Modak