HP COBOL II/iX [ HP FORTRAN 77/iX Programmer's Guide ] MPE/iX 5.0 Documentation
HP FORTRAN 77/iX Programmer's Guide
HP COBOL II/iX
The data types of HP FORTRAN 77/iX and HP COBOL II/iX differ. Numeric HP
COBOL II/iX data types are binary packed-decimal or in ASCII format (see
Table 8-2 ). However, by taking the size and the format into
consideration, you can successfully match HP FORTRAN 77/iX and HP COBOL
II/iX types.
Table 8-2. HP COBOL II/iX Numeric Types and Formats
-------------------------------------------------------------------------
| | |
| HP COBOL II/iX | Description of the Format |
| Type | |
| | |
-------------------------------------------------------------------------
| | |
| COMP-3 | Packed decimal format with the sign in the |
| | rightmost half-byte and 2 digits per byte. |
| | |
-------------------------------------------------------------------------
| | |
| COMP | Binary format; the sign bit 0 is for positive, 1 |
| | for negative. |
| | |
| | The size S9 to S9(4) is 2 bytes. |
| | The size S9(5) to S9(9) is 4 bytes. |
| | The size S9(10) to S9(18) is 8 bytes. |
| | |
-------------------------------------------------------------------------
| | |
| DISPLAY | Unpacked decimal format (ASCII). |
| | |
| | Unsigned: |
| | alphanumeric format; |
| | no leading or trailing sign; |
| | 1 character per byte. |
| | |
| | Sign is leading: |
| | alphanumeric format; |
| | sign overpunched in leftmost byte. |
| | |
| | Sign is trailing: |
| | alphanumeric format; |
| | sign overpunched in rightmost byte. |
| | |
| | Sign is leading and is separate: |
| | first byte is ASCII '-' for negative and '+' for |
| | positive. |
| | |
| | Sign is trailing and is separate: |
| | last byte is ASCII '-' for negative and '+' for |
| | positive. |
| | |
-------------------------------------------------------------------------
Table 8-3 shows examples of possible matches between HP COBOL II/iX
and HP FORTRAN 77/iX types.
Table 8-3. HP COBOL II/iX and HP FORTRAN 77/iX Data Types
---------------------------------------------------------------------------
| | |
| HP COBOL II/iX Type | HP FORTRAN 77/iX Type |
| | |
---------------------------------------------------------------------------
| | |
| PIC X(N) | CHARACTER*n |
| | |
---------------------------------------------------------------------------
| | |
| PIC S9(01)-S9(04) COMP | INTEGER*2 {-9999..9999} |
| | |
---------------------------------------------------------------------------
| | |
| PIC S9(05)-S9(09) COMP | INTEGER*4 {999,999,999..999,999,999} |
| | |
---------------------------------------------------------------------------
| | |
| PIC S9(10)-S9(18) COMP | INTEGER*4 varname(2) |
| | |
---------------------------------------------------------------------------
The HP COBOL II/iX types 01 and 77 always start on word boundaries.
Calling HP COBOL II/iX from HP FORTRAN 77/iX
HP COBOL II/iX expects parameters to be passed by reference. When
passing character data to an HP COBOL II/iX routine, the ALIAS compiler
directive must indicate that the routine language is HP COBOL II/iX, so
only the string address is passed and not the additional length. For
example,
HP FORTRAN 77/iX program that calls an HP COBOL II/iX subprogram:
$ALIAS cobsubr COBOL
PROGRAM fortran_cobol
IMPLICIT NONE
INTEGER*4 int1,int2,int3
C By default, all parameters are passed by reference.
int1 = 25000
int2 = 30000
CALL cobprog(int1,int2,int3)
PRINT *,int3
END
HP COBOL II/iX subprogram:
$CONTROL SUBPROGRAM
IDENTIFICATION DIVISION.
PROGRAM-ID. COBPROG.
AUTHOR. LD.
ENVIRONMENT DIVISION.
CONFIGURATION SECTION.
SOURCE-COMPUTER. HP3000.
OBJECT-COMPUTER. HP3000.
DATA DIVISION.
LINKAGE SECTION.
77 IN1 PIC S9(09) COMP.
77 IN2 PIC S9(09) COMP.
77 OUT PIC S9(09) COMP.
PROCEDURE DIVISION USING IN1, IN2, OUT.
PARA-1.
ADD IN1, IN2, GIVING OUT.
GOBACK.
Calling HP FORTRAN 77/iX from HP COBOL II/iX
The GIVING phrase must be used when calling an HP FORTRAN 77/iX function
from HP COBOL II/iX.
Example 1
HP COBOL II/iX program that calls an HP FORTRAN 77/iX function:
001000 IDENTIFICATION DIVISION.
002000 PROGRAM-ID. CALLFTN.
003000 DATA DIVISION.
004000 WORKING-STORAGE SECTION.
005000 01 TABLE-INIT.
006000 05 PIC S9(9) COMP SYNC VALUE 10.
007000 05 PIC S9(9) COMP SYNC VALUE 8.
008000 05 PIC S9(9) COMP SYNC VALUE 14.
009000 05 PIC S9(9) COMP SYNC VALUE 9.
010000 05 PIC S9(9) COMP SYNC VALUE 18.
011000 05 PIC S9(9) COMP SYNC VALUE 98.
012000 05 PIC S9(9) COMP SYNC VALUE 7.
013000 05 PIC S9(9) COMP SYNC VALUE 23.
014000 01 TABLE-1 REDEFINES TABLE-INIT.
015000 05 TABLE-EL OCCURS 8
016000 PIC S9(9) COMP SYNC.
017000
018000 01 LARGEST-VALUE PIC S9(9) COMP SYNC.
019000
020000 01 STRING-1 PIC X(10) VALUE "ABCDEFGHIJ".
021000 01 LEN PIC S9(9) COMP SYNC.
022000
023000 PROCEDURE DIVISION.
024000 P1.
025000****************************************************************
026000* Call FORTRAN subroutine "LARGER" to find the largest element *
027000* in a table on "LEN" elements. *
028000****************************************************************
029000
030000 MOVE 8 TO LEN.
031000 CALL "LARGER" USING TABLE-1, LEN GIVING LARGEST-VALUE.
032000 DISPLAY LARGEST-VALUE " IS THE LARGEST VALUE IN THE TABLE".
033000
034000****************************************************************
035000* Call FORTRAN subroutine "BACKWARDS" to reverse a string of *
036000* 10 characters. *
037000* Shows passing character strings to FORTRAN subroutine *
038000****************************************************************
039000
040000 MOVE 1 TO LEN.
041000 DISPLAY STRING-1 " BACKWARDS IS " WITH NO ADVANCING
042000 CALL "BACKWRDS" USING STRING-1 \LEN\.
043000 DISPLAY STRING-1.
HP FORTRAN 77/iX function:
INTEGER*4 FUNCTION LARGER(A,L)
INTEGER*4 A(8)
INTEGER*4 LARGST,L
C
C THIS SUBROUTINE FINDS THE LARGEST VALUE IN AN ARRAY
C OF 'L' INTEGERS.
C
LARGST = A(1)
DO 100 I = 2,L
IF (LARGST .GT. A(I)) GO TO 100
LARGST = A(I)
100 CONTINUE
LARGER = LARGST
RETURN
END
C ******************************************************
C * SUBROUTINE BACKWRDS *
C * THIS SUBROUTINE REVERSES AN ARRAY OF 'L' CHARACTERS*
C ******************************************************
SUBROUTINE BACKWRDS(STR)
CHARACTER STR(10)
CHARACTER N
J = 10
DO 100 K = 1,5
N = STR(K)
STR(K) = STR(J)
STR(J) = N
J = J - 1
100 CONTINUE
RETURN
END
Example 2
HP COBOL II/iX program that calls an HP FORTRAN 77/iX function:
IDENTIFICATION DIVISION.
PROGRAM-ID. CALLFTN2.
DATA DIVISION.
WORKING-STORAGE SECTION.
01 INT-1 PIC S9(4) COMP SYNC VALUE 13.
01 INT-2 PIC S9(4) COMP SYNC.
01 STRING-1 PIC X(10) VALUE "0123456789".
PROCEDURE DIVISION.
P1.
CALL "FUNC1" USING INT-1,@STRING-1 GIVING INT-2.
DISPLAY STRING-1.
DISPLAY INT-2.
HP FORTRAN 77/iX function:
$FTN3000_66 CHARS ON
INTEGER*2 FUNCTION func1(i,string)
CHARACTER string*10
INTEGER*2 i
WRITE(6,*) i, string
string = 'This is it'
func1 = i
END
MPE/iX 5.0 Documentation