We are going to call the elements developed in WINDEV (project, windows, analysis, and so on) from the Cobol language. The WLanguage code used from the external language will be dynamically compiled and run during its call.

This mode is illustrated by the City.cbl project (in Cobol format) supplied in the "ExternalLanguages\Cobol" sub-directory of the setup directory of WINDEV.

Note: The Cobol language does not allow you to use the HyperFileSQL engine. To handle the HyperFileSQL engine, perform the necessary WLanguage processes in WINDEV.

Implementation

Including the files of the Cobol interface of WINDEV

The following files must be included in a Cobol project in order to call the Cobol interface of WINDEV:

WDDEB.CBL

WDFIN.CBL

WINDEV.CPY

The following lines must be found in the code of the main ".CBL" file of your Cobol project:

These lines allow you to retrieve the minimum declarations required to use the external interface.

Loading the WINDEV library (WDL)

The WINDEV library (.WDL extension) contains all the project elements (windows, reports, classes, queries, analysis, ...). Therefore, it must be loaded in memory in order for its components to be called.

Caution: If the library to load contains windows, the code of each one of these windows must be included in the corresponding ".WDW" file ("Include the compiled code" must be checked in the "Details" tab of the description of each window).

All the WLanguage functions can be called from the external language. The behavior of these WLanguage functions as well as the returned values are identical whether they are called:

from WINDEV or

from the interface of external language

To find out the parameters and the return values of a WLanguage function, see the online help or the documentation about WLanguage.

The call to a WLanguage procedure from the external interface is performed by CallWD. For example:

* open the first window of the program that contains the menucall CALLWD using by reference "Open, menuWdn.wdw" & x"00"

2. Retrieving the events triggered in the WINDEV windows

The input in the WINDEV windows requires to retrieve the events triggered in these windows.

To retrieve the user events (click on a menu, on a button, ...), you must implement a system based on a loop in your Cobol program. This loop will remain active as long as the WINDEV window is opened and it will be used to intercept each user action.

To find out the type of action performed by the user, you have the ability to use a character string variable (in WLanguage) named 'WDKey'. This variable will be used in your WLanguage code to signal to the Cobol program which button has been pressed for example.

Example: Cobol code

* open the first window of the program that contains the menucall CALLWD usingby reference "Open,menuWdn.wdw" & x"00"* the program loops until the File Exit option* is selectedPerform MENUINPUT with test before until (WDKey = "ESC")...MENUINPUT.* perform the input of the menucall CALLWD usingby reference "Screen,Edit" & x"00"* the status report WDKey is set to *M* when a menu choice* was selectedif (WDKey = "*M*")move WDString to chn*---------------------------------------* Decode the selected option.* WDString contains the sequence of shortcut letters* that are used to select the menu choice*---------------------------------------if (Str = "FQ")Move "ESC" TO WDKeyend-if...end-if.

Code for intercepting the selection of "File..Exit" of the WINDEV "Menu" window:

* the program loops until the File Exit option* is selectedPerform MENUINPUT with test before until (WDKey = "ESC")...if (Str = "FQ")Move "ESC" TO WDKeyend-if...* Done...copy "wdfin.cbl".exit program returning zero.stop run.

When the user clicks "File..Exit", WDKey will be equal to "ESC".

Note: The WDKey variable being a character string, its content can be a detailed description of the action to perform. For example, "Close the application".