Calling Intrinsics [ HP COBOL II/XL Programmer's Guide ] MPE/iX 5.0 Documentation
HP COBOL II/XL Programmer's Guide
Calling Intrinsics
The section explains some aspects of calling intrinsics. For more
information about HP Intrinsics, see the MPE XL Intrinsics Reference
Manual.
Using $CONTROL CALLINTRINSIC
Intrinsics are subprograms whose declarations reside in the intrinsic
file, SYSINTR.PUB.SYS. Ideally, your program always calls an intrinsic
with CALL INTRINSIC instead of CALL, and does not use the control option
CALLINTRINSIC.
The control option CALLINTRINSIC increases compile time because it causes
the compiler to search SYSINTR.PUB.SYS every time your program calls a
subprogram with CALL literal. If the subprogram declaration is in
SYSINTR.PUB.SYS, the compiler assumes that you intended to call it as an
intrinsic, and the compiler does the following:
* Issues a warning.
* Generates code for the subprogram as if your program had called it
as an intrinsic.
If you are not sure whether your program always calls an intrinsic with
CALL INTRINSIC, compile it with the CALLINTRINSIC control option, which
will identify all of the intrinsic calls that use CALL. In those calls,
change CALL to CALL INTRINSIC. Then, recompile your program without the
CALLINTRINSIC control option.
How Intrinsics Are Called
When your program calls a subprogram as an intrinsic, the compiler reads
from SYSINTR.PUB.SYS the following information about each formal
subprogram parameter:
* Whether the formal paramater is passed by reference or value.
Don't explicitly specify reference or value. For example, do not
include the character \ to pass a data item by value, or the @
sign to pass a data item by reference.
* The default value of the formal parameter.
This value is assigned to the formal parameter if your program
does not provide an actual parameter for it. Specify \\ for each
parameter omitted.
* The type of the formal parameter.
The compiler issues an error message if the types of the formal
and actual parameters are not compatible. See Table 4-8 for a
list of intrinsic parameter types and corresponding COBOL types.
* The alignment of the formal parameter.
The compiler issues an error message if the actual parameter does
not have the same alignment as the formal parameter.
Table 4-8 lists the intrinsic parameter types and their corresponding
COBOL types.
Table 4-8. Intrinsic Parameter Types and Corresponding COBOL Types
-----------------------------------------------------------------------------------------------------
| | | | | |
| | Full Name of | Size | COBOL Type | COBOL Type |
| Mnemonic | Intrinsic | in Bytes | (Passed by | (Passed by Value) |
| | Parameter Type | | Reference) | |
| | | | | |
-----------------------------------------------------------------------------------------------------
| | | | | |
| A | Array | n | USAGE DISPLAY | Numeric items (1) |
| | | | USAGE PACKED_DECIMALNonnumeric items (1)
| | | | Group item | |
| | | | | |
-----------------------------------------------------------------------------------------------------
| | | | | |
| B | Boolean | 1 | Group item | Numeric items |
| | | | | Nonnumeric items (1)
| | | | | |
-----------------------------------------------------------------------------------------------------
| | | | | |
| C | Character | 1 | USAGE DISPLAY | Numeric items |
| | | | Group item | Nonnumeric items (1)
| | | | | |
-----------------------------------------------------------------------------------------------------
| | | | | |
| - | Packed decimal | n | USAGE PACKED-DECIMAL[REVaBEG]cable[REV|END]
| | | | | |
-----------------------------------------------------------------------------------------------------
| | | | | |
| - | Entry point | 4 | S9(9) BINARY[REV BEG]ot compatible[REV|END]
| | | | | |
-----------------------------------------------------------------------------------------------------
| | | | | |
| - | External ASCII | n | USAGE DISPLAY | Not applicable[REV|END]
| | | | Group item[REV BEG] |
| | | | | |
-----------------------------------------------------------------------------------------------------
| | | | | |
| I16 | 16-bit signed integer 2 | S9(1)-S9(4) BINARY| Numeric items |
| | | | | |
-----------------------------------------------------------------------------------------------------
| | | | | |
| I32 | 32-bit signed integer 4 | S9(5)-S9(9) BINARY| Numeric items |
| | | | | |
-----------------------------------------------------------------------------------------------------
| | | | | |
| I64 | 64-bit signed integer 8 | S9(10)-S9(18) BINARYNumeric items |
| | | | | |
-----------------------------------------------------------------------------------------------------
| | | | | |
| - | Procedure | 0 | Not compatible | Not compatible |
| | | | | |
-----------------------------------------------------------------------------------------------------
| | | | | |
| REC | Record | n | USAGE DISPLAY | Numeric items (1) |
| | (generic structure) | USAGE PACKED-DECIMALNonnumeric items (1) [REV END]
| | | | Group item[REV BEG] |
| | | | | |
-----------------------------------------------------------------------------------------------------
| | | | | |
| R32 | 32-bit real | 4 | Not compatible[REV|BEG]eric items (2) [REV END]
| | | | | |
-----------------------------------------------------------------------------------------------------
| | | | | |
| R64 | 64-bit real | 8 | Not compatible[REV|BEG]eric items (2) [REV END]
| | | | | |
-----------------------------------------------------------------------------------------------------
| | | | | |
| R128 | 128-bit real | 16 | Not compatible | Not compatible |
| | | | | |
-----------------------------------------------------------------------------------------------------
| | | | | |
| U16 | 16-bit unsigned integer 2 | S9(1)-S9(4) BINARY| Numeric items |
| | | | | |
-----------------------------------------------------------------------------------------------------
| | | | | |
| U32 | 32-bit unsigned integer4[REV BEG] | S9(9) BINARY[REV END]umeric items |
| | | | | |
-----------------------------------------------------------------------------------------------------
| | | | | |
| U64 | 64-bit unsigned integer8[REV BEG] | S9(18) BINARY[REV END]meric items |
| | | | | |
-----------------------------------------------------------------------------------------------------
| | | | | |
| - | Constant address | 4 | Not compatible | Not compatible |
| | | | | |
-----------------------------------------------------------------------------------------------------
| | | | | |
| - | Local label address 4 | Not compatible | Not compatible[REV|BEG]
| | | | | |
-----------------------------------------------------------------------------------------------------
| | | | | |
| @32 | 32-bit address | 4 | S9(9) BINARY | Not compatible |
| | | | | |
-----------------------------------------------------------------------------------------------------
| | | | | |
| @64 | 64-bit address | 8 | S9(18) BINARY | Not compatible |
| | | | | |
-----------------------------------------------------------------------------------------------------
| | | | | |
| S | Set | 4 | Not compatible | Numeric items (1) [REV END]
| | | | | |
-----------------------------------------------------------------------------------------------------
(1) Size must match exactly. No type conversion is done.
(2) For R32, use S9(9) BINARY. For R64, use S9(18) BINARY.
[REV
BEG]
For BINARY fields, an intrinsic may return a value outside the range of
valid numbers for the COBOL type. Calculations with such values may
cause a SIZE ERROR. To prevent the error, use a MOVE statement to move
the contents of such fields to larger BINARY fields. For example, the
WHO intrinsic may return 16385 for the terminal parameter. Because the
terminal parameter is COBOL type S9(4) BINARY, the value of terminal can
be moved to a COBOL type S9(5) BINARY to match the type with the
contents.[REV END]
[REV BEG]
Passing Real Numbers to Intrinsics
Some intrinsics have parameters that are real numbers, for example PAUSE.
You can call these intrinsics by converting a numeric character string
representing the real number into floating-point format. The intrinsic
HPEXTIN converts a numeric character string into a floating-point value.
For more information about HPEXTIN, see the Compiler Library/XL Reference
Manual.
Example.
The following program reads a numeric value from the terminal, converts
the value to floating-point, and passes it to the PAUSE intrinsic.
001000 IDENTIFICATION DIVISION.
001100 PROGRAM-ID. COBPAUSE.
001200 DATA DIVISION.
001300 WORKING-STORAGE SECTION.
001400 01 CHAR-STRING PIC S999 SIGN IS LEADING SEPARATE.
001500 01 STRING-LEN PIC S9(4) BINARY.
001600 01 REAL-SECONDS PIC S9(9) BINARY VALUE ZERO.
001700 01 ERROR-CODE PIC S9(4) BINARY VALUE ZERO.
001800 PROCEDURE DIVISION.
001900 FIRST-PARA.
002000 DISPLAY "Enter number of seconds to pause."
002100 ACCEPT CHAR-STRING FREE
002150 CALL INTRINSIC ".LEN." USING CHAR-STRING GIVING STRING-LEN
002200 CALL INTRINSIC "HPEXTIN" USING CHAR-STRING STRING-LEN
002300 0 1 0 0 REAL-SECONDS ERROR-CODE
002400 IF ERROR-CODE <> 0
002500 PERFORM HPEXTIN-ERROR
002600 ELSE
002700 CALL INTRINSIC "PAUSE" USING REAL-SECONDS
002800 END-IF
002900 STOP RUN.
003000
003100 HPEXTIN-ERROR.
003200 DISPLAY "HPEXTIN ERROR = " ERROR-CODE.
[REV END]
MPE/iX 5.0 Documentation