Microsoft KB Archive/57437

From BetaArchive Wiki

Passing a Record Structure from Pascal to COBOL by Reference

PSS ID Number: Q57437 Article last modified on 11-30-1990

3.00 3.00a MS-DOS

Summary: The two programs shown below demonstrate how a Microsoft Pascal program can call a COBOL program and pass it a user-defined record structure. 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, query in the Software/Data Library on the following word: COBMIXED

Code Example

To demonstrate these programs from an .EXE program, compile and link under DOS as follows: COBOL COB.CBL; PAS1 P.PAS ; PAS2 LINK /NOD P COB,,,LIBPASE LCOBOL; Please note that the above library for Pascal may be called LIBPASER instead of LIBPASE. This will depend on how you installed Pascal. The following COBOL program is COB.CBL, which is called from a Pascal program and is passed a user-defined record structure, which it then displays: $SET LITLINK IDENTIFICATION DIVISION. PROGRAM-ID. "_CobProg“. DATA DIVISION. WORKING-STORAGE SECTION. LINKAGE SECTION. 01 REC-1. 05 INTNUM PIC 9(4) COMP-5. 05 LONGNUM PIC 9(8) COMP-5. 05 THESTRING PIC X(8). PROCEDURE DIVISION USING REC-1. DISPLAY”Passed INTNUM : " INTNUM. DISPLAY “Passed LONGNUM :” LONGNUM. DISPLAY “Passed THESTRING :” THESTRING. STOP RUN. The following program is P.PAS, which initializes the user-defined record structure and then passes it to the COBOL routine: program pproc(input, output); TYPE TheRec = RECORD i : integer; j : integer4; TheString : STRING(8); END; procedure CobProg (vars PasRec : TheRec) [C]; extern; VAR PasRec : TheRec; begin PasRec.i := 206; PasRec.j := 98765; PasRec.TheString := ‘Pascal’; CobProg(PasRec); end. P.EXE produces the following output: Passed INTNUM : 00206 Passed LONGNUM : 000098765 Passed THESTRING : Pascal

Copyright Microsoft Corporation 1990.