Page 3
Fujitsu NetCOBOL Language Reference Refer to the information on how to develop programs using Fujitsu NetCOBOL, refer to the NetCOBOL User's Guide Intended Readers This manual is intended for persons who develop COBOL programs using Java classes.
How to Use This Manual When using the J adapter class generator for the first time, begin to read from Chapter 1. Chapter 1 provides an outline of the J adapter class generator, Chapter 2 explains the framework, and Chapter 3 explains the procedures from development to execution.
Microsoft, Windows, and Windows NT are registered trademarks of Microsoft Corporation in the U.S. and other countries. Java and other trademarks including Java are trademarks of Sun Microsystems, Inc. in the U.S. and other countries. J Adapter Class Generator User's Guide...
Page 6
NetCOBOL J Adapter Class Generator User's Guide...
Contents Chapter 1. Outline of J Adapter Class Generator ...9 What is the J Adapter Class Generator? ...10 What the J Adapter Class Generator Can Do ...11 What the J Adapter Class Generator Cannot Do ...11 Preparation ...12 Chapter 2. Adapter Class Generator Framework ...13 Adapter Class...14...
Page 8
Sample 1 – Using Classes...81 Sample 2 – Specifying Method...83 Appendix A. Message List...85 Java2cob Command Messages...86 Messages Output during Generation...87 Messages Output during Execution ...90 Appendix B. Exception Type List ...93 Index ...97 NetCOBOL J Adapter Class Generator User's Guide...
However, the class structure varies from language to language and therefore Java class libraries cannot normally be used from COBOL. The J adapter class generator provides a framework that enables COBOL to use Java classes. The J adapter class generator enables a COBOL program to: •...
The Java class interface must be converted into the COBOL interface for a COBOL program to use Java classes. The J adapter class generator generates an adapter class that converts the Java interface into the COBOL interface. What the J Adapter Class Generator Can Do Using adapter classes generated by the J adapter class generator enables the following types of operation for Java.
JDK 1.1.8, J2SDK 1.2.2, or a later version is required to develop programs using the J adapter class generator. JDK 1.1.8, J2SDK 1.2.2, JRE 1.1.8, J2RE 1.2.2, or a later version is required to run applications developed using the J adapter class generator.
Adapter Class To make Java classes available to COBOL, a mechanism for converting the Java class interface into the COBOL interface is required. The J adapter class generator works as an interface converting mechanism to generate adapter classes corresponding to Java classes.
Adapter Object At execution time, an adapter class generates the adapter object corresponding to a Java instance object. The adapter object: • Holds the pointer to the corresponding Java instance object. • Calls the corresponding Java method of the corresponding Java instance object Only the adapter object can be seen from the COBOL program.
Page 16
Chapter 2. Adapter Class Generator Framework...
J adapter class What the J Adapter Class generator can handle the class and interface. See " Generator Can Do What the J Adapter Class Generator Cannot Do " and " " for information on which classes and interfaces can be used.
Page 19
Finally, compile and link-edit the generated adapter class source to create an adapter class library (DLL). Use the COBOL project manager to do so. Refer to the Fujitsu NetCOBOL User's Guide for information on how to use the COBOL project manager Follow the procedure below to build an adapter class: 1.
Page 20
Generation was interrupted Reducing the Size of Adapter Class The adapter class source generated by the J adapter class generator may be simply compiled and linked before it is used. Since, however, the adapter source class can include class files, which are not used by the applications, there might be cases where the size of the DLL file of the adapter class is significantly larger than necessary.
Page 21
Specifying the -om option or the "Option ReduceClass" parameter can reduce the number of adapter classes generated. To check for parameter validity at method invocation, the J adapter class generator generates adapter classes corresponding to individual parameters. Thus many adapter classes are generated for one class.
REPOSITORY. CLASS J-OBJECT AS "java-lang-Object" LINKAGE SECTION. 01 P1-OUTPUTSTREAM OBJECT REFERENCE J-OBJECT. Developing an Application That Uses an Adapter Class This section explains how to develop a program that uses an adapter class. Outline The flow of program processing using the adapter class is as follows: 1.
Page 23
Terminating the Java VM When an adapter class is no longer used, the Java VM must be terminated. Use the JVM-TERMINATE method of the FJ-JAVA-CONTROL class to terminate the Java VM. A coding sample is shown below: REPOSITORY. CLASS FJ-JAVA-CONTROL PROCEDURE DIVISION.
Page 24
An example of generating a Date class object is shown below: REPOSITORY. CLASS J-Date AS "java-util-Date" WORKING-STORAGE SECTION anDate OBJECT REFERENCE J-Date. PROCEDURE DIVISION. INVOKE J-Date "Create-Date-01" RETURNING anDate. Note: • Since the adapter class name is very long, it is recommended that an alias be assigned by specifying AS in the REPOSITORY paragraph.
Page 25
An example of referencing the class variable AM_PM_FIELD (static field) of the DateFormat class is shown below: REPOSITORY. CLASS J-DateFormat AS "java-text-DateFormat" WORKING-STORAGE SECTION FMT-Type PIC S9(9) COMP-5. PROCEDURE DIVISION. MOVE JF-AM_PM_FIELD OF J-DateFormat TO FMT-Type. Comparing Object References COBOL uses "=" to check whether multiple object references point to the same object.
Page 26
An example of assigning an object, which has been referenced with Object class data, into Data class data is shown below: REPOSITORY. CLASS J-Object AS "java-lang-Object" CLASS J-Date AS "java-util-Date" WORKING-STORAGE SECTION anDate OBJECT REFERENCE J-Date. anObject OBJECT REFERENCE J-Object. PROCEDURE DIVISION.
Page 27
… When the -s option or the "Option String" parameter is specified, the conversion between the String object and the COBOL data items is not necessary since an alphanumeric item can be specified as the String type argument and returns a value directly.
Java exception information can be extracted. For the details of the exception handling using the USE statement, refer to "Defining Exception Processes" of the "Fujitsu NetCOBOL User's Guide". Example of coding of the exception handling is shown as follows: …...
F3BIJART.LIB in it. F3BIJART.LIB exists in the LIB folder of the install folder. 5. Specify compiler and link options: For REPIN, specify XXX\REP (XXX is the J adapter class generator install folder) and the folder containing the adapter class repository. Specify ALPHAL (WORD) or NOALPHAL.
Conversion to Java2 When using the resources (execute-form programs (EXE), DLLs, adapter class source, and program source using adapter classes) created by JDK1.1.x, note the following: • Adapter class source and DLLs created by JDK 1.1.x can be used as they are in the Java2 environment.
Starting the J Adapter Class Generator Command Syntax When the constructor/method/field is not specified: java2cob [-classpath class-name/interface-name ]] [-t] When the constructor/method/field is specified: java2cob [-classpath class-name/interface-name t] –r [,...]"]] [-gm [" method-name When the optional file is specified: optional-file...
Page 33
Chapter 4. Using the Generator Command generated. When specifying two or more constructors, they must be delimited by comma (,) or a blank. When two or more constructors of the same name exist, only the constructor that matches the parameter type is generated by specifying the parameter-type. If a parameter type is omitted, all of the constructors of the same name are generated.
Page 34
Chapter 4. Using the Generator Command Specified to reduce the number of adapter classes generated. When this parameter is specified, the object reference types of all parameters excluding RETURNING become java-lang-Object. Instead, the parameter names are generated so that they include original type information (see "Specifying the -om option or the "Option ReduceClass"...
Page 35
name, replace the period "." of the internal class name with a dollar sign "$". More than one class name or interface name can be specified. Environment Variable CLASSPATH Specifies the Java class/interface search path. When -classpath is specified, the CLASSPATH environment variable is ignored.
Optional File The optional file is a text format file used to define generator options in a file instead of on the command line. The optional file is specified in a command line of the java2cob command. For example, specifying the many method names, etc. in the command line every time is troublesome during the specification of the constructor/method/field.
Page 37
Notes on describing the optional file: • Clauses enclosed by square brackets can be omitted. • Curly brackets indicate selection of clause that is delimited by ”| ”. • Italic type indicates a variable character string. Class class-name/interface-name Specification format class-name/interface-name Class option...
Option Code Specification format Option Code = { SJIS | UNICODE } Specification contents Specify a code system during execution time. Specify the same code system as that of the COBOL program that uses the Java class. When omitted, it is assumed that SJIS is specified. Meaning of the parameter •...
Page 39
Option MethodTable Specification format Option MethodTable { YES | NO } Specification contents Specify whether or not to output the method name cross-reference list file (list of adapter class methods that correspond to the Java class methods). If omitted, it is assumed that NO is specified.
Page 40
Option ReduceClass Specification format Option ReduceClass = { YES | NO } Specification contents Specify whether or not to reduce the number of adapter classes. When YES is specified, the type of object reference except RETURNING becomes java-lang-Object, and the parameter name is generated so as to include the original type information instead.
Page 41
Option Terminal Specification format Option Terminal = { YES | NO } Specification contents Specify whether or not to generate an adapter class allowed to set end character strings, for the method that has string-type fields and string-type parameters. (Refer to "End control of character string.") If omitted, it is assumed that NO is specified.
Output The generator outputs the following files: • Adapter class source file • Generation name management file • Method name cross-reference list file Adapter Class Source File The adapter class source file corresponding to the specified Java class or interface is generated.
Page 43
Figure 4.1 Generation Name Management File The J adapter class generator uses a generation name management file to manage the correspondence between the names used in Java classes and adapter classes. The generation name management file is generated with the following name in the adapter class output folder: java2cob.mgt...
Page 44
A method name cross-reference list file is output in the following format: [Java] java-class-name [COBOL] cobol-external-class-name (1) [Java] type java-method-name (argument-type) [COBOL] cobol-external-method-name (2) [Java] type java-method-name (argument-type) OVERRIDE [COBOL] -None- (n) [Java] type java-method-name () [COBOL] cobol-external-method-name java-class-name Class name or interface name qualified by a package name cobol-external-class-name External class name of the adapter class corresponding to the Java class...
Chapter 5. Adapter Class Reference This chapter provides detailed information on the FJ-JAVA-BASE, FJ-JAVA-CONTROL and FJ-JAVA-ERROR classes provided by the J adapter class generator, and adapter classes generated by the J adapter class generator.
Class Configuration The figure below shows the hierarchical relationships among the FJ-JAVA-BASE, FJ- JAVA-CONTROL and FJ-JAVA-ERROR classes provided by the J adapter class generator, and adapter classes generated by the J adapter class generator. Class Hierarchy • FJ-JAVA-BASE: Super class of every adapter class •...
FJ-JAVA-BASE class The FJ-JAVA-BASE class is the super class of every adapter class. The FJ-JAVA-BASE class has the methods shown below. Method name Type J-NARROW Factory J-DUPLICATE Object J-EQUALS Object J-NARROW Method (factory method) Explanation This method assigns an adapter object to a subclass. Syntax class-name J-NARROW...
Java VM Same as JVM-INIT Terminates the Java VM (Only at the last calling). Disconnects the current thread from the Java VM Disconnects the current thread from the Java VM Fujitsu NetCOBOL User's Guide for information...
Page 49
Environment variable name Function COBJNI_MAX_NSTACK Specifies the maximum size (bytes) of the stack used for the native code. The default is 128 kilobytes. COBJNI_JAVA_STACK Specifies the maximum size (bytes) of the stack used for the Java code. The default is 400 kilobytes. COBJNI_MIN_HEAP Specifies the startup size of the memory allocation pool in bytes.
The exception message, exception type and exception information of Java can be acquired by using the FJ-JAVA-ERROR class method. Refer to "Fujitsu NetCOBOL User's Guide" for details of the exception processing. The FJ-JAVA-ERROR class has the following methods. Methods that Acquire Exception Information...
GET-EXCEPTION method (object method) Explanation The Java exception information is returned. Syntax INVOKE EXCEPTION-OBJECT "GET-EXCEPTION" USING class classLength RETURNING Parameter and return value • message (attribute: PIC X ANY LENGTH) Specifies the data item that stores the Java exception message. •...
Data types The Java data types are mapped to the COBOL data types as shown below: Java data COBOL data type type boolean PIC 1 byte PIC X char PIC X(2) • When an ANK character is stored, the first byte is used and the second byte is X'00'.
Page 53
END CLASS internal-class-name-1. Generation rules 1. Internal class names 1 and 2 are internally used by the J adapter class generator and are not viewed from the class user. 2. The external class name is used to identify the class. The class user can identify the class with the external class name.
Page 54
Note: Fujitsu NetCOBOL does not distinguish between uppercase and lowercase letters of a class name. Therefore, class names whose external class names are different only in uppercase and lowercase letters cannot be used concurrently. Supplement When the adapter class of java.lang.String is generated, the public method defined in the java.lang.String class is generated.
Page 55
6. When an exception is declared for the constructor, the RAISING specification is generated. Generation example The factory method corresponding to constructor Date() of the java.util.Date class is generated as shown below: METHOD-ID. CREATE-01 AS "Create-Date-01". LINKAGE SECTION. CREATED-OBJECT OBJECT REFERENCE SELF. PROCEDURE DIVISION RETURNING CREATED-OBJECT.
Page 56
Class variable Explanation A public class variable (static field) is mapped to a COBOL property method (factory). Expansion format METHOD-ID. GET PROPERTY property-name. LINKAGE SECTION. 01 property-value data-description-entry. PROCEDURE DIVISION RETURNING property-value. END METHOD property-name. METHOD-ID. SET PROPERTY property-name. LINKAGE SECTION. 01 property-value data-description-entry PROCEDURE DIVISION USING property-value.
Page 57
END METHOD internal-method-name. Generation rules 1. The internal method name is internally used by the J adapter class generator and cannot be viewed from the class user. 2. The external method name is used to identify the method. The class user identifies the method with the external method name.
Page 58
Generation example The factory method corresponding to class method abs (long) of the java.lang.Math class is generated as shown below: METHOD-ID. JM-ABS-01 AS "abs-01". LINKAGE SECTION. RTN-VALUE PIC S9(18) COMP-5. PARA-1 PIC S9(18) COMP-5. PROCEDURE DIVISION USING PARA-1 RETURNING RTN-VALUE. END METHOD JM-ABS-01.
Page 59
If a same property name has already been assigned, the second and subsequent property names are each suffixed with a hyphen "-" followed by a two-digit number (01 to 99) to prevent name duplication. (See Numbering names. " ") A name exceeding 30 characters is truncated after the 30th character. 3.
Page 60
END METHOD internal-method-name. Generation rules 1. The internal method name is internally used by the J adapter class generator and cannot be viewed from the class user. 2. The external method name is used to identify the method. The class user identifies the method with the external method name.
Generation example The object method corresponding to instance method getTime() of the java.util.Date class is generated as shown below: METHOD-ID. JM-GETTIME AS "getTime". LINKAGE SECTION. RTN-VALUE PIC S9(18) COMP-5. PROCEDURE DIVISION RETURNING RTN-VALUE. END METHOD JM-GETTIME. 1. Since there is only one method with name "getTime," a method with name "getTime"...
Page 62
Parameter and return value • class-name Specifies the internal class name of the java-lang-String class declared in the REPOSITORY paragraph. • initialValue (attribute: PIC X ANY LENGTH) Specifies an alphanumeric data item as the initial value of the String object. •...
Page 63
• createdObject (attribute: OBJECT REFERENCE SELF) Returns the generated object. Supplement When a data name is specified for initialValue, a String object as long as data item length is generated. However, inserting X”0000” in the statement can generate a String object shorter than data item length. REPOSITORY.
Page 64
GET-STRING-N method (object method) Explanation This method fetches the character string from the String object as a national data item. Syntax anObject INVOKE "GET-STRING-N" RETURNING Parameter and return value • anObject Specifies the String object from which a character string is to be fetched. •...
GET-STRING-LENGTH-N method (object method) Explanation This method returns the length of the character string of the String object as the length (number of characters) of the national data item. Syntax anObject INVOKE "GET-STRING-LENGTH-N" RETURNING Parameter and return value • anObject Specifies the String object whose character length is to be checked.
Page 66
END CLASS internal-class-name-1. Generation rules 1. Internal class names 1 and 2 are internally used by the J adapter class generator and are not viewed from the class user. 2. The external class name is used to identify the class. The class user can identify the class with the external class name.
Page 67
CLASS-ID. JA-1-STRING AS "JA-1-java-lang-String" INHERITS J-OBJECT. END CLASS JA-1-STRING. Adapter classes of int [] [] [] are generated as shown below: CLASS-ID. JA-3-INT AS "JA-3-int" INHERITS J-OBJECT. END CLASS JA-3-INT. CLASS-ID. JA-2-INT AS "JA-2-int" INHERITS J-OBJECT. END CLASS JA-2-INT. CLASS-ID. JA-1-INT AS "JA-1-int" INHERITS J-OBJECT. END CLASS JA-1-INT.
Page 68
REPOSITORY. CLASS JA-2-INT AS "JA-2-int" CLASS JA-1-INT AS "JA-1-int" anArray OBJECT REFERENCE JA-2-INT. wArray OBJECT REFERENCE JA-1-INT. INVOKE JA-2-INT "NEW-ARRAY" USING n RETURNING anArray. PERFORM VARYING I FROM 0 BY 1 UNTIL I >= n INVOKE JA-1-INT "NEW-ARRAY" USING m RETURNING wArray INVOKE anArray "SET-ARRAY-ELEMENT"...
This section explains the rules of assigning numbers to names used for adapter classes. Effective range of name The names handled by the J adapter class generator are classified into the following three types depending on the effective range of a name: •...
Page 70
• Two or more constructors are defined for one class. In this case, the J adapter class generator assigns numbers to the methods with a same name according to the following rules: 1. Number 01 is assigned to the name that appears first and then serial numbers are assigned in ascending order to the subsequent names.
Page 71
For the adapter class corresponding to these interface and classes, methods of the same name must be generated for the read methods having the same parameters. The J adapter class generator uses the generation name management file to manage the correspondence of method names across classes or interfaces. It then assigns numbers to methods with the same name according to the following rules: 1.
Page 72
java.io.ObjectInput read() interface read(byte[]) read(byte[], int, int) java.io.InputStream read() class read(byte[]) read(byte[], int, int) java.io.ObjectInputStrea read() m class read(byte[], int, int) Note: The way of assigning numbers may be different depending on the order adapter classes are generated. Use the same generation name management file to generate adapter classes to be used under the same environment.
Java2cob class loading failed. Reinstall the J adapter class generator and retry. The J adapter class generator is not installed normally. Reinstall the J adapter class generator. Messages Output during Generation This section explains the messages output during adapter class generation, including the operator responses to the messages.
Page 75
Error: An invalid class name "xxx" was specified. Specify a Java class name or interface name qualified by a package name. Specify a valid class name or interface name and retry. Error: A valid directory name was missing. The option was ignored to continue processing.<<Same as above>>...
Page 76
(see " available "). Error: A memory space shortage occurred. Generation was interrupted. Terminate unnecessary applications and retry. Error: A system error occurred. Generation was interrupted. The J adapter class generator failed. Collect failure information and call your Fujitsu systems engineer.
Messages Output during Execution This section explains the messages output during execution of programs using adapter classes, including the operator responses to the messages. The message format is shown below: Class name information: Class name information indicates the adapter class in which an error occurred. The format of class name information varies depending on the class type.
Page 78
The current thread could not be disconnected from Java VM. Check whether the program properly invokes the JVM-DETACH method. The adapter class generated by the J adapter class generator contains a Java class name in invalid format. Contact the J adapter class generator supplier.
Page 79
Check the Java class/interface. Java class initialization failed. Call the J adapter class generator supplier. The J adapter class generator failed. Collect failure information and call your Fujitsu systems engineer. No Java method is found. Check whether the Java class/interface was changed after execution of the J adapter class generator.
Chapter 7. Samples Sample 1 – Using Classes Example 1: Example of using java.lang.System, java.io.PrintStream, and java.util.Date classes This section explains the “Sample Program - Example 1 ” provided with this product. Example 1 shows how the java.lang.System, java.io.PrintStream, and java.util.Date classes of Java are used from COBOL.
Page 82
Project build or rebuild function This section explains how to create an executable program using the build function of the project manager. Refer to the “Fujitsu COBOL User’s Guide” for detailed information on how to use the project manager. 1. When using Java(JDK 1.1.x), open project file “DATE01JAVA.PRJ”. When using Java2(J2SDK 1.2.2 or later), open project file “DATE01JAVA2.PRJ”.
Chapter 7. Samples Sample 2 – Specifying Method Example 2: Example of generating an adapter class by specifying constructor/method/field This program description explains “Sample Program - Example 2” provided with this product. Example 2 shows how to generate the adapter class specifying constructor/method/field.
Page 84
Project build or rebuild function This section explains how to create an executable program using the build function of the project manager. Refer to the “Fujitsu COBOL User’s Guide” for detailed information on how to use the project manager. 1. When using Java(JDK 1.1.x), open project file “DATE02JAVA.PRJ”. When using Java2(J2SDK 1.2.2 or later), open project file “DATE02JAVA2.PRJ”.
Java2cob class loading failed. Reinstall the J adapter class generator and retry. The J adapter class generator is not installed normally. Reinstall the J adapter class generator. Failed to open the optional file. Check the file status. Generation was interrupted.
Messages Output during Generation This section explains the messages output during adapter class generation, including the operator responses to the messages. The message format is shown below: Message type: Message text The message types are shown below: Message type Level Error Severe Warning...
Page 88
Error: The suffix number exceeded 99. Generation was interrupted. Retry while specifying –r option, -gc option, -gm option, -gf option, -om option, constructor/method/field-specifying-option parameter, or “Option ReduceClass” parameter to decrease the number of classes, fields (variables), or methods. Error: The status of file "xxx" is invalid for generation. Check the file status.
Page 89
(see "Generating an adapter class when the class file is not available"). Error: A memory space shortage occurred. Generation was interrupted. Terminate unnecessary applications and retry. Error: A system error occurred. Generation was interrupted. The J adapter class generator failed. Collect failure information and call your Fujitsu systems engineer.
Messages given while execution is underway are output to the same target output as that of the DISPLAY statement that is specified by UPON SYSERR of COBOL. Refer to "Fujitsu COBOL User's Guide" for the target output of the DISPLAY statement that is specified by UPON SYSERR of COBOL.
Page 91
The adapter class generated by the J adapter class generator contains a Java class name in invalid format. Contact the J adapter class generator supplier. The J adapter class generator failed. Collect failure information and call your Fujitsu systems engineer.
Page 92
The character string could not be fetched from the String object. Call the J adapter class generator supplier. The J adapter class generator failed. Collect failure information and call your Fujitsu systems engineer. The subscript of the array object is invalid. Specify a subscript within the array range.
Meaning Java class initialization failed. Call the J adapter class generator supplier. Response The J adapter class generator failed. Collect failure information and call your Fujitsu systems engineer. Meaning A memory space shortage occurred. Increase the values of environment variables (COBJNI_MAX_NSTACK, COBJNI_JAVA_STACK, COBJNI_MIN_HEAP, and COBJNI_MAX_HEAP), then retry.
Page 94
The subscript value is outside the range from "0 to (element count - 1)." Specify a valid subscript. Meaning The adapter class generated by the J adapter class generator contains a Java class name in invalid format. Contact the J adapter class generator supplier. Response The J adapter class generator failed.
Page 95
The character string could not be fetched from the String object. Call the J adapter class generator supplier. Response The J adapter class generator failed. Collect failure information and call your Fujitsu systems engineer. Meaning Type conversion failed. Check the parameter passed to the J-NARROW method.
Page 96
An internal logical error (inconsistency between the return value and object reference) occurred. Call the J adapter class generator supplier. Response The J adapter class generator failed. Collect failure information and call your Fujitsu systems engineer. Meaning Java VM detected an error. Remove the error cause. (exception name:...
Need help?
Do you have a question about the J Adapter Class Generator and is the answer not in the manual?
Questions and answers