OO-Cobol. Moving between MVS and UNIX From MVS, use a TSO command to start a UNIX shell: TSO OMVS Or...

29
OO-Cobol

Transcript of OO-Cobol. Moving between MVS and UNIX From MVS, use a TSO command to start a UNIX shell: TSO OMVS Or...

Page 1: 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.

OO-Cobol

Page 2: 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.

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

Page 3: 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.

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 command-line editing

• You cannot use OEDIT to edit a file

Page 4: 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.

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

Page 5: 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.

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

Page 6: 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.

Defining a Cobol Class

IDENTIFICATION DIVISION.…ENVIRONMENT DIVISION.…FACTORY. (optional)…OBJECT. (optional)…END CLASS

Page 7: 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.

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

Page 8: 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.

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

Page 9: 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.

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 DivisionWorking-Storage section.01 AccountNumber pic 9(6).01 AccountBalance pic s9(9) value zero.

…End Object.

Page 10: 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.

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.

Page 11: 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.

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.

Page 12: 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.

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

Page 13: 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.

Method – Identification Division

Identification Division.

Method-id. “credit”.

Page 14: 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.

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

Page 15: 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.

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

Page 16: 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.

Linkage Section

• This works like any linkage section to provide addressability to data outside the method

Page 17: 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.

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

Page 18: 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.

Defining a MethodProcedure 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.

Page 19: 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.

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

Page 20: 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.

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

Page 21: 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.

Client Data DivisionData 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.

Page 22: 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.

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

Page 23: 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.

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 JNIEnvPtrSet address of JNINativeInterface to JNIEnvCall IsSameObject Using by value JNIEnvPtr

object1 object2 returning is-same If is-same-true …

Page 24: 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.

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

Page 25: 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.

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.

Page 26: 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.

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.

Page 27: 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.

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

Page 28: 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.

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

Page 29: 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.

Java Client

• To Compile:

javac Actrunr.java• To execute:

java Actrunr