Microsoft KB Archive/57438

A Pascal Function Returning a Long Integer to COBOL

PSS ID Number: Q57438 Article last modified on 12-07-1990

3.00 3.00a MS-DOS

Summary: The two programs below demonstrate how a Microsoft Pascal function can return a long integer to a COBOL program. This information about interlanguage calling applies to Microsoft COBOL versions 3.00 and 3.00a for MS-DOS.

More Information: For more examples of passing other types of parameters between COBOL and Pascal, query on the following word: COB2PAS For a complete discussion about mixed-language programming with COBOL, search in the Software/Data Library for the following word: COBMIXED

Code Example
To demonstrate these programs from an .EXE program, compile and link as follows: COBOL COB.CBL; PAS1 P.PAS ; PAS2 LINK /NOE COB MINITP P,,,LCOBOL LIBPASE; Note that the above Pascal library LIBPASE.LIB may be called LIBPASER.LIB, depending on how you installed Pascal. The following COBOL program is COB.CBL, which calls a Pascal function that cubes a passed long integer. The returned value is then displayed. $SET LITLINK $SET RTNCODE-SIZE(4) IDENTIFICATION DIVISION. DATA DIVISION. WORKING-STORAGE SECTION. 01 LONGNUM PIC 9(8) COMP-5 VALUE 8. PROCEDURE DIVISION. CALL “P_Cube” USING BY VALUE LONGNUM. DISPLAY LONGNUM &quot; Raised to the 3rd power = &quot; RETURN-CODE. STOP RUN. The following program is P.PAS, which returns the cube (a number raised to the third power) of a passed long integer: module CubeProc; function Cube(i : integer4) : integer4; begin Cube := i * i * i; end; end. COB.EXE produces the following output: 000000008 Raised to the 3rd power = +000000512

Copyright Microsoft Corporation 1990.