After adding the FILEIO5.Rep file to the project hierarchy, you should attempt to rebuild the FILEIO5.DLL file. When doing so, the following error will be encountered:
Figure 3.6 An error displayed when trying to build the FILEIO5.DLL program
The message displayed in the Builder window shown in Figure 3.6 is somewhat mysterious and warrants some explanation. When you create a COM Server FILEIO5.DLL, one of the files created with be named FILEIO5_DLL.ODL.
This .ODL contains a special interface definition language used by COM. The file created in this instance is shown in Figure 3.7.
// FILEIO5_DLL.odl [ uuid(9427D108-7ACB-4937-92CE-E143D9B4AC42), helpstring("FILEIO5.DLL"), version(1.0) ] library FILEIO5 { importlib("stdole2.tlb"); dispinterface _FILEIO5; [uuid(9D47C2A1-DF64-4710-BE9D-2BFA6FB930D9)] dispinterface _FILEIO5 { properties: methods: [id(1)] void CLOSE-FILE([in,out] decimal* RETURN-STATUS); [id(2)] void OPEN-FILE([in,out] decimal* RETURN-STATUS); [id(3)] void READ-FILE([in,out] decimal* RETURN-STATUS,[in,out] bstr* RETURN-RECORD); [id(4)] void INIT(); [id(5)] void _FINALIZE(); }; [ uuid(1A97EC50-A138-461C-BA4F-88BD0A65136C), version(1.0) ] coclass FILEIO5 { [default] dispinterface _FILEIO5; }; };
Figure 3.7 The FILEIO5.DLL.ODL file
The error message shown in Figure 3.6 notes an error on line 19 at position 25. Line 19 in this .ODL file contains:
[id(1)] void CLOSE-FILE([in,out] decimal* RETURN-STATUS);
If you count over 25 columns, you will find the hyphen character in the CLOSE-FILE method name.
This error is complaining about the use of a hyphen (“-“) in the COM interface. Hyphens are not allowed in the COBOL TO COM interface, so we must find every place a hyphen appears in either a method name or a LINKAGE SECTION data item name being passed to or from a method and change it. An underscore (“_”) is a good substitute.
This means we need to edit the FILEIO5.COB program and change the Method names and their LINKAGE SECTION parameter names from containing any hyphens to underscores.
The results of our changes are shown in Figure 3.8.
Identification Division. Class-ID. FILEIO5 Inherits FJBASE. Environment Division. Configuration Section. Repository. Class FJBASE. Object. Environment Division. Input-Output Section. File-Control. Select Infile Assign To "test.txt" Organization is Line Sequential File Status is Infile-Status. Data Division. File Section. FD Infile. 01 Infile-Record Pic X(132). Working-Storage Section. 01 Infile-Status Pic 99. 01 File-Opened-Flag Pic 9 Value 0. Procedure Division. Method-ID. OPEN_FILE. Data Division. Linkage Section. 01 Return_Status Pic 99. Procedure Division Using Return_Status. If File-Opened-Flag Not = 0 *> File is already open, so return error Move 99 To Return_Status Else Open Input Infile Move Infile-Status To Return_Status If Infile-Status = 0 Move 1 To File-Opened-Flag End-If End-If. End Method OPEN_FILE. Method-ID. CLOSE_FILE. Data Division. Linkage Section. 01 Return_Status Pic 99. Procedure Division Using Return_Status. If File-Opened-Flag = 0 *> File is not open, so return error Move 88 To Return_Status Else Close Infile Move Infile-Status To Return_Status Move 0 To File-Opened-Flag End-If. End Method CLOSE_FILE. Method-ID. READ_FILE. Data Division. Linkage Section. 01 Return_Status Pic 99. 01 Return_Record Pic X(132). Procedure Division Using Return_Status Return_Record. If File-Opened-Flag = 0 *> File is not open, so return error Move 88 To Return_Status Else Read Infile Move Infile-Status to Return_Status Move Infile-Record to Return_Record End-If. End Method READ_FILE. End Object. End Class FILEIO5.
Figure 3.8 The corrected FILEIO5 program having changed hyphens to underscores
Note that in making these changes you do not have to change all data items names to get rid of hyphens - only those that are used in the interface as LINKAGE SECTION items. You must also change method names and any public property names (we do not have any public property names in this example, however).
Now we can attempt to build this application again and we do not receive any errors.