How to Link COBOL & C Together on z/OS

How to Link COBOL & C Together on z/OS thumbnail
You can link programs created in different languages using ILC.

A highly secure enterprise operating system developed by IBM, z/OS powers large mainframe computers and provides an integrated environment for developing applications in various programming languages. You can use the interlanguage communication -- or ILC -- functionality built into z/OS to seamlessly link COBOL and C programs, as the operating system offers native support for this feature. You can call C routines from COBOL or call COBOL routines from C, or a combination of both, in much the same manner in which you would call local routines in each language.

Things You'll Need

  • IBM mainframe running z/OS
  • Enterprise COBOL for z/OS
  • z/OS XL C/C++
Show More

Instructions

    • 1

      Link your C program to call your COBOL program by declaring your C and COBOL functions as follows:

      Declare a function in C that passes an integer value (i) to COBOL:
      void CBLRTN(int );
      CBLRTN(i);

      Use the value “I” from the C program in your COBOL program:
      01 I PIC S9(9) BINARY.
      PROCEDURE DIVISION USING BY VALUE I.

    • 2

      Link your COBOL program to your C program by having the COBOL program call a C function and pass it a value, as follows:

      Call the C subroutine “CFUNC” from COBOL, passing the value “I”:
      01 I PIC S9(9) BINARY.
      CALL "CFUNC" USING BY VALUE I.

      Declare the function in C:
      void CFUNC(int i) {
      return i;
      }

    • 3

      Declare a “pragma_linkage” at the top of your C program to explicitly declare a linkage to COBOL, which is required by some compilers. The syntax for the pragma linkage is:
      “#pragma linkage(function, COBOL)”.

      You declare the pragma linkage and create a C function to pass a value to COBOL as follows:

      #pragma linkage(CBLRTN,COBOL)
      void CBLRTN(int i);
      CBLRTN(i);

      You then use the passed variable in your COBOL program as follows:

      01 I PIC S9(9) USAGE IS BINARY
      PROCEDURE DIVISION USING I.

    • 4

      Declare a “pragma linkage” at the top of your C program to explicitly link the COBOL program to C. This is required by some compilers. The pragma linkage is always done in the C program, even when the COBOL program is passing the value to the C program.

      You declare the variable in the COBOL program and call the C function as follows:

      01 I PIC S9(9) USAGE IS BINARY
      CALL 'CFUNC' USING BY CONTENT I.

      You then declare the pragma linkage to COBOL and define the function in C as follows:

      #pragma linkage(CFUNC,COBOL)
      void CFUNC(int p1) {
      }

Related Searches:

References

Resources

  • Photo Credit Ablestock.com/AbleStock.com/Getty Images

Comments

Related Ads

Featured