OO Cobol in z/OS.

Slides:



Advertisements
Similar presentations
Topic 10 Java Memory Management. 1-2 Memory Allocation in Java When a program is being executed, separate areas of memory are allocated for each class.
Advertisements

Chapter 7: User-Defined Functions II Instructor: Mohammad Mojaddam.
Chapter 6 Introduction to Defining Classes
Georgia Institute of Technology Workshop for CS-AP Teachers Chapter 3 Advanced Object-Oriented Concepts.
ITEC200 – Week03 Inheritance and Class Hierarchies.
George Blank University Lecturer. CS 602 Java and the Web Object Oriented Software Development Using Java Chapter 4.
Road Map Introduction to object oriented programming. Classes
CSM-Java Programming-I Spring,2005 Class Design Lesson - 4.
1 Chapter 7: Runtime Environments. int * larger (int a, int b) { if (a > b) return &a; //wrong else return &b; //wrong } int * larger (int *a, int *b)
OOP in Java Nelson Padua-Perez Chau-Wen Tseng Department of Computer Science University of Maryland, College Park.
Classes and Instances. Introduction Classes, Objects, Methods and Instance Variables Declaring a Class with a Method and Instantiating an Object of a.
1 Chapter 2 Introductory Programs. 2 Getting started To create and run a Java program –Create a text file with a.java extension for the source code. For.
Terms and Rules Professor Evan Korth New York University (All rights reserved)
OOP in Java Fawzi Emad Chau-Wen Tseng Department of Computer Science University of Maryland, College Park.
Programming Languages and Paradigms Object-Oriented Programming.
CSM-Java Programming-I Spring,2005 Introduction to Objects and Classes Lesson - 1.
1 Inheritance and Polymorphism Chapter 9. 2 Polymorphism, Dynamic Binding and Generic Programming public class Test { public static void main(String[]
REFACTORING Lecture 4. Definition Refactoring is a process of changing the internal structure of the program, not affecting its external behavior and.
220 FINAL TEST REVIEW SESSION Omar Abdelwahab. INHERITANCE AND POLYMORPHISM Suppose you have a class FunClass with public methods show, tell, and smile.
Writing Classes (Chapter 4)
Programming in Java Unit 2. Class and variable declaration A class is best thought of as a template from which objects are created. You can create many.
Java Classes Appendix C © 2015 Pearson Education, Inc., Hoboken, NJ. All rights reserved.
An Introduction to Java Chapter 11 Object-Oriented Application Development: Part I.
Chapter 6: User-Defined Functions
Java™ How to Program, 10/e © Copyright by Pearson Education, Inc. All Rights Reserved.
An Object-Oriented Approach to Programming Logic and Design Chapter 3 Using Methods and Parameters.
Lecture 31 Creating Executable Programs on the Mainframe Tuesday, January 20, 2009.
User Defined Functions Chapter 7 2 Chapter Topics Void Functions Without Parameters Void Functions With Parameters Reference Parameters Value and Reference.
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.
Chapter 6 Introduction to Defining Classes. Objectives: Design and implement a simple class from user requirements. Organize a program in terms of a view.
CPSC 252 The Big Three Page 1 The “Big Three” Every class that has data members pointing to dynamically allocated memory must implement these three methods:
Chapter 14 Abstract Classes and Interfaces. Abstract Classes An abstract class extracts common features and functionality of a family of objects An abstract.
Introduction to z/OS Basics © 2006 IBM Corporation Chapter 7: Batch processing and the Job Entry Subsystem (JES) Batch processing and JES.
Programming with Java © 2002 The McGraw-Hill Companies, Inc. All rights reserved. 1 McGraw-Hill/Irwin Chapter 5 Creating Classes.
Methods: A Deeper Look. Template for Class Definition public class { } A.Import Statement B.Class Comments C.Class Name D.Data members E.Methods (inc.
Introduction to Java Chapter 7 - Classes & Object-oriented Programming1 Chapter 7 Classes and Object-Oriented Programming.
Inheritance. Inheritance - Introduction Idea behind is to create new classes that are built on existing classes – you reuse the methods and fields and.
Classes. Constructor A constructor is a special method whose purpose is to construct and initialize objects. Constructor name must be the same as the.
Chapter 5 Introduction to Defining Classes
1 Chapter 5: Defining Classes. 2 Basics of Classes An object is a member of a class type What is a class? Fields & Methods Types of variables: –Instance:
Liang, Introduction to Java Programming, Sixth Edition, (c) 2007 Pearson Education, Inc. All rights reserved Chapter 9 Inheritance and.
Programming With Java ICS201 University Of Ha’il1 Chapter 7 Inheritance.
Chapter 10: Classes and Data Abstraction. Objectives In this chapter, you will: Learn about classes Learn about private, protected, and public members.
IBM-Mainframes COBOL Class-1. Background and History  COBOL is an acronym for: Common Business Oriented Language  COBOL was developed in 1959 by the.
UMass Lowell Computer Science Java and Distributed Computing Prof. Karen Daniels Fall, 2000 Lecture 9 Java Fundamentals Objects/ClassesMethods Mon.
Chapter 8 Class Inheritance and Interfaces F Superclasses and Subclasses  Keywords: super F Overriding methods  The Object Class  Modifiers: protected,
 In the java programming language, a keyword is one of 50 reserved words which have a predefined meaning in the language; because of this,
Inheritance and Class Hierarchies Chapter 3. Chapter 3: Inheritance and Class Hierarchies2 Chapter Objectives To understand inheritance and how it facilitates.
Java Programming, Second Edition Chapter Twelve Advanced Inheritance Concepts.
Chapter 11: Advanced Inheritance Concepts. Objectives Create and use abstract classes Use dynamic method binding Create arrays of subclass objects Use.
Topic 8Classes, Objects and Methods 1 Topic 8 l Class and Method Definitions l Information Hiding and Encapsulation l Objects and Reference Classes, Objects,
Classes, Interfaces and Packages
Quick Review of OOP Constructs Classes:  Data types for structured data and behavior  fields and methods Objects:  Variables whose data type is a class.
Chapter 10: Classes and Data Abstraction. Classes Object-oriented design (OOD): a problem solving methodology Objects: components of a solution Class:
Methods.
5.1 Basics of defining and using classes A review of class and object definitions A class is a template or blueprint for an object A class defines.
OOP Basics Classes & Methods (c) IDMS/SQL News
Creating Java Applications (Software Development Life Cycle) 1. specify the problem requirements - clarify 2. analyze the problem - Input? Processes? Output.
UMass Lowell Computer Science Java and Distributed Computing Prof. Karen Daniels Fall, 2000 Lecture 10 Java Fundamentals Objects/ClassesMethods.
RealTimeSystems Lab Jong-Koo, Lim
Classes CS 162 (Summer 2009). Parts of a Class Instance Fields Methods.
Chapter 5 Introduction to Defining Classes Fundamentals of Java.
Java Programming: Guided Learning with Early Objects
Java Primer 1: Types, Classes and Operators
Chapter 3: Using Methods, Classes, and Objects
Programming in COBOL.
Chapter 9 Inheritance and Polymorphism
Java Programming Language
Chapter 7 Objects and Classes
SPL – PS3 C++ Classes.
Presentation transcript:

OO Cobol in z/OS

Enterprise Cobol Features Allows you to define classes with methods and in Cobol Create instances of Java and Cobol classes Invoke methods on Java and Cobol objects Write classes that inherit from Java or Cobol classes Overload methods

Java Interoperability OO Cobol programs must be compiled with the THREAD option in order to work with Java programs Cobol object instances are freed by the Java runtime system GC

JNI Support Basic Java features are accessed using Cobol syntax In Enterprise Cobol you can also invoke the Java Native Interface (JNI) to obtain other Java-oriented capabilities For example, converting PIC X type data to Java String objects

Wrapper Classes Legacy procedural Cobol code can be wrapped as a Cobol class to allow existing code to be called from Java Java code can create instances of Cobol classes and invoke Cobol class methods Java code can extend Cobol classes

Restrictions Cobol class definitions can’t contain EXEC SQL statements Cobol class definitions can’t contain EXEC CICS statements

A Cobol Driver to Invoke Java cbl dll,thread Identification division. Program-id. "tstDoor" recursive. Environment division. Configuration section. Repository. class Door is "Door". Data Division. Procedure Division. DISPLAY "COBOL PROGRAM tstDoor ENTERED" INVOKE Door "doSomething" DISPLAY "RETURNED FROM JAVA Door TO tstDoor“ GOBACK. END PROGRAM "tstDoor".

Defining a Cobol Class Identification division Environment division (configuration section only) Factory definition – Identification division – Data division – Procedure division (containing one or more method definitions) Object definition

Creating a Java Class in UNIX Use TSO OMVS to move to UNIX Build a directory for the class (cd, mkdir) Save an env file in the Directory (see env panel that follows) Use TSO OEDIT to create a .java file in the directory Compile the .java file with javac. Make sure you allocate enough space when you sign on to TSO

Door.java public class Door { private String state; public Door() System.out.println("building a closed door..."); state = "closed"; } public Door(String s) System.out.println("building the door..."); if (s.equals("open")) state = "open"; else

Door.java public void open() { System.out.println("About to open the door..."); if (state.equals("open")) System.out.println("The door is already open."); } else state = "open"; public void close() System.out.println("About to close the door..."); if (state.equals("closed"))

Door.java System.out.println("The door is already closed."); } else { state = "closed"; public String toString() return "The door is " + state + "."; public static void doSomething() System.out.println("I did something."); public void print() System.out.println("The door is " + state + ".");

An env File PATH=/bin:/u/Java5_31/J5.0/bin. LIBPATH=/lib:/usr/lib:/u/Java5_31/J5.0/bin:/u/Java5_31/J5.0/bin/j9vm CLASSPATH=/u/csup004/Door The CLASSPATH should point to the directories that contains your .class files

Compile, Link, Run JCL //CSUP004O JOB 'WOOLBRIGHT',CLASS=A,MSGCLASS=A,TIME=(0,5), // LINES=5,MSGLEVEL=(1,1),NOTIFY=&SYSUID,REGION=0M // SET COBPRFX='IGY410' // SET LIBPRFX='CEE' //* //COMPILE EXEC PGM=IGYCRCTL, // PARM='SIZE(5000K),LIB' //SYSLIN DD DSNAME=&&OBJECT(TSTDOOR),UNIT=SYSDA,DISP=(NEW,PASS), // SPACE=(CYL,(1,1,1)) //SYSPRINT DD SYSOUT=* //STEPLIB DD DSN=&COBPRFX..SIGYCOMP,DISP=SHR // DD DSN=&LIBPRFX..SCEERUN,DISP=SHR //SYSUT1 DD UNIT=SYSDA,SPACE=(CYL,(1,1)) //SYSUT2 DD UNIT=SYSDA,SPACE=(CYL,(1,1)) //SYSUT3 DD UNIT=SYSDA,SPACE=(CYL,(1,1)) //SYSUT4 DD UNIT=SYSDA,SPACE=(CYL,(1,1)) //SYSUT5 DD UNIT=SYSDA,SPACE=(CYL,(1,1))

Compile, Link, Run JCL //SYSUT6 DD UNIT=SYSDA,SPACE=(CYL,(1,1)) //SYSIN DD * cbl dll,thread Identification division. Program-id. "tstDoor" recursive. Environment division. Configuration section. Repository. class Door is "Door". Data Division. Procedure Division. DISPLAY "COBOL PROGRAM tstDoor ENTERED" INVOKE Door "doSomething" DISPLAY "RETURNED FROM JAVA Door TO tstDoor"

Compile, Link, Run JCL DISPLAY "RETURNED FROM JAVA Door TO tstDoor" GOBACK. END PROGRAM "tstDoor". /* //LKED EXEC PGM=IEWL, // PARM='RENT,LIST,LET,DYNAM(DLL),CASE(MIXED)' //SYSLIB DD DSN=&LIBPRFX..SCEELKED,DISP=SHR // DD DSN=&LIBPRFX..SCEELKEX,DISP=SHR //SYSTERM DD SYSOUT=* //SYSPRINT DD SYSOUT=* //SYSLMOD DD DSN=&&GOSET(TSTDOOR),DISP=(MOD,PASS), // UNIT=SYSALLDA,SPACE=(CYL,(1,1,1)),DSNTYPE=LIBRARY //SYSDEFSD DD DUMMY //OBJMOD DD DSN=&&OBJECT,DISP=(OLD,DELETE) //SYSLIN DD * INCLUDE OBJMOD(TSTDOOR) INCLUDE '/u/Java5_31/J5.0/bin/j9vm/libjvm.x' INCLUDE '/usr/lpp/cobol/lib/igzcjava.x'

Compile, Link, Run JCL //GO EXEC PGM=TSTDOOR, // PARM='/ENVAR("_CEE_ENVFILE=/u/csup004/env")XPLINK(ON) // POSIX(ON)' //* POSIX(ON)' //*STEPLIB DD DSN=CSUP004.LOAD,DISP=SHR //STEPLIB DD DSN=*.LKED.SYSLMOD,DISP=SHR // DD DSN=&LIBPRFX..SCEERUN2,DISP=SHR // DD DSN=&LIBPRFX..SCEERUN,DISP=SHR //SYSOUT DD SYSOUT=* //CEEDUMP DD SYSOUT=* //SYSUDUMP DD DUMMY //JAVAOUT DD PATH='/u/csup004/javaout', // PATHOPTS=(OWRONLY,OCREAT,OTRUNC), // PATHMODE=(SIRUSR,SIWUSR,SIRGRP) //

Sample Compile, Link, Run JCL CSU.PUBLIC.OO(OOMAIN1) OR CSU.PUBLIC.OO(CJSTATIC)

INVOKE

INVOKE NEW Use INVOKE class NEW to instantiate an object The returned reference must be saved in an object reference variable 01 myObj object reference DOOR. … INVOKE Door NEW RETURNING myObj

INVOKE NEW The constructor call based on the pattern of parameters that are passed. INVOKE Door NEW using by value jstring1 returning myDoor 01 jstring1 object reference jstring.

INVOKE A STATIC METHOD INVOKE Door "doSomething " Door is the class. “doSomething” is the static method in Door

INVOKING INSTANCE METHODS 01 myObj object reference Door. ================================ INVOKE Door NEW RETURNING myObj INVOKE myObj "open" INVOKE myObj "print" Class Door contains instance methods “open” and “print” which have no parms

Interoperable Types

Interoperable Arrays and Strings

Passing Parms, Returning Values working-storage Section. 01 myObj object reference Door. 01 intval10 pic s9(9) BINARY value 10. 01 intval20 pic s9(9) BINARY value 20. 01 intval30 pic s9(9) BINARY value 0. Procedure Division. DISPLAY "COBOL PROGRAM tstCalc ENTERED" INVOKE Calculator NEW using by value intval10 returning myObj INVOKE myObj "add" using by value intval20 returning intval30

USING Parameters in INVOKE Pass parameters BY VALUE when using INVOKE The BY VALUE phrase specifies that the value of the argument is passed, not a reference to the sending data item. The invoked method can modify the formal parameter that corresponds to an argument passed by value, but changes do not affect the argument because the invoked method has access only to a temporary copy of the sending data item.

Returning Constraints If the RETURNING item is not an object reference, the following rules apply: – If the target method is implemented in COBOL, the returning item in the INVOKE statement and the RETURNING item in the target method must have an identical data description entry. – If the target method is implemented in Java, the returning item in the INVOKE statement must correspond to the Java type of the method result, as described in “Interoperable Types”

Returning Constraints If the RETURNING item is an object reference, the RETURNING item specified in the INVOKE statement must be an object reference typed exactly to the class of the returning item specified in the target method. That is, the class specified in the returning clause must not be a subclass or a superclass of the class of the returning item in the target method.

OO Exercise #1 In UNIX, build a Java class called Point that stores a pair of integers (x and y coordinates). Put in the normal things that Java Classes should have (Constructor, accessors, mutators, toString) Build a second Java class called PointStuff that has a static method called distance which is passed two Point objects. The method computes the distance between the two points and returns the distance √((x1-x2)2 –(y1-y2)2. Write a Cobol program that creates two Point objects and passes them to distance. Print out the result the method returns.

Building Cobol Classes IDENTIFICATION DIVISION. CLASS-ID. Account inherits Base. The class ID names the class you are defining. Base represents java.lang.Object and is referenced in the Repository.

Repository Paragraph Environment Division. Configuration Section. Repository. Class Base is “java.lang.Object” Class Account is “Account”. The Repository is used to relate the internal class names to external class names. The Repository has rules for generating external names if they are omitted. Extenal names can include fully qualified package names.

Object Paragraph Identification Division Object. … data and methods End Object. The Object paragraph is used to define the instance data and methods of the class. The Object paragraph is immediately preceded by an Identification Division header. (Different from the one that starts the class.)

Working Storage in Object Identification Division Object. Data Division. Working Storage Section. 01 balance pic s9(6) value 0. … End Object.

Working Storage in Object Working Storage fields become instance data for Cobol objects. Instance fields are initialized with value clauses in Working Storage Fields are allocated when the object is instantiated Fields exist until the object is garbage collected by the Java run time

Working Storage To initialize more complicated objects, you need to write special initialization methods in a Factory Essentially, there is one constructor for Cobol objects Fields are equivalent to Java private nonstatic member data No other class or subclass can reference Cobol instance data directly Provide sets and gets to make fields accessible

Instance Methods in Object Instance methods are defined in the Procedure Division of the Object paragraph Each method has four divisions followed by END METHOD marker

Instance Method Divisions Identification Division. Method-id. “init” Environment Division Input-Output Section. File-Control. Select...myFile assign to MYFILE … used to relate filenames used in method to external names (optional)

Instance Method Divisions Data Division. File Section. …used to define a file record layout Local-Storage Section. …used to define local variables which are allocated upon entry and freed upon return. Put a value clause to initialize a variable upon entry

Instance Method Divisions Data Division. … Working-Storage Section. … One copy of this storage is allocated at runtime. Data persists in its last used state. One copy exists for all threads.

Instance Method Divisions Data Division. … Linkage Section. … Used to describe parameters and fields that are returned from the method.

Instance Method Divisions Procedure Division. … used to define the executable code for the method You may not code: ENTRY, EXIT, ALTER, GOTO, SEGMENT-LIMIT, USE FOR DEBUGGING SORT or MERGE You may code: EXIT METHOD GOBACK

Passing Parameters Specifiy parms in the division header. Parms must be passed by value. Describe each parm in Linkage as 01 or 77 level items Data types must be interoperable with Java Linkage Section. 01 X pic s9(9) binary. 01 Y pic s9(9) binary. Procedure Division using by value X, Y

Returning a Parm A method can return a value. This is evident when the method is invoked: INVOKE Calculator “add” using by value X Y returning Total Variables that are returned must be described as 01 or 77 items in the Linkage Section

OO Exercise #2 Build a Calculator class that has a single private variable “regValue” that will hold an integer (Pic S9(9) Binary). Build an “setRegValue” method that changes the stored value Build a “getRegValue” method that returns the stored value Build an “add” method that passes an integer, adds it to the stored value and returns the sum Build a “print” method that prints the object