Microsoft KB Archive/52172

From BetaArchive Wiki
The printable version is no longer supported and may have rendering errors. Please update your browser bookmarks and please use the default browser print function instead.

Passing a PIC X String from C to COBOL

PSS ID Number: Q52172 Article last modified on 12-05-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 PIC X string to a COBOL routine. This information about interlanguage calling applies to Microsoft COBOL versions 3.00 and 3.00a for MS-DOS and 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. A PIC X string is passed to the COBOL program through the linkage section. The COBOL program displays the passed string. $SET LITLINK IDENTIFICATION DIVISION. PROGRAM-ID. "_COBPROG“. DATA DIVISION. WORKING-STORAGE SECTION. LINKAGE SECTION. 01 FIELD1 PIC X(6). PROCEDURE DIVISION using FIELD1. DISPLAY”String from C: " FIELD1. STOP RUN. The following program is C.C, which passes a string to a called COBOL routine: #include <stdio.h> extern cdecl COBPROG(char *Cptr); char Cptr[] = “ABCDEF”; void main() { COBProg(Cptr); } To demonstrate these programs from an .EXE program, compile and link for MS-DOS as follows: COBOL COB.CBL; CL /c /Awlf C.C ; LINK /NOE C COB,,,LLIBCER LCOBOL; Compile and link for OS/2 protected mode as follows: PCOBOL COB.CBL; CL /c /Awlf /Lp C.C ; LINK /NOE /NOP C COB,,,LLIBCEP PCOBOL DOSCALLS; C.EXE produces the following output: String from C: ABCDEF

Copyright Microsoft Corporation 1990.