ITEM: AZ9881L

How to do dynamic loading in IBM COBOL SET for AIX


Question: How do you do dynamic loading of sub-programs in
          IBM COBOL SET for AIX.  The sub-programs can be either
          COBOL or C? 

Response:

IBM COBOL SET for AIX supports both dynamic call and static
call.

 A static call has the format: CALL "abcd", where "abcd" is
 the explicit name of the subprogram being called, and it
 is resolved at link-time by the linker.

 A dynamic call has the format: CALL PGM-NAME, where PGM-NAME
 is a data item that will contain the name of the subprogram
 being called.  In this case the aix file name and the name
 of the program being called must be the same.

Listed below are three sample program that show dynamic calling:
dl6.cbl  - COBOL main program that calls dl6a and dl6b.
dl6a.c   - C function called by dl6.
dl6b.cbl - COBOL program called by dl6.
----dl6.cbl ----
      * dl6:
      * - call C function - dl6a executable
      * - call "dl6b" with pgmname(mixed)
       Identification Division.
       Program-id. "dl6".
      *
       Environment Division.
       Configuration Section.
       Input-Output Section.
       File-control.
      *
       Data Division.
       File Section.
       Working-storage Section.
       01 var pic x(10).
       Linkage Section.
      *
       Procedure Division.
           move "dl6a" to var.
           display "Calling " var.
           call var.
           display "Calling " var.
           call var.
           move "dl6b" to var.
           display "Calling " var.
           call var.
           display "Calling " var.
           call var.
           stop run.
----dl6a.c----
void
dl6a()
{static int n = 123;
printf("C dl6a function.\\n");
n = n * 10;
printf("n = %d\\n", n);
}----dl6b.cbl----
       IDENTIFICATION DIVISION.
       PROGRAM-ID. "dl6b".
      *
       ENVIRONMENT DIVISION.
       CONFIGURATION SECTION.
       OBJECT-COMPUTER. ANY-THING.
      *
       DATA DIVISION.
       WORKING-STORAGE SECTION.
       77 num pic 9(4) binary value is zero.
      *
       PROCEDURE DIVISION.
       LA-START.
           display "COBOL dl6b function." upon console.
           add 111 to num.
           display "num = " num
           goback.
------
Compile with the following:

  cob2 dl6.cbl -o dl6
  cob2 dl6b.cbl -o dl6b
  xlc -o dl6a -edl6a dl6a.c

Enter export COBPATH=. \<-- COBPATH MUST BE SET

Enter ./dl6 to execute



Support Line: How to do dynamic loading in IBM COBOL SET for AIX ITEM: AZ9881L
Dated: June 1996 Category: N/A
This HTML file was generated 99/06/24~13:30:24
Comments or suggestions? Contact us