Wrapping Legacy Code - Columbus State University

advertisement
OO-Cobol
Moving between MVS and UNIX
• From MVS, use a
TSO command to
start a UNIX shell:
TSO OMVS
Or
TSO ISHELL
• From UNIX, use the
exit command to
return to MVS:
exit
Logging Directly into z/OS UNIX
• You can telnet directly to z/OS UNIX from a command
prompt:
c:\> telnet 192.86.33.118
• You cannot switch to TSO. You can use the TSO SHELL
command to run a TSO command from your shell
session
• You can use the UNIX vi editor or UNIX-style commandline editing
• You cannot use OEDIT to edit a file
Basic z/OS UNIX Commands
• Use the change directory (cd) command to
move to a specific directory:
CSUP004:/u: cd /u/csu/csup004
• Use the list command (ls) to list
subdirectories and files in the current
directory:
CSUP004:/u:
ls
Basic z/OS UNIX Commands
• Use the remove (rm) command to remove
a file or subdirectory:
CSUP004:/u: rm myprog.java
• Use a shell command (oedit) to edit or
create a file:
CSUP004:/u:
oedit myprog.java
Defining a Cobol Class
IDENTIFICATION DIVISION.
…
ENVIRONMENT DIVISION.
…
FACTORY.
(optional)
…
OBJECT.
(optional)
…
END CLASS
IDENTIFICATION DIVISION
Identification Division.
Class-id. Account inherits Base.
• Names the class you are defining
• Names the immediate superclass (Java or
Cobol)
• Base is defined in the Repository
• All classes must be derived directly or indirectly
from java.lang.Object
Repository
Environment Division.
Configuration Section.
Repository.
Class Base is “java.lang.Object”
Class Account is “Account”.
• Connects the internal names to external class names
• Base is required, Account is optional
• Specify the external class name if the name contains
non-Cobol characters, or any referenced class that is
part of a Java package
Class Instance Data
•
•
Define a Data Division and a Working-Storage section
in the Object section to define instance data
The Object section is immediately preceded by an
Identification Division.
Identification Division.
Object.
Data Division
Working-Storage section.
01 AccountNumber
pic 9(6).
01 AccountBalance pic s9(9) value zero.
…
End Object.
Initializing Instance Data
• Initialize instance data by using value
clauses
• Complex instance data can be initialized
by calling customized methods
• Cobol instance data is equivalent to Java
private nonstatic member data.
cbl dll,thread,pgmname(longmixed)
Identification Division.
Class-id. Account inherits Base.
Environment Division.
Configuration section.
Repository.
Class Base is "java.lang.Object"
Class Account is "Account".
*
Identification division.
Object.
Data division.
Working-storage section.
01 AccountNumber pic 9(6).
01 AccountBalance pic S9(9) value
zero.
*
Procedure Division.
**
(Instance method definitions here)
*
End Object.
*
End class Account.
Defining Instance Methods
• Define instance methods in the Procedure
Division of the Object paragraph
• Each instance method has four divisions:
1) Identification – names the method
2) Environment – names the files the method
uses
3) Data – defines files and creates local variables
4) Procedure – defines the executable
statements that provide the service
Method – Identification Division
Identification Division.
Method-id. “credit”.
Local Storage Section
• A separate copy of Local-Storage is
allocated for each invocation of the
method, and is freed on return
• If a value clause is coded, the item is
initialized to that value on each invocation
of the method
Working Storage Section
• A single copy of Working-Storage is
allocated. Data persists in its last-used
state until the run unit ends
• The same copy of data is used whenever
the method is invoked, regardless of the
invoking object or thread
• A value clause is used to intialize a data
item on the first invocation of the method
Linkage Section
• This works like any linkage section to
provide addressability to data outside the
method
Procedure Division for Methods
• Code the executable statements for a method in the
Procedure Division
• Compile with the THREAD option
• You can code EXIT METHOD or GOBACK
• If you specify RETURNING upon invocation of the
method, the EXIT METHOD or GOBACK returns the
value of the data item to the invoking client
• There is an implicit EXIT METHOD at the end of each
Procedure Division for each method
• Coding STOP RUN kills the entire run unit
• Code End Method for each Method body
Defining a Method
Procedure Division.
*
Identification Division.
Method-id. "getBalance".
Data division.
Linkage section.
01 outBalance pic S9(9) binary.
*
Procedure Division returning outBalance.
Move AccountBalance to outBalance.
End method "getBalance".
**
(Other instance methods not shown)
End Object.
*
End class Account.
Client Programs
In a Cobol or Java client, you can:
1) Create object instances of Java and
Cobol classes.
2) Invoke instance methods on Java and
Cobol objects
3) Invoke Cobol factory methods and Java
static methods
Client Programs
Each client has four divisions:
1) Identification a) Declare program RECURSIVE in the
Program-Id paragraph.
b) Compile with the THREAD option
2) Environment – define a repository
3) Data – define local client data
4) Procedure – create classes, manipulate
objects
Client Data Division
Data Division.
Local-storage section.
01 anAccount usage object reference Account.
01 aCheckingAccount usage object
referenceCheckingAccount.
01 aCheck usage object reference Check.
01 payee usage object reference Account.
• Object reference variables are like reference variables in Java
• If the class name is omitted after “object reference”, the reference
can point to any object and have limited interoperability with Java
• You must define class-names that are used in the object reference
phrase. The definitions belong in the Repository.
Comparing Object References
• One way to compare object references is by
coding conditional statements:
If anAccount = Null …
If anAccount = Nulls …
• You can also invoke the JNI IsSameObject
service:
Set address of JNIEnv to JNIEnvPtr
Set address of JNINativeInterface to
JNIEnv
Call IsSameObject Using by value JNIEnvPtr
object1 object2 returning
Comparing Object References
• You can also invoke the JNI IsSameObject
service:
01 is-same Pic X.
88 is-same-false value x’00’.
88 is-same-true value x’01’ through x’FF’.
Linkage Section.
Copy JNI.
Procedure Division.
Set address of JNIEnv to JNIEnvPtr
Set address of JNINativeInterface to JNIEnv
Call IsSameObject Using by value JNIEnvPtr
object1 object2 returning is-same
If is-same-true …
Comparing Object References
• Within a method, calling IsSameObject
with SELF compares an object reference
to see if it refers to the same object as the
one on which the method was invoked
Setting References
• An object reference can be set to null:
Set anAccount to Null.
• An object reference can be set to another
reference:
Set anAccount to otherAccount.
• An object reference can point to the
containing object:
Set anAccount to SELF.
Invoking Methods
• Use Invoke to execute a method:
Invoke Account "createAccount"
using by value 123456
returning anAccount
Invoke anAccount "credit" using by value 500.
• The createAccount method must be a Cobol
factory method if Account is a Cobol program
• Variable anAccount must be defined:
01anAccount usage object Reference Account.
Defining a Factory
• Factory methods and data are associated with
the class (similar to Java static members)
Identification Division.
Factory.
Data Division.
Working-storage section.
…
Procedure Division.
…
End Factory
Compiling, Linking Cobol Classes
• To compile a Cobol class:
cob2 -c -qdll,thread Accounta.cbl
• To compile the Java version:
javac Accounta.java
• To link in the sidefiles and build a DLL:
cob2 -bdll -o libAccounta.so Accounta.o
/u/Java5_31/J5.0/bin/j9vm/libjvm.x
/usr/lpp/cobol/lib/igzcjava.x
Java Client
• To Compile:
javac Actrunr.java
• To execute:
java Actrunr
Download