U:\Book\Book_09.doc Multilanguage Object Programming

Similar documents
Chapter 10 :: Data Abstraction and Object Orientation

Chapter 9 :: Data Abstraction and Object Orientation

Computer Science 4U Unit 1. Programming Concepts and Skills Modular Design

Part (04) Introduction to Programming

Chapter 3:: Names, Scopes, and Bindings (cont.)

COP 3330 Final Exam Review

Lecturer: William W.Y. Hsu. Programming Languages

Zhifu Pei CSCI5448 Spring 2011 Prof. Kenneth M. Anderson

Chapter 3:: Names, Scopes, and Bindings (cont.)

Introduction to Computers and Programming Languages. CS 180 Sunil Prabhakar Department of Computer Science Purdue University

Programming for the Web with PHP

Programming in C++ Prof. Partha Pratim Das Department of Computer Science and Engineering Indian Institute of Technology, Kharagpur

What are the characteristics of Object Oriented programming language?

OOPS Viva Questions. Object is termed as an instance of a class, and it has its own state, behavior and identity.

G Programming Languages - Fall 2012

JAVA: A Primer. By: Amrita Rajagopal

UNIT I Programming Language Syntax and semantics. Kainjan Sanghavi

public class Foo { private int var; public int Method1() { // var accessible anywhere here } public int MethodN() {

SAP Automation (BC-FES-AIT)

Second-generation: Assembly language. Figure 6.1 Generations of programming languages. Assembly Language Characteristics.

Chapter 12. OOP: Creating Object- Oriented Programs. McGraw-Hill. Copyright 2011 by The McGraw-Hill Companies, Inc. All Rights Reserved.

An Overview of Visual Basic.NET: A History and a Demonstration

B2.52-R3: INTRODUCTION TO OBJECT ORIENTATED PROGRAMMING THROUGH JAVA

Chapter 6: Programming Languages

Microsoft Visual Basic 2005: Reloaded

Microsoft Visual Basic 2005: Reloaded

Chapter 1 Getting Started

A PROGRAM IS A SEQUENCE of instructions that a computer can execute to

Abstract data types &

Abstract Data Types & Object-Oriented Programming

Chapter 2. Building Multitier Programs with Classes The McGraw-Hill Companies, Inc. All rights reserved. McGraw-Hill

C++ (Non for C Programmer) (BT307) 40 Hours

EDIABAS BEST/2 LANGUAGE DESCRIPTION. VERSION 6b. Electronic Diagnostic Basic System EDIABAS - BEST/2 LANGUAGE DESCRIPTION

FUNCTION MODULE. BAPI are RFC enabled function modules. Might Be Remote Enabled or May not be Remote Enabled

Introduction. In this preliminary chapter, we introduce a couple of topics we ll be using DEVELOPING CLASSES

COMP 181. Agenda. Midterm topics. Today: type checking. Purpose of types. Type errors. Type checking

Homework #2 Think in C, Write in Assembly

Names, Scopes, and Bindings II. Hwansoo Han

Programmiersprachen (Programming Languages)

Sri Vidya College of Engineering & Technology

10. Abstract Data Types

CSC 533: Organization of Programming Languages. Spring 2005

SAP ABAP Training Course Content :

VB.NET. Exercise 1: Creating Your First Application in Visual Basic.NET

Graphical Interface and Application (I3305) Semester: 1 Academic Year: 2017/2018 Dr Antoun Yaacoub

Distributed Objects. Object-Oriented Application Development

Windows Script Host Fundamentals

Programming Languages

CERTIFICATE IN WEB PROGRAMMING

COMP 250 Winter 2011 Reading: Java background January 5, 2011

TYPES, VALUES AND DECLARATIONS

CS 231 Data Structures and Algorithms, Fall 2016

Implementing Subprograms

02 Features of C#, Part 1. Jerry Nixon Microsoft Developer Evangelist Daren May President & Co-founder, Crank211

Lecture 2, September 4

Inheritance and Interfaces

INTRODUCTION TO.NET. Domain of.net D.N.A. Architecture One Tier Two Tier Three Tier N-Tier THE COMMON LANGUAGE RUNTIME (C.L.R.)

1. Describe History of C++? 2. What is Dev. C++? 3. Why Use Dev. C++ instead of C++ DOS IDE?

Classes and Methods עזאם מרעי המחלקה למדעי המחשב אוניברסיטת בן-גוריון מבוסס על השקפים של אותו קורס שניתן בשנים הקודמות

Lesson 10A OOP Fundamentals. By John B. Owen All rights reserved 2011, revised 2014

1. A Web Form created in Visual Basic can only be displayed in Internet Explorer. True False

Data Abstraction. Hwansoo Han

JAVA MOCK TEST JAVA MOCK TEST II

Chapter Twelve. Systems Design and Development

Lesson 10B Class Design. By John B. Owen All rights reserved 2011, revised 2014

Rules and syntax for inheritance. The boring stuff

2 rd class Department of Programming. OOP with Java Programming

Lecture 18 Tao Wang 1

Classes and Methods לאוניד ברנבוים המחלקה למדעי המחשב אוניברסיטת בן-גוריון

Discussion. Type 08/12/2016. Language and Type. Type Checking Subtypes Type and Polymorphism Inheritance and Polymorphism

AP Computer Science Chapter 10 Implementing and Using Classes Study Guide

Computation Abstractions. Processes vs. Threads. So, What Is a Thread? CMSC 433 Programming Language Technologies and Paradigms Spring 2007

Object Oriented Programming in C#

Programming in C++ Prof. Partha Pratim Das Department of Computer Science and Engineering Indian Institute of Technology, Kharagpur

THE CONCEPT OF OBJECT

Processor. Lecture #2 Number Rep & Intro to C classic components of all computers Control Datapath Memory Input Output

ADMINISTRATIVE MANAGEMENT COLLEGE

CS Internet programming Unit- I Part - A 1 Define Java. 2. What is a Class? 3. What is an Object? 4. What is an Instance?

NOTE: Answer ANY FOUR of the following 6 sections:

STUDY NOTES UNIT 1 - INTRODUCTION TO OBJECT ORIENTED PROGRAMMING

Object Oriented Programming is a programming method that combines: Advantage of Object Oriented Programming

Chapter 02 Building Multitier Programs with Classes

G Programming Languages - Fall 2012

1 Epic Test Review 2 Epic Test Review 3 Epic Test Review 4. Epic Test Review 5 Epic Test Review 6 Epic Test Review 7 Epic Test Review 8

Glossary. For Introduction to Programming Using Python By Y. Daniel Liang

COMSC-051 Java Programming Part 1. Part-Time Instructor: Joenil Mistal

DHANALAKSHMI COLLEGE OF ENGINEERING, CHENNAI DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING REWRAP TEST I CS6301 PROGRAMMING DATA STRUCTURES II

INHERITANCE: EXTENDING CLASSES

Imperative Languages!

CSE 142 Su 04 Computer Programming 1 - Java. Objects

M301: Software Systems & their Development. Unit 4: Inheritance, Composition and Polymorphism

Short Notes of CS201

Java Threads and intrinsic locks

Lecture 13: Object orientation. Object oriented programming. Introduction. Object oriented programming. OO and ADT:s. Introduction

POLYTECHNIC OF NAMIBIA SCHOOL OF COMPUTING AND INFORMATICS DEPARTMENT OF COMPUTER SCIENCE

3.Constructors and Destructors. Develop cpp program to implement constructor and destructor.

INTRODUCTION TO Object Oriented Systems BHUSHAN JADHAV

Programming Exercise 14: Inheritance and Polymorphism

SAP' ABAP. Handbook. Kogent Learning Solutions, Inc. Sudbury, Massachusetts JONES AND BARTLETT PUBLISHERS BOSTON TORONTO LONDON SINUAPORI:

Contents A Little C++

Transcription:

1 Book 9 Multilanguage Object Programming U:\Book\Book_09.doc Multilanguage Object Programming 5 What to Read in This Part Multilanguage Object Programming... 1 1 Programming Objects In Java, VB and ABAP... 2 1.1 Before we start... 2 1.2 Object Oriented Thinking... 2 1.3 Object Classes and Instances... 3 1.4 Building Classes with Visual Basic... 4 1.5 Building Classes with ABAP... 5 1.6 Building Classes With Java... 5 1.7 Sharing Resources and Proxy Applications... 5 1.8 Constructors... 6 1.9 Destructors...7 1.10 Property Declarations... 7 1.11 Methods Declarations... 8 1.12 Strings Declarations... 8 1.13 Array Declarations... 9 2 Exploring SAP R/3 BAPIs With R/3... 10 3 Examples of Calling BAPIs From Visual Basic... 11 4 Examples of Calling BAPIs From Java... 12 Fehler! Es wurden keine Einträge für das Inhaltsverzeichnis gefunden. 1

2 Fehler! Formatvorlage nicht definiert./multilanguage Object Programming 1 Programming Objects In Java, VB and ABAP Object oriented programming is a way of thinking. Their base idea is the interaction of program sniplets through messages and events. It is our goal to make you familiar with the way of thinking in distributed environments and to make it clear that object oriented programming is not programming in a different syntax where methods take the part of procedures and classes replace function libraries, but that the central philosophy of objects is the communication with messages and reacting to events. Object oriented programming reverses the traditional programming approach: instead of a big central master program to marshal program parts, there is now a community of small programs that talk to each others. 20 1.1 Before we start Object oriented 10 programming is a way of thinking Object oriented programming is a way 15 of thinking. Their base idea is the interaction of programs through messages and events. PL/1 has been one of the first object oriented languages. I say this to everybody who claims, he had a thorough understanding of object technologies. Some are too young to know PL/1 and many others heavily deny this. PL/1 exactly fulfils this requirements, definitely better than many wannabe object programming languages like Visual Basic. OOP requires a program to communicate with parallel running processes. These processes may be instantiated by the master process or simply exist with unknown genesis. I stress this to make clear, that an OOP language is not characterised by the presence of certain language statements like Create Object, not 1does its absence lead to any conclusion that the language is not object oriented. ABAP IV (without objects) is the same: it is a process and transaction based language and therefore inherently object oriented. 30 45 1.2 Object Oriented Thinking Object oriented programming is a way of thinking 25 Traditional programs are objects, too In programming, an object sends and receives messages 35 OOP is also the sixth 40 programming language generation To say it loud and clearly and again: Object oriented programming is a way of thinking, not a programming language. Instead of putting all the functionality into a huge lengthy program, an object based program will create simple individual program parts that expose there essential functionality to other programs (and call them methods.). A traditional program can also be seen as an object, which. is by itself a compound collection of other objects, such as variables, type definitions, sub routines. Functions and subroutines in a public library are somewhat the same as methods as on object, while the library corresponds to the object class. Again: the difference is the abstract interpretation of class and library, respectively. When we talk about Object programming (lets call it OOP) in a stricter sense, we basically talk about communication and messaging. If we see it that way, an object is a piece of software that can receive messages, process them and send out messages to other objects. In a true object environment an object broadcasts messages to everybody and an object that feels responsible for the requested task picks up that message, does some action and sends a message back to the original requester or broadcasts itself a result. OOP languages can also be seen as Sixth Generation Languages (1.GL: machine code; 2.GL: mnemonic languages like assembler, BASIC, FORTRAN and C; 3.GL: Typed procedural languages like PASCAL, Visual Basic and PL/1; 4:GL Query languages like SQL; 5.GL: Artificial Intelligence descriptive modeling languages like LISP, PROLOG, VRML; 6.GL: Distributed communication languages like SmallTalk, DELPHI, ADA, Java, VB.NET (maybe), C++). 2 Characteristics of objects implied by messaging of 12 Axel Angeli 12 March 2001

Programming Objects In Java, VB and ABAP/Fehler! Formatvorlage nicht definiert. 3 50 55 60 65 70 75 Objects are polymorph Inheritance Instantiation The following characteristics are corollaries of that universal object concept. Although them are a consequence of the base characteristic of a message based interaction they are often used as description of what objects are. Naturally they are, it is in the nature of messages. Polymorphism means that the same general request may be processed by different methods according to the nature of the parameters involved or the context they are in. Example: Adding two numbers, adding two strings or two Boolean expressions are completely different algorithms although they may me denoted equally. 5 + 5 10 Fred + Flintstone Fred Flintstone true + false true (sic! Logical AND is a multiplication) Because true objects send out messages like the following: Execute 5 + 5 where both operands are integer numbers The methods that care for strings or Boolean operations will not feel addressed. For the programmer the operations will appear polymorph (will look the same although the context is different). Objects can inherit methods and characteristics from another object, known as a parent object. Thinking in true abstract objects, this is more than natural: an object that descends from a parent object inherits the parent s features unless it reimplements them. This is the nature of inheritance in OOP. In technical terms, inheritance can be simple realized as a redirection. If a message is received and there does not exist a proper method, it will be redirected to the proper method of the parent object. Objects have a limited lifetime. They are created and destroyed during the execution of a master program or when a special event occurs. The created object is called an instance while the template which is used as a blueprint for the object instance is called a class. Every time an object is created it typically executes a constructor (in Visual Basic: Sub Class_Initialize) and before it is destroyed a dedicated exit routine, called a destructor in Visual Basic: Sub Class_Terminate) is called. 85 90 1.3 Object Classes and Instances Classes are blueprints for objects. Unlike traditional programs, an object instance does load the program code only once with the class while given each instance a private data memory area. Classes are blueprints for an object creation and multiple objects can be created simultaneously 80 from the same class blueprint An object instance is a closed memory area created from the object class template Classical programs load the code for every instance that is called A class is a definition that describes how an object should look like and what methods it can execute. The trick with classes is, that an arbitrary number of objects can be created from a class template simultaneously. In classical programming terms a class would be somewhat like a program stored on a disk. Every program has its own memory space where it stores the content of its variables. An instance of a class is called an object. That would correspond to having the program with its own proper memory space loaded. Now you could load the program with a new and separate memory space loaded again and executed. That would be the second instance of a class. A class is not yet an executable object but it is used to create an arbitrary number of object instances on demand. Such object instances acquire an own private memory block where the execute and store there main memory data. This memory block is completely shielded from other programs which can only communicate with the object through the predefined interfaces and methods. This is also widely known as data encapsulation. The difference between objects and conventional structured programs is the concept of multithreading. In a conventional environment you can execute a 3

4 Fehler! Formatvorlage nicht definiert./multilanguage Object Programming 95 110 Object load the class 100 only once for any number of instances Object load the class only once for any number of instances 105 program by loading it into the memory, reserving a private workspace for it and execute it. You can call the program again and thus load another copy of the program into the memory. This is fine because every instance of the program gets its own memory space and data area. The bad news is, that the program is loaded over and over again into the memory, thus unnecessarily consuming precious resources. Objects instances actually replicate the data block every time an instance is created while the executable code remains in the object class block and is loaded only once into the memory. It actually sounds profane that loading the program code only once into the machine while giving each object instance an own memory area to work with. It truly is like that. However, writing a compiler and operating system that actually supports this type of memory management is far from trivial. In the case of Visual Basic and Windows it must be said, that it does not truly implement all these kind of memory management and threading mechanism as it is done by most UNIX and LINUX implementations. For an application developer this is not of much importance but threading concepts will be an issue for any performance and sizing analyst. 120 125 130 135 1.4 Building Classes with Visual Basic Visual Basic stores compiled classes that belong together in libraries, the dll-files. With the CreateObject command the class template is instantiated into a living object. Classes are blueprints for an object creation and multiple objects can 115 be created simultaneously from the same class blueprint Steps to create a class in Visual Basic A class is a definition that describes how an object should look like and what methods it can execute. The trick with classes is, that an arbitrary number of objects can be created from a class template simultaneously. In classical programming terms a class would be somewhat like a program stored on a disk. Every program has its own memory space where it stores the content of its variables. An instance of a class is called an object. That would correspond to having the program with its own proper memory space loaded. Now you could load the program with a new and separate memory space loaded again and executed. That would be the second instance of a class. After choosing New project in Visual-Basic select ActiveX-dll and enter a name for the library in the menu-item project, properties, project name. This name will also be a default for the name of the VB project file (vbp) and the dll-filename. You could use three different names, but I don t know what this would be good for. enter a name for the class in the properties-windows. In the project-explorer you can add additional classes. The source-code for each class are stored in a files with the extension.cls select the property MTS-TransactionMode to anything else but not an MTS object. uses transactions is a good choice. In the general, declaration -section of the code-window you can create properties for the class by simply entering: PUBLIC XXX AS TTT (XXX is any name for the property and TTT is the data type i.e. integer. the prefix PUBLIC before the name of a sub-program is used to define a method. Note that only complied dll can go into the MTS. You build the dll in the filemenu. 4 of 12 Axel Angeli 12 March 2001

Programming Objects In Java, VB and ABAP/Fehler! Formatvorlage nicht definiert. 5 Listing 1: Sample Code for a class Public counter as Integer Public Sub inc() counter = counter + 1 Public Sub clear() counter = 0 145 150 155 1.5 Building Classes with ABAP ABAP supports the concept of Classes since release 4 and since 4.6 they are integral part of the ABAP language and repository. Steps to create a class in Creating a local class that can be used within your currently running program is Visual Basic 140 supported by means of After choosing New project in Visual-Basic select ActiveX-dll and Listing 2: Sample Code for a class Public counter as Integer Public Sub inc() counter = counter + 1 Public Sub clear() counter = 0 enter a name for the library in the menu-item project, properties, project name. This name will also be a default for the name of the VB project file (vbp) and the dll-filename. You could use three different names, but I don t know what this would be good for. enter a name for the class in the properties-windows. In the project-explorer you can add additional classes. The source-code for each class are stored in a files with the extension.cls select the property MTS-TransactionMode to anything else but not an MTS object. uses transactions is a good choice. In the general, declaration -section of the code-window you can create properties for the class by simply entering: PUBLIC XXX AS TTT (XXX is any name for the property and TTT is the data type i.e. integer. the prefix PUBLIC before the name of a sub-program is used to define a method. Note that only complied dll can go into the MTS. You build the dll in the filemenu. 1.6 Building Classes With Java 165 1.7 Sharing Resources and Proxy Applications A proxy is an application that installs itself between an application and a server. For both ends the proxy will appear as the other peer. A Proxy plays an important roles in sharing critical and expensive 160 connections Proxy marshaling The most obvious use of a proxy application to share a resource, like connecting through a modem to a server. In an apartment threaded model this would lead to the undesirable situation that every new session would try to dial up an individual connection to the server and result in extra phone costs. A proxy application can work as a handler to share the single phone line, once established. The proxy will look, to the client, like the server application itself and take requests from the client. The requests will then be serialized by the proxy and forwarded to the true server as soon as it is available. The ability to accept requests from multiple clients and redirect them to a single 5

6 Fehler! Formatvorlage nicht definiert./multilanguage Object Programming 180 A Proxy may help to 170 limit the number of simultaneous connections to R/3 A Proxy can shield the 175 internal login data from ASP connection is called Proxy Marshaling. Proxy marshaling commands the COM application to not create a new object instance whenever a new thread is opened but instead to serialize them and process them one after the other. R/3 allows a virtually unlimited number of simultaneous RFC connections. However, there are situations when you prefer to use a single connection to R/3 and re-route all requests through that single connection. This may already be desirable when your R/3 server does limit the number of simultaneous RFC connections by a single user. Another even more important use of a proxy component is the ability to shield the R/3 login data from the ASP tier. For that purpose, the ASP will always contact the proxy component as a trusted application, i.e. it will not require any kind of login. The proxy will automatically perform the appropriate logon to R/3 and get the necessary logon credentials from a hidden source. The logon can be set up in a way that it remains absolutely transparent to the ASP, i.e. the ASP then can see the R/3 as a permanent and local connection. 1.8 Constructors A constructor method is a method, which is automatically executed when a class instance is instantiated. Thus it is the last action performed during the lifecycle of a class instance. 185 Constructors in Java A Java Constructor looks like a method definition, with the two defining characteristics: A constructor has the same name as its class It has no result type 190 Constructor in Java public class Test { This is the constructor for the class Test: public Test() { } Here the class is created and the constructor is executed during instantiation. } public static void main(string[] args) { Test test1 = new Test(); } Constructors in ABAP Objects 195 Constructor in Visual Basic 6 Constructors in VB A constructor in Visual Basic is a special Method with the name Class_Initialize. VERSION 1.0 CLASS Attribute VB_Name = "TEST" of 12 Axel Angeli 12 March 2001

Programming Objects In Java, VB and ABAP/Fehler! Formatvorlage nicht definiert. 7 This is the constructor for the class Test: Private Sub Class_Initialize() This is the destructor for the class Test: Private Sub Class_Terminate() When the class is created the constructor is called automatically. 200 Set newinst = New Test() Another way to create an instance in VB: Set newinst = CreateObject( Test ) 1.9 Destructors Destructors are special methods, which are called when the instance of a class is destroyed. Thus it is the last action performed during the lifecycle of a class instance. Destructors in Java There are no special destructor methods in Java. 205 Destructors in ABAP Objects Destructor in Visual Basic Destructors in VB A destructor in Visual Basic is a special Method with the name Class_Terminate. VERSION 1.0 CLASS This is the constructor for the class Test: Private Sub Class_Initialize() This is the destructor for the class Test: Private Sub Class_Terminate() 210 1.10 Property Declarations A property of a class is an enhancement of a variable. In addition to simply assigning or reading the value of a variable, a property allows the execution of a full sequence of actions, both when setting and reading the value of the property. Properties in Java 7

8 Fehler! Formatvorlage nicht definiert./multilanguage Object Programming 215 The method s name is: Properties in Java are declared as a method with a special naming convention: the property s name with the first character capitalised prefixed with get for a get property prefixed with set for a set property Get Properties in Java Set Properties in Java Get Properties in VB Set Properties in VB 220 Get Properties in ABAP Set Properties in ABAP Properties in VB Properties in ABAP Objects 1.11 Methods Declarations 225 Method in Java Methods in Java Method in VB Methods in VB Method in ABAP 230 Methods in ABAP Objects 1.12 Strings Declarations Strings in Java String in Java String in VB 235 Strings in VB 8 of 12 Axel Angeli 12 March 2001

Programming Objects In Java, VB and ABAP/Fehler! Formatvorlage nicht definiert. 9 String in ABAP Strings in ABAP Objects 1.13 Array Declarations Arrays in Java Array in Java 240 Array in VB Arrays in VB 245 Array in ABAP Arrays in ABAP Objects 9

10 Fehler! Formatvorlage nicht definiert./multilanguage Object Programming 2 Exploring SAP R/3 BAPIs With R/3 10 of 12 Axel Angeli 12 March 2001

Examples of Calling BAPIs From Visual Basic/Fehler! Formatvorlage nicht definiert. 11 3 Examples of Calling BAPIs From Visual Basic 11

12 Fehler! Formatvorlage nicht definiert./multilanguage Object Programming 4 Examples of Calling BAPIs From Java 250 12 of 12 Axel Angeli 12 March 2001