Fujitsu J Adapter Class Generator Portable Generator User Manual


 
28 Chapter 3. Developing Programs
If an adapter class is generated by specifying the -t option or the "Option Terminal"
parameter, the character string that is shorter than the data item length can be
passed to a method without setting the end of string, since the end (X "00") of the
character string is set in the adapter class.
The following example shows that "ABC" is copied to alphanumeric item initialValue
having the length of 50 characters and is passed to the NEW-STRING-X method:
REPOSITORY.
CLASS J-String AS "java-lang-String"
WORKING-STORAGE SECTION.
01 initialValue PIC X(50).
01 aString OBJECT REFERENCE J-String.
PROCEDURE DIVISION.
MOVE "ABC" TO initialValue.
INVOKE J-String "NEW-STRING-X" USING initialValue RETURNING aString.
Exception Processing
When an adapter class detects an error during processing, the exception object is
generated. FJ-JAVA-ERROR class is the class of the exception object.
In order to detect an exception generated in the adapter class, using the "exception
object", the "exception handling" needs be described in the declaratives of the
procedure division of the program, using the USE statement. When the method of
the FJ-JAVA-ERROR class is used in the exception handling, the exception message,
exception type and 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:
REPOSITORY.
CLASS FJ-JAVA-ERROR
WORKING-STORAGE SECTION
01 errMessage PIC X(256).
01 expMessage PIC X(1024).
01 expClass PIC X(256).
01 errCode PIC S9(9) COMP-5.
01 errMessageLen PIC S9(9) COMP-5.
01 expMessageLen PIC S9(9) COMP-5.
01 expClassLen PIC S9(9) COMP-5.
01 rc PIC S9(9) COMP-5.
PROCEDURE DIVISION.
DECLARATIVES.
ERR SECTION.
USE AFTER EXCEPTION FJ-JAVA-ERROR.
INVOKE EXCEPTION-OBJECT "GET-CODE" RETURNING errCode.
INVOKE EXCEPTION-OBJECT "GET-MESSAGE"
USING errMessage RETURNING errMessageLen.
INVOKE EXCEPTION-OBJECT "GET-EXCEPTION"
USING expMessage expMessageLen expClass expClassLen
RETURNING rc.