Microsoft KB Archive/57352

Passing a Two-Dimensional Array of Longs from COBOL to C

PSS ID Number: Q57352 Article last modified on 12-05-1990

3.00 3.00a MS-DOS

Summary: The two programs below demonstrate how a Microsoft COBOL program can pass a two-dimensional array of longs to a Microsoft C routine. 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 C, search in this Knowledge Base for the following word: COB2C 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; CL /c /Awlf C.C ; LINK /NOE COB MINITC C,,,LCOBOL LLIBCE; The following COBOL program is COB.CBL, which passes a two-dimensional array of longs to a C routine. The C routine then prints out the passed array. $SET LITLINK $SET ANS85 $SET BOUND IDENTIFICATION DIVISION. DATA DIVISION. WORKING-STORAGE SECTION. 01 I1 PIC 9. 01 J1 PIC 9. 01 T-TABLE. 02 T-FIELD OCCURS 2 TIMES. 05 THE-TABLE PIC 9(8) COMP-5 OCCURS 3 TIMES. PROCEDURE DIVISION. PERFORM VARYING I1 FROM 1 BY 1 UNTIL I1 > 2 PERFORM VARYING J1 FROM 1 BY 1 UNTIL J1 > 3 MOVE J1 TO THE-TABLE(I1, J1) END-PERFORM END-PERFORM. CALL “C_CProc” USING T-TABLE. STOP RUN. The following program is C.C, which displays the values contained in a passed two-dimensional array of longs: #include  void CProc(long IntTable[2][3]) { int i, j; for (i = 0; i < 2; i++) for (j = 0; j < 3; j++) printf(“Array [%i,%i]: %ld”, i, j, IntTable[i][j]); } COB.EXE produces the following output: Array [0,0]: 1 Array [0,1]: 2 Array [0,2]: 3 Array [1,0]: 1 Array [1,1]: 2 Array [1,2]: 3

Copyright Microsoft Corporation 1990.