The module level ExecuteInDuplicate property controls the behavior of a PowerCOBOL .exe file when a user attempts to launch it for execution a second time. There are three values available for this property. They are listed with their related results below:
0 - Multi Instance - allows multiple instances of the application to be launched.
1 - Single Instance (Message) - only allows a single instance of the application to be executed and displays an error dialog box when the user tries to launch the application a second time.
2 -Single Instance (Activate) - only allows a single instance of the application to be executed and focuses the user on the currently running instance if he/she attempts to launch a second instance.
Note that PowerCOBOL treats multiple execution of an application in the same path separately. Therefore, PowerCOBOL recognizes an application that resides in another folder as a different application even if they were built from the same project file. For example, the following are different applications:
An application saved in the local path and same application saved in the network path.
An application copied to another path.
The Execute in Duplicate property is effective when the FileType property of module is "0-Execute Module". Note that, the ExecuteInDuplicate property should be used to prevent multiple access to a file. In cases where the same data file may be accessed concurrently from multiple instances of the same application (or from different applications), you need to use record file and/or record locking. For example, to open a file for exclusive use and lock it from other currently running applications:
FILE-CONTROL
SELECT LOCKFILE ASSIGN TO LF FILE STATUS IS LF-STATUS LOCK MODE IS EXCLUSIVE.
FILE
FD LOCKFILE GLOBAL. 01 OAREA PIC X.
WORKING-STORAGE
01 LF-STATUS PIC X(2) GLOBAL.
OPENED Event
ENVIRONMENT DIVISION. DATA DIVISION. WORKING-STORAGE SECTION. PROCEDURE DIVISION. OPEN OUTPUT LOCKFILE WITH LOCK IF LS-STATUS NOT = "00" THEN INVOKE POW-SELF "DisplayMessage" USING "OPEN ERROR!" INVOKE POW-SELF "Deactivate" END-IF.