[an error occurred while processing this directive]

HP OpenVMS Systems Documentation

Content starts here

HP COBOL
User Manual


Previous Contents Index

Sample Run of GETROOT (OpenVMS)


$ RUN GETROOT [Return]
Enter number (with decimal point): 25. [Return]
The square root is:     5.000000
     5.0000
Enter number (with decimal point): )HELLO [Return]
** INVALID ARGUMENT FOR SQUARE ROOT
Enter number (with decimal point): 1000000. [Return]
The square root is:  1000.000000
1,000.0000
Enter number (with decimal point): 2. [Return]
The square root is:     1.414214
     1.4142
Enter number (with decimal point): [Return]
$                                                   <>

12.7.2 Calling a BASIC Program

The rich, yet easily accessed features of BASIC make that language a natural environment for development of short routines to be called from COBOL. Example 12-15 shows one example of an HP COBOL program that calls a BASIC program.

Example 12-15 Calling a BASIC Program from a COBOL Program

IDENTIFICATION DIVISION.
PROGRAM-ID.    APPL.
******************************************************
* This  COBOL program accepts credit application     *
* information and passes this information to a BASIC *
* program that performs a credit analysis. Notice    *
* that the data passed to the BASIC program is in    *
* the standard binary format.                        *
******************************************************
DATA DIVISION.
WORKING-STORAGE SECTION.
01  APPLICATION-NUMBER   PIC 999.
01  C-APPLICATION-NUMBER PIC 9(3) COMP.
01  ANNUAL-SALARY        PIC 9(5).
01  C-ANNUAL-SALARY      PIC 9(5) COMP.
01  MORTGAGE-RENT        PIC 999.
01  C-MORTGAGE-RENT      PIC 9(3) COMP.
01  YEARS-EMPLOYED       PIC 99.
01  C-YEARS-EMPLOYED     PIC 9(2) COMP.
01  YEARS-AT-ADDRESS     PIC 99.
01  C-YEARS-AT-ADDRESS   PIC 9(2) COMP.
PROCEDURE DIVISION.
010-BEGIN.
    DISPLAY "Enter 3 digit application number".
    ACCEPT APPLICATION-NUMBER.
    IF APPLICATION-NUMBER = 999
    DISPLAY "All applicants processed" STOP RUN.
    MOVE APPLICATION-NUMBER TO C-APPLICATION-NUMBER.
    DISPLAY "Enter 5 digit annual salary".
    ACCEPT ANNUAL-SALARY.
    MOVE ANNUAL-SALARY TO C-ANNUAL-SALARY.
    DISPLAY "Enter 3 digit mortgage/rent".
    ACCEPT MORTGAGE-RENT.
    MOVE MORTGAGE-RENT TO C-MORTGAGE-RENT.
    DISPLAY "Enter 2 digit years employed by current employer".
    ACCEPT YEARS-EMPLOYED.
    MOVE YEARS-EMPLOYED TO C-YEARS-EMPLOYED.
    DISPLAY "Enter 2 digit years at present address".
    ACCEPT YEARS-AT-ADDRESS.
    MOVE YEARS-AT-ADDRESS TO C-YEARS-AT-ADDRESS.
    CALL "APP" USING BY REFERENCE C-APPLICATION-NUMBER
    C-ANNUAL-SALARY C-MORTGAGE-RENT
    C-YEARS-EMPLOYED C-YEARS-AT-ADDRESS.
    GO TO 010-BEGIN.
Example 12-16 shows the BASIC program APP called in Example 12-15, and sample output from the program's execution.

Example 12-16 BASIC Program "APP" and Output Data

10 SUB APP (A%,B%,C%,D%,E%)
40 IF A% = 999 THEN 999
50 IF B% => 26000 THEN 800
60 IF B% => 18000 THEN 600
70 IF B% > 15000 THEN 500
80 IF B% => 10000 THEN 400
90 GO TO 700
400 IF E% < 4 THEN 800
410 IF D% < 2 THEN 800
420 GO TO 800
500 IF E% < 4 THEN 700
510 GO TO 800
600 LET X% = B% / 12
650 IF C% => X%/4 THEN 670
660 GO TO 800
670 IF E% => 4 THEN 800
700 PRINT TAB(1);"APPLICANT NUMBER ";A%; " REJECTED"
710 GO TO 999
800 PRINT TAB(1);"APPLICANT NUMBER ";A%;" ACCEPTED"
999 SUBEND

Sample Run of APPL


$ RUN APPL
Enter 3 digit application number
376 [Return]
Enter 5 digit annual salary
35000 [Return]
Enter 3 digit mortgage/rent
461 [Return]
Enter 2 digit years employed by current employer
03 [Return]
Enter 2 digit years at present address
05 [Return]
APPLICANT NUMBER  376  ACCEPTED
Enter 3 digit application number
999 [Return]
All applicants processed

12.7.3 Calling a C Program

Calling a program or routine that is written in C allows you to take advantage of features of that language. Example 12-17 features a C routine that can be called from a COBOL program.

Example 12-17 has two global external variables, __Argc and **__Argv. Note that **__Argv[] has an extra level of indirection; it is a pointer to a pointer to an array.

Example 12-17 C Routine to Be Called from a COBOL Program

/* crtn - c function to test use of argc and argv in c routines
 *   called from HP COBOL  */

#include "cobfunc.h"
#include <stdio.h>

extern int _ _Argc;
extern char **_ _Argv[];
#define argc _ _Argc
#define argv (*_ _Argv)

void crtn()
{
 int i;

 i = 0;
 for (i = 0; i < argc; i++) {
  printf("argv[%d] = %s\n", i, argv[i]);
 }
}

Example 12-18 is a representation of how you can call a C program from your HP COBOL application. In this case, the C routine crtn (in Example 12-17) is called.

Example 12-18 Calling a C Program from a COBOL Program


       IDENTIFICATION DIVISION.
       PROGRAM-ID. CTEST.
       DATA DIVISION.
       WORKING-STORAGE SECTION.
       .
       .
       .

       PROCEDURE DIVISION.
       MAIN SECTION.
       A001-MAIN.
       .
       .
       .
           CALL "crtn".
           EXIT PROGRAM.
       END PROGRAM CTEST.

For information on handling LIB$INITIALIZE when calling a C program, see Appendix B.

12.8 Special Considerations for Interprogram Communication

Certain situations require special consideration when your programs will communicate with other programs.

12.8.1 CALL and CANCEL Arguments

The CALL verb with a data item and the CANCEL verb with either a literal or a data item are implemented by a Run-Time Library routine that finds the appropriate program.

On Tru64 UNIX, these language features are implemented using nlist . Because of this implementation, the following items will not work on stripped images (for additional information on the strip command, refer to strip(1)):

  • CALL data item
  • CANCEL statement
  • cobcall routine
  • cobcancel routine
  • cobfunc routine <>

On OpenVMS, these features are implemented by depositing information in compiler generated psects. <>

12.8.2 Calling OpenVMS Alpha and I64 Shareable Images (OpenVMS)

When calling a subprogram installed as a shareable image, the program name specified in the CALL statement can be either a literal or a data-name. The same is true for the CANCEL verb. For more information on shareable images refer to HP COBOL online help file and the OpenVMS Linker Utility Manual. <>

12.8.3 Calling Tru64 UNIX Shareable Objects (Tru64 UNIX)

When you call a subprogram contained in a shared object, the program name specified in the CALL statement must be a literal. The CANCEL verb cannot be applied to programs in shared objects. For more information on shared objects, refer to the Tru64 UNIX programming documentation.

12.8.4 Case Sensitivity on Tru64 UNIX

One difference between Tru64 UNIX and OpenVMS Alpha and I64 is case sensitivity. From program code creation, to your application internal operations, you must maintain an awareness of this issue when you consider porting COBOL source code between the platforms.

12.8.4.1 Linker Case Sensitivity

The linker on Tru64 UNIX is case sensitive. "JOB1" is not the same routine as "job1". However, COBOL is defined as a case insensitive language: CALL "job1" should invoke a routine whose PROGRAM-ID is JOB1. This is not true of case sensitive languages, such as C. The names option flag increases the flexibility of the HP COBOL compiler in communicating with case sensitive languages.

The names option has three values:

  • lower---Forces all external data names, PROGRAM-ID names, and CALL literals to be lowercase. This is the default.
  • upper---Forces all external data names, PROGRAM-ID names, and CALL literals to be uppercase.
  • as_is---The case of literals used in CALL literals is taken as is. This is useful when you are calling subroutines with mixed case (for example, GetStatusRoutine). Data items defined with EXTERNAL will be treated as lowercase. PROGRAM-ID names will be treated as uppercase.

The names option flag does not apply to the CANCEL verb or to the CALL verb used with a data item. These language features are meaningful only when both the calling program and the called program are HP COBOL programs.


Previous Next Contents Index