Microsoft KB Archive/57370

Passing a Two-Dimensional Array of Structures to COBOL

PSS ID Number: Q57370 Article last modified on 12-06-1990

3.00 3.00a | 3.00 3.00a MS-DOS | OS/2

Summary: The two programs shown below demonstrate how a Microsoft C program can pass a two-dimensional array of structures to a Microsoft COBOL routine. This information about interlanguage calling applies to Microsoft COBOL versions 3.00 and 3.00a for MS-DOS and MS OS/2.

More Information: For more examples of passing other types of parameters between COBOL and C, query on 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
The following COBOL program is COB.CBL, which is called from a C program. It is passed a two-dimensional array of structures, which it displays. $SET ANS85 $SET LITLINK IDENTIFICATION DIVISION. PROGRAM-ID. &quot;_CobProc“. DATA DIVISION. WORKING-STORAGE SECTION. 01 I1 PIC 9. 01 J1 PIC 9. LINKAGE SECTION. 01 THE-TABLE. 02 T-TABLE OCCURS 2 TIMES. 05 T-FIELD OCCURS 3 TIMES. 10 FIELD1 PIC 9(4) COMP-5. 10 FIELD2 PIC X(6). PROCEDURE DIVISION USING THE-TABLE. PERFORM VARYING I1 FROM 1 BY 1 UNTIL I1 > 2 PERFORM VARYING J1 FROM 1 BY 1 UNTIL J1 > 3 DISPLAY”Table[&quot; I1 &quot;][&quot; J1 &quot;]: &quot; FIELD1(I1, J1) DISPLAY &quot; &quot; FIELD2(I1, J1) END-PERFORM END-PERFORM. STOP RUN. The following program is C.C, which creates a two-dimensional array of structures that is passed to a called COBOL routine: #include  struct TableStruc { /* define structure / int TheInt; char String[6]; } TheTable[2][3]; extern void far cdecl CobProc(struct TableStruc TheTable[2][3]); void main { int i, j; for (i = 0; i < 2; i++) / initialize structure / for (j = 0; j < 3; j++) { TheTable[i][j].TheInt = j; Sprintf(TheTable[i][j].String, “[%1i][%1i]”, i, j); } CobProc(TheTable); / Call COBOL routine */ } To demonstrate these programs from an .EXE program, compile and link under DOS as follows: COBOL COB.CBL; CL /c /Awlf C.C ; LINK /NOE C COB,,,LLIBCE LCOBOL; Compile and link under OS/2 as follows: PCOBOL COB.CBL; CL /c /Awlf /Lp C.C ; LINK /NOD C COB,,,LLIBCEP PCOBOL DOSCALLS; COB.EXE produces the following output: Table[1][1]: 00000 [0][0] Table[1][2]: 00001 [0][1] Table[1][3]: 00002 [0][2] Table[2][1]: 00000 [1][0] Table[2][2]: 00001 [1][1] Table[2][3]: 00002 [1][2]

Copyright Microsoft Corporation 1990.