Skip to main content

This article describes how to use floating-point data item as parameters.

Problem:

I would like to use floating-point data item as a parameter between Micro Focus module and Language C module or Java module. How is this done?

Resolution:

This is an example :

**** Makefile *******

.SUFFIXES: .so .cbl .gnt

all : prog.gnt

ccomp.so : ccomp.c

cob -z -o ccomp.so ccomp.c

prog.gnt : prog.cbl prog1.gnt ccomp.so

cob -u prog.cbl -U

prog1.gnt : prog1.cbl javacalled.class

cob -u prog1.cbl -U

javacalled.class: javacalled.java

javac javacalled.java

clean :

rm -f ccomp.o ccomp.so javacalled.class prog1.idy prog1.int

rm -f prog.gnt prog.idy prog.int prog.o prog1.gnt

**** prog.cbl ************

123456$SET INTLEVEL(4)

01 ZONE1 COMP-1.

01 ZONE2 COMP-2.

01 ZONE1-DISPLAY PIC S9(12)V9(12).

01 ZONE2-DISPLAY PIC S9(12)V9(12).

PROCEDURE DIVISION.

MOVE -12345.678 TO ZONE1.

MOVE -12345678.9012 TO ZONE2.

MOVE ZONE1 TO ZONE1-DISPLAY.

MOVE ZONE2 TO ZONE2-DISPLAY.

DISPLAY "Before C"

DISPLAY ZONE1-DISPLAY.

DISPLAY ZONE2-DISPLAY.

CALL "ccomp" using ZONE1 ZONE2.

MOVE ZONE1 TO ZONE1-DISPLAY.

MOVE ZONE2 TO ZONE2-DISPLAY.

DISPLAY "After C"

DISPLAY ZONE1-DISPLAY.

DISPLAY ZONE2-DISPLAY.

call "prog1".

******** prog1;cbl **********

123456$set ooctrl( p-f) reentrant(2) INTLEVEL(4)

program-id. cobolcaller.

class-control.

clajavacalled is class "$java$javacalled".

working-storage section.

01 ZONE1 COMP-1.

01 ZONE2 COMP-2.

01 ZONE1-DISPLAY PIC S9(12)V9(12).

01 ZONE2-DISPLAY PIC S9(12)V9(12).

01 Hjavacalled object reference.

PROCEDURE DIVISION.

MOVE -12345.678 TO ZONE1.

MOVE -12345678.9012 TO ZONE2.

MOVE ZONE1 TO ZONE1-DISPLAY.

MOVE ZONE2 TO ZONE2-DISPLAY.

display "Before Java".

DISPLAY ZONE1-DISPLAY.

DISPLAY ZONE2-DISPLAY.

invoke clajavacalled "new" returning hjavacalled.

invoke hjavacalled "ecriture" using zone1 zone2.

invoke hjavacalled "lectureFloat" returning zone1 .

invoke hjavacalled "lectureDouble" returning zone2.

MOVE ZONE1 TO ZONE1-DISPLAY.

MOVE ZONE2 TO ZONE2-DISPLAY.

display "After Java".

DISPLAY ZONE1-DISPLAY.

DISPLAY ZONE2-DISPLAY.

exit program.

**** javacalled.java************

public class javacalled {

float c;

double d;

public javacalled() {

}

public void ecriture(float a , double b ) {

System.out.println("Java Float =" a);

System.out.println("Java Double =" b);

c = a;

d = b ;

}

public float lectureFloat() {

float e;

e = c * 2 ;

return e ;

}

public double lectureDouble() {

double e;

e = d * ( - 3 );

return e ;

}

}

***** ccomp.c *******

ccomp(float *f1, double *f2)

{

*f1 = *f1 * 2;

*f2 = *f2 * ( 5 - 8 );

}

********************

To execute

cobjrun prog

Note: Don't forget to write the current directory into $CLASSPATH

Old KB# 14892