It is possible to pass data between a COBOL program that calls a PowerCOBOL application using the POWEROPENFORM method noted above.
This is done simply by defining the same data item name(s) in both the COBOL program and the PowerCOBOL application at the appropriate locations using the IS GLOBAL EXTERNAL clause.
This clause should immediately follow the actual data item name in its COBOL declaration as in the example below:
01 Global-String Is Global External Pic X(23)
You may include any number of such definitions in your application. Within the PowerCOBOL application, you may define this in the form's WORKING-STORAGE SECTION under its DATA DIVISION. To do this, right-click on the form name and select this from the pop-up menu, or on in the WORKING-STORAGE SECTION of any event procedure within the form.
Note that if you place a Global External data declaration with a specific procedure of a PowerCOBOL form, this data is only available to the PowerCOBOL application within that specific procedure - it cannot be accessed from other procedures in the same form. If you want to share this data between multiple procedures, you must declare it in the form's WORKING-STORAGE section.
Within a COBOL application, you define this in the application's standard WORKING-STORAGE section.
Below is an example of a sample COBOL application that calls a PowerCOBOL form named "MainForm" contained in a module built into a .DLL named "Hello.DLL":
Notice that this program contains a Global External data declaration.
The Click event procedure of the MainForm form in the PowerCOBOL application contains a similar declaration as follows:
When the COBOL program shown in figure 9.6 is executed, it calls the MainForm form in the PowerCOBOL application.
MainForm is then displayed. When MainForm's command button control is clicked on and the event procedure shown in figure 9.7 is executed, the Global-String data passed from the COBOL program is displayed on the form: