This document discusses object-oriented programming (OOP) concepts in ABAP such as classes, objects, encapsulation, inheritance, and polymorphism. It provides examples of creating local and global classes, defining and implementing methods, handling exceptions, and interacting with class methods and attributes. Various OOP techniques in ABAP like object instantiation, access specifiers, and parameter passing are also explained with example code.
This document discusses using switch-case statements in C programming to perform mathematical operations. It provides the syntax for switch-case, an example of a program that takes two numbers and an operator as input to perform addition, subtraction, multiplication and division. The program is presented along with its flowchart and algorithm. The learning objectives are to write switch-case syntax, draw flowcharts, write algorithms and programs using switch-case statements.
This document discusses C programming loops and provides examples of programs using for, while, do-while, and nested loops. It includes the theory, syntax, flowcharts, algorithms, and programs for each type of loop. Several programs are provided as examples, such as one to display characters and their ASCII values using a for loop, one to calculate the factorial of a number using a while loop, one to find the Fibonacci series using a do-while loop, and one to find prime numbers using a nested loop. Students are provided learning objectives for each example to learn how to write the loop syntax, draw flowcharts, write algorithms, and implement the programs using the specified loop type.
This document provides instructions for writing a C program to count the vowels, consonants, digits, and whitespace in a string. It begins by explaining how to declare, initialize, read, and manipulate strings in C. It then presents the algorithm and full C program to iterate through a string, check each character, and increment the appropriate counter. The program takes a string as input and outputs the count of each type of character. Examples of additional string programs are provided for practice.
It is an attempt to make the students of IT understand the basics of programming in C in a simple and easy way. Send your feedback for rectification/further development.
This document provides information on writing a C program to find the largest number in an array. It defines arrays and how they are declared and initialized. The document includes a flowchart and algorithm for the problem. It also includes the full C program code to find the largest number in an array by getting array size and elements from user input and iterating through the array to find the largest. It concludes by stating the learning outcomes were to declare arrays, draw a flowchart, write an algorithm, and write the program.
This document discusses C variables including declaring, initializing, and naming variables as well as built-in data types. It also covers input/output functions like scanf() and printf(), arithmetic, relational, and logical operators, and comments in C code. Specifically, it defines variables as named locations in memory that hold values, shows how to declare and initialize variables with examples, and explains rules for naming variables. It also demonstrates using operators with examples and precedence rules.
1. There are two main ways to handle input-output in C - formatted functions like printf() and scanf() which require format specifiers, and unformatted functions like getchar() and putchar() which work only with characters.
2. Formatted functions allow formatting of different data types like integers, floats, and strings. Unformatted functions only work with characters.
3. Common formatted functions include printf() for output and scanf() for input. printf() outputs data according to format specifiers, while scanf() reads input and stores it in variables based on specifiers.
This document discusses using switch-case statements in C programming to perform mathematical operations. It provides the syntax for switch-case, an example of a program that takes two numbers and an operator as input to perform addition, subtraction, multiplication and division. The program is presented along with its flowchart and algorithm. The learning objectives are to write switch-case syntax, draw flowcharts, write algorithms and programs using switch-case statements.
This document discusses C programming loops and provides examples of programs using for, while, do-while, and nested loops. It includes the theory, syntax, flowcharts, algorithms, and programs for each type of loop. Several programs are provided as examples, such as one to display characters and their ASCII values using a for loop, one to calculate the factorial of a number using a while loop, one to find the Fibonacci series using a do-while loop, and one to find prime numbers using a nested loop. Students are provided learning objectives for each example to learn how to write the loop syntax, draw flowcharts, write algorithms, and implement the programs using the specified loop type.
This document provides instructions for writing a C program to count the vowels, consonants, digits, and whitespace in a string. It begins by explaining how to declare, initialize, read, and manipulate strings in C. It then presents the algorithm and full C program to iterate through a string, check each character, and increment the appropriate counter. The program takes a string as input and outputs the count of each type of character. Examples of additional string programs are provided for practice.
It is an attempt to make the students of IT understand the basics of programming in C in a simple and easy way. Send your feedback for rectification/further development.
This document provides information on writing a C program to find the largest number in an array. It defines arrays and how they are declared and initialized. The document includes a flowchart and algorithm for the problem. It also includes the full C program code to find the largest number in an array by getting array size and elements from user input and iterating through the array to find the largest. It concludes by stating the learning outcomes were to declare arrays, draw a flowchart, write an algorithm, and write the program.
This document discusses C variables including declaring, initializing, and naming variables as well as built-in data types. It also covers input/output functions like scanf() and printf(), arithmetic, relational, and logical operators, and comments in C code. Specifically, it defines variables as named locations in memory that hold values, shows how to declare and initialize variables with examples, and explains rules for naming variables. It also demonstrates using operators with examples and precedence rules.
1. There are two main ways to handle input-output in C - formatted functions like printf() and scanf() which require format specifiers, and unformatted functions like getchar() and putchar() which work only with characters.
2. Formatted functions allow formatting of different data types like integers, floats, and strings. Unformatted functions only work with characters.
3. Common formatted functions include printf() for output and scanf() for input. printf() outputs data according to format specifiers, while scanf() reads input and stores it in variables based on specifiers.
This document discusses delegates, lambda expressions, and events in C#. It covers:
- Delegates allow methods to be passed as arguments or returned as the value of functions.
- Lambda expressions provide a concise way to write inline anonymous methods for use with delegates.
- Events use delegates to allow classes to notify listeners of events, following a publish/subscribe model. Event publisher classes raise events, while listeners subscribe to events.
The document discusses input and output functions in C programming. It describes getchar() and putchar() for character input/output, printf() and scanf() for formatted input/output, and gets() and puts() for string input/output. It provides examples of using these functions to read input from the keyboard and display output to the screen.
The document discusses pointers in C programming. It begins by explaining how variables are stored in memory with addresses and values. It then introduces pointers as variables that store memory addresses. Examples are given to demonstrate declaring pointer variables and accessing the value at a pointer's address using the dereference operator (*). The document also covers double pointers and passing arguments by value versus by reference. Key topics covered in less than 3 sentences include: pointers store memory addresses, dereferencing a pointer accesses the value at its address, double pointers point to other pointer variables, call by reference passes argument addresses allowing the called function to modify the original variables.
C's character set includes alphabets, digits, special characters, and whitespace characters. Source character set includes these categories which are used to write programs. Execution character set includes escape sequences which are used at runtime and start with backslash. Common escape sequences include newline, tab, carriage return. Variables in C must start with a letter or underscore and can include digits and letters but no special symbols. Variables are declared with a data type and can be initialized. Variables can be local, global, or environment based on their scope. Identifiers name variables and other elements and have similar naming rules as variables. Keywords are predefined words that cannot be used as identifiers.
Chapter 4 : Balagurusamy Programming ANSI in CBUBT
The document contains solutions to programming problems from the book "C Programming: Chapter-4" by E. Balagurusamy. It includes problems on input/output operators like scanf() and printf(), reading and displaying data in various formats, rounding numbers, bar charts, multiplication tables, and formatting output. Each problem has the code snippet to solve it along with sample input/output. The solutions demonstrate proper use of scanf(), printf(), and formatting specifiers to handle different data types and formats.
This chapter discusses fundamental concepts of C programming language and basic input/output functions. It covers C development environment, C program structure including main functions and statements, basic data types, input/output functions like printf and scanf, and common programming errors.
The document describes the basic structure and components of a C program using flowcharts and code examples. It includes 3 key parts:
1. Preprocessor directives like #include that provide header files and libraries.
2. Input/output functions like printf and scanf that allow transferring data to and from the user.
3. Common operators in C like arithmetic, relational, logical, and unary operators and their order of precedence.
The document uses flowcharts and code snippets to demonstrate how these components fit together in a simple C program that takes input from the user and performs calculations.
Classes allow programmers to define custom data types called objects that encapsulate both data and functions that operate on that data. A class defines the form of an object, while an object is an instance of a class. Classes contain private and public members and methods - private members and methods can only be accessed within the class, while public members and methods provide the interface for outside access. Classes provide data hiding, reusability, and changeability in programs. Common C++ classes include strings and file input/output streams.
The document discusses functions in C programming. It defines a function as an independent, reusable block of code that performs a specific task. Functions allow for modularity and code reuse by encapsulating reusable blocks of code. Functions receive parameters, perform operations, and return values. They improve code organization and maintainability.
This document discusses writing a C program to add two matrices using a two-dimensional array. It includes the theory of multi-dimensional arrays in C, a flowchart showing the process of adding matrices, an algorithm describing the steps, sample code to add two 2x2 matrices, example input/output, and concludes by stating the learning outcomes of understanding how to declare and use multi-dimensional arrays to solve problems like adding matrices.
This document contains 24 C++ programs with explanations and sample outputs. The programs cover basic concepts like variable declaration and input/output, conditional statements, loops, functions, arrays and structures. The programs include calculating area and circumference of shapes, finding largest/smallest numbers, checking leap years, calculating electricity bills, compound interest, digit sum, palindrome checking and more. The programs are meant as examples for students to practice and learn C++ programming.
1) The document discusses object-oriented programming (OOPS) concepts in ABAP such as classes, objects, attributes, methods, inheritance, polymorphism, and exceptions.
2) It provides examples of creating local and global classes, defining methods, and handling exceptions.
3) Key aspects covered include defining classes, creating objects, accessing attributes and methods, static and instance methods/attributes, and using constructor methods.
This document discusses C and C++ selection statements including if, if-else, and if-else-if. It provides examples of code using these conditional statements and corresponding flowcharts. It also includes exercises for the reader to complete code snippets and answer questions about the flow of execution through the conditional logic.
This document provides an overview of the C programming language. It covers C fundamentals like data types and operators. It also discusses various control structures like decision making (if-else), loops (for, while, do-while), case control (switch) and functions. Additionally, it explains input/output operations, arrays and string handling in C. The document is presented as lecture notes with sections and subsections on different C concepts along with examples.
This document provides an introduction to the C programming language. It covers C program structure, variables, expressions, operators, input/output, loops, decision making statements, arrays, strings, functions, pointers, structures, unions, file input/output and dynamic memory allocation. The document uses examples and explanations to introduce basic C syntax and concepts.
C++ hybrid inheritance allows a class to inherit from multiple classes using more than one form of inheritance. This can cause ambiguity if two base classes define a method with the same name. Ambiguity can be resolved by using the class resolution operator (::) to explicitly call the desired method from the specific base class. The example shows a class D inheriting publicly from both classes B and C, which inherit from classes A and C respectively. Class D is then able to access methods from all base classes.
This document contains code snippets in different programming languages like C#, C++, and pseudocode demonstrating basic programming concepts like variables, input/output, conditional statements, and switch/case statements.
The code examples include:
1. C# code to calculate the perimeter of a rectangle by getting user input for the length and multiplying it by itself.
2. C++ code to calculate the 4th power of a number entered by the user.
3. Pseudocode demonstrating a simple if-then conditional statement to check if a student's average is 10 to determine if they get a diploma.
4. Pseudocode showing a switch/case statement to perform different mathematical operations like addition
x = 2 and z = 4. y is calculated using various operations on x and z:
1) y = x++ + ++x evaluates to 6 as x is incremented twice.
2) y = ++x + ++x evaluates to 8 as both x values are pre-incremented.
3) y = ++x + ++x + ++x evaluates to 13 as x is incremented three times.
4) y = x > z evaluates to 0 as the relation x > z is false.
5) y = x > z ? x : z evaluates to 4 as z is chosen by the conditional operator.
6) y = x & z evaluates to 0 as the bitwise
A leader must have strong creative problem-solving skills to anticipate, identify, and address problems in the workplace. Creative problem-solving requires positive communication, respect for all parties, and innovative approaches. When problems arise, effective leaders look ahead to visualize the future and facilitate managed change, rather than just reacting to problems. Good leaders anticipate issues before they occur and seek solutions proactively. The qualities of strong problem solvers include anticipating problems, accepting problems honestly to move forward, seeing the big picture, and handling one problem at a time systematically. Leaders should communicate transparently, break down barriers between groups, foster an open-minded culture, and always have a plan of action to address issues strategically.
This document discusses methods for summarizing data, including frequency distributions, measures of central tendency, and measures of dispersion. It provides examples and formulas for constructing frequency distributions and calculating the mean, median, mode, range, variance, and standard deviation. Key points covered include using frequency distributions to group data, calculating central tendency measures for grouped data, and methods for measuring dispersion both for raw data and grouped data.
This document discusses delegates, lambda expressions, and events in C#. It covers:
- Delegates allow methods to be passed as arguments or returned as the value of functions.
- Lambda expressions provide a concise way to write inline anonymous methods for use with delegates.
- Events use delegates to allow classes to notify listeners of events, following a publish/subscribe model. Event publisher classes raise events, while listeners subscribe to events.
The document discusses input and output functions in C programming. It describes getchar() and putchar() for character input/output, printf() and scanf() for formatted input/output, and gets() and puts() for string input/output. It provides examples of using these functions to read input from the keyboard and display output to the screen.
The document discusses pointers in C programming. It begins by explaining how variables are stored in memory with addresses and values. It then introduces pointers as variables that store memory addresses. Examples are given to demonstrate declaring pointer variables and accessing the value at a pointer's address using the dereference operator (*). The document also covers double pointers and passing arguments by value versus by reference. Key topics covered in less than 3 sentences include: pointers store memory addresses, dereferencing a pointer accesses the value at its address, double pointers point to other pointer variables, call by reference passes argument addresses allowing the called function to modify the original variables.
C's character set includes alphabets, digits, special characters, and whitespace characters. Source character set includes these categories which are used to write programs. Execution character set includes escape sequences which are used at runtime and start with backslash. Common escape sequences include newline, tab, carriage return. Variables in C must start with a letter or underscore and can include digits and letters but no special symbols. Variables are declared with a data type and can be initialized. Variables can be local, global, or environment based on their scope. Identifiers name variables and other elements and have similar naming rules as variables. Keywords are predefined words that cannot be used as identifiers.
Chapter 4 : Balagurusamy Programming ANSI in CBUBT
The document contains solutions to programming problems from the book "C Programming: Chapter-4" by E. Balagurusamy. It includes problems on input/output operators like scanf() and printf(), reading and displaying data in various formats, rounding numbers, bar charts, multiplication tables, and formatting output. Each problem has the code snippet to solve it along with sample input/output. The solutions demonstrate proper use of scanf(), printf(), and formatting specifiers to handle different data types and formats.
This chapter discusses fundamental concepts of C programming language and basic input/output functions. It covers C development environment, C program structure including main functions and statements, basic data types, input/output functions like printf and scanf, and common programming errors.
The document describes the basic structure and components of a C program using flowcharts and code examples. It includes 3 key parts:
1. Preprocessor directives like #include that provide header files and libraries.
2. Input/output functions like printf and scanf that allow transferring data to and from the user.
3. Common operators in C like arithmetic, relational, logical, and unary operators and their order of precedence.
The document uses flowcharts and code snippets to demonstrate how these components fit together in a simple C program that takes input from the user and performs calculations.
Classes allow programmers to define custom data types called objects that encapsulate both data and functions that operate on that data. A class defines the form of an object, while an object is an instance of a class. Classes contain private and public members and methods - private members and methods can only be accessed within the class, while public members and methods provide the interface for outside access. Classes provide data hiding, reusability, and changeability in programs. Common C++ classes include strings and file input/output streams.
The document discusses functions in C programming. It defines a function as an independent, reusable block of code that performs a specific task. Functions allow for modularity and code reuse by encapsulating reusable blocks of code. Functions receive parameters, perform operations, and return values. They improve code organization and maintainability.
This document discusses writing a C program to add two matrices using a two-dimensional array. It includes the theory of multi-dimensional arrays in C, a flowchart showing the process of adding matrices, an algorithm describing the steps, sample code to add two 2x2 matrices, example input/output, and concludes by stating the learning outcomes of understanding how to declare and use multi-dimensional arrays to solve problems like adding matrices.
This document contains 24 C++ programs with explanations and sample outputs. The programs cover basic concepts like variable declaration and input/output, conditional statements, loops, functions, arrays and structures. The programs include calculating area and circumference of shapes, finding largest/smallest numbers, checking leap years, calculating electricity bills, compound interest, digit sum, palindrome checking and more. The programs are meant as examples for students to practice and learn C++ programming.
1) The document discusses object-oriented programming (OOPS) concepts in ABAP such as classes, objects, attributes, methods, inheritance, polymorphism, and exceptions.
2) It provides examples of creating local and global classes, defining methods, and handling exceptions.
3) Key aspects covered include defining classes, creating objects, accessing attributes and methods, static and instance methods/attributes, and using constructor methods.
This document discusses C and C++ selection statements including if, if-else, and if-else-if. It provides examples of code using these conditional statements and corresponding flowcharts. It also includes exercises for the reader to complete code snippets and answer questions about the flow of execution through the conditional logic.
This document provides an overview of the C programming language. It covers C fundamentals like data types and operators. It also discusses various control structures like decision making (if-else), loops (for, while, do-while), case control (switch) and functions. Additionally, it explains input/output operations, arrays and string handling in C. The document is presented as lecture notes with sections and subsections on different C concepts along with examples.
This document provides an introduction to the C programming language. It covers C program structure, variables, expressions, operators, input/output, loops, decision making statements, arrays, strings, functions, pointers, structures, unions, file input/output and dynamic memory allocation. The document uses examples and explanations to introduce basic C syntax and concepts.
C++ hybrid inheritance allows a class to inherit from multiple classes using more than one form of inheritance. This can cause ambiguity if two base classes define a method with the same name. Ambiguity can be resolved by using the class resolution operator (::) to explicitly call the desired method from the specific base class. The example shows a class D inheriting publicly from both classes B and C, which inherit from classes A and C respectively. Class D is then able to access methods from all base classes.
This document contains code snippets in different programming languages like C#, C++, and pseudocode demonstrating basic programming concepts like variables, input/output, conditional statements, and switch/case statements.
The code examples include:
1. C# code to calculate the perimeter of a rectangle by getting user input for the length and multiplying it by itself.
2. C++ code to calculate the 4th power of a number entered by the user.
3. Pseudocode demonstrating a simple if-then conditional statement to check if a student's average is 10 to determine if they get a diploma.
4. Pseudocode showing a switch/case statement to perform different mathematical operations like addition
x = 2 and z = 4. y is calculated using various operations on x and z:
1) y = x++ + ++x evaluates to 6 as x is incremented twice.
2) y = ++x + ++x evaluates to 8 as both x values are pre-incremented.
3) y = ++x + ++x + ++x evaluates to 13 as x is incremented three times.
4) y = x > z evaluates to 0 as the relation x > z is false.
5) y = x > z ? x : z evaluates to 4 as z is chosen by the conditional operator.
6) y = x & z evaluates to 0 as the bitwise
A leader must have strong creative problem-solving skills to anticipate, identify, and address problems in the workplace. Creative problem-solving requires positive communication, respect for all parties, and innovative approaches. When problems arise, effective leaders look ahead to visualize the future and facilitate managed change, rather than just reacting to problems. Good leaders anticipate issues before they occur and seek solutions proactively. The qualities of strong problem solvers include anticipating problems, accepting problems honestly to move forward, seeing the big picture, and handling one problem at a time systematically. Leaders should communicate transparently, break down barriers between groups, foster an open-minded culture, and always have a plan of action to address issues strategically.
This document discusses methods for summarizing data, including frequency distributions, measures of central tendency, and measures of dispersion. It provides examples and formulas for constructing frequency distributions and calculating the mean, median, mode, range, variance, and standard deviation. Key points covered include using frequency distributions to group data, calculating central tendency measures for grouped data, and methods for measuring dispersion both for raw data and grouped data.
005 ways to turn challenges into opportunitiesabir hossain
The document provides 3 ways to turn challenges into opportunities: 1) Accept responsibility for your circumstances to gain a sense of control over your life. 2) Use leverage to exert the greatest amount of control with the least amount of effort to avoid negative paths. 3) View challenges as a game by maintaining a positive attitude like those around you in order to see opportunities where others may only see difficulties.
This document provides an introduction to basic statistics concepts. It defines statistics as the science of collecting, organizing, presenting, analyzing, and interpreting numerical data to assist with decision making. Statistics are used widely in fields such as marketing, healthcare, sports, education and more. The document outlines different types of statistics including descriptive statistics, which organize and summarize data, and inferential statistics, which make estimates about populations based on samples. It also defines variables, scales of measurement including nominal, ordinal, interval and ratio scales, and provides examples of each.
The document outlines principles and strategies for managing organizational conflicts. It discusses definitions of conflict, positive aspects of conflict, six steps for conflict resolution, necessary skills like listening and feedback, and strategies for managing conflicts. The document also covers principles of negotiation and effective communication that can aid in resolving conflicts, such as using neutral terms, avoiding absolutes, asking open-ended questions, and active listening.
1. Assess the assignment and needs, communicate regularly with updates, and document the entire process. Break large projects into smaller digestible parts by creating a timeline and checklist.
2. Delegate tasks to others and acknowledge achievements along the way. Periodically reassess goals and the work remaining.
3. Facing challenges with determination and finding solutions requires assessing needs, communicating transparently, and documenting the process to back up any delays in meeting deadlines.
Clear communication is the most important skill for leadership success. Leaders must master both speaking clearly and ensuring their message is understood. The best leaders are strong communicators - they motivate teams through clear communication, promote strategic alignment through clear communication, and have clear, solid values they effectively promote. To communicate clearly, leaders must realize communication is two-way and focus on listening to ensure understanding. They should also use communication to build relationships between people. Vocal expressiveness through control of pitch, loudness, rhythm, and quality can make even an ordinary voice a powerful persuasive tool.
The document discusses the differences between leadership and management. It notes that leaders develop visions and drive change, while managers monitor progress and solve problems. It then discusses the importance of vision for leadership, stating that vision sees what must happen in the future, inspires others, provides clarity, and generates supportive actions. Finally, it lists five characteristics of a leader: challenging the process, inspiring a shared vision, enabling others to act, modeling the way, and encouraging the heart.
1) The document discusses statistical inference and hypothesis testing. It covers topics like point and interval estimation, confidence intervals, hypothesis testing steps and terminology, tests for population means and proportions, and chi-square tests for independence.
2) An example calculates a 95% confidence interval for the mean hours students work per week based on sample data.
3) The final section discusses contingency tables and chi-square tests, providing an example to test if hand dominance and gender are associated using a contingency table. It shows calculating expected frequencies and the chi-square test statistic to evaluate the null hypothesis of independence.
The document discusses data manipulation and management. It covers arithmetic operations that can be used in transformation expressions like addition, subtraction, multiplication and division. It also discusses relational operators like equal, not equal, less than, greater than that can be used to compare values. Finally, it provides examples of the COMPUTE and RECODE commands that can be used for data manipulation tasks like creating new variables from expressions, recoding values into categories.
This document provides a table of contents and overview of useful ABAP transactions, programs, functions, and topics for ABAP programming. It covers transactions and tools for EDI, IDoc, message control, sales, reports, object programming, file processing, and more. The document serves as a reference guide for SAP developers.
This document discusses correlation and regression analysis. It defines correlation as a statistical technique used to measure the relationship between two variables. Regression analysis develops an equation to express this relationship and can be used to predict the value of one variable based on the other. The key outputs of regression analysis are the regression line equation, the coefficient of determination (R2), and the correlation coefficient (r). R2 indicates what proportion of the variation in the dependent variable is explained by the independent variable.
This very short document discusses fashion illustration but provides no other details in just one word "Fashion" and "Illustration". It does not contain enough contextual information to generate a meaningful 3 sentence summary.
This document discusses various training methods that can be used to engage learners, including case studies, role playing, demonstrations, and group discussions. It provides details on how to develop and structure case studies and role plays. Case studies focus on realistic scenarios and problems to reinforce learning, while role plays allow participants to explore situations by taking on different roles. Demonstrations allow the trainer to show participants how to do something. Other discussed methods include brainstorming, lectures, and structured exercises to provide learning content and keep participants involved.
This document provides guidance on skills training for effective presentations. It covers several key areas:
1. Proper preparation including knowledge of the company, product, and marketing plan. Practice is encouraged.
2. Goals of the presentation including enlightening the audience without data, encouraging them with data but no desire, and enlisting them to take action.
3. Appearance guidelines for both men and women presenters including dress, accessories, makeup, and hair.
4. Effective presentation techniques including considering the audience, using an engaging introduction and conclusion, maintaining interest, involving the audience, and using visual aids and gestures.
The document provides tips for creating effective PowerPoint presentations. Some key points include:
- Use PowerPoint to interact with your audience and keep them engaged rather than just presenting slides of information.
- Choose a light text on dark background color scheme and only change colors on certain emphasis slides. Limit colors to those associated with your business.
- Include no more than 5 bullet points per slide and never read directly from slides. Use clip art sparingly to enhance points without needing explanation.
- Customize backgrounds and use animation, sounds, and transitions sparingly. Ensure readability of text on slides with font size, style and sufficient contrast with backgrounds.
The document outlines the process of training which includes 4 phases: pre-training, training, post-training, and follow up. Pre-training involves identifying trainees, assessing needs, setting objectives, and developing content and materials. Training consists of implementing the program and evaluating learning before, during, and after. Post-training success depends on follow up, which is often overlooked but critical to the training cycle.
The document provides dos and don'ts for trainers during learning sessions. It recommends that trainers maintain eye contact, prepare in advance, involve participants, use visual aids, speak clearly and loudly, encourage questions, recap sessions, bridge topics, encourage participation, write clearly, summarize, use logical sequencing, manage time well, keep things simple, give feedback, position visuals so all can see, avoid distractions, be aware of body language, keep the group focused and provide clear instructions. It also advises trainers to not talk only to the flipchart, block visual aids, stand in one spot, ignore comments and feedback or read directly from the curriculum.
This document contains 23 exercises related to Java programming. The exercises cover a range of topics including sorting and filtering lists, working with maps and sets, implementing classes and interfaces, inheritance and polymorphism using abstract classes and interfaces, and working with enums. The goal of the exercises is to practice and demonstrate skills in object-oriented programming concepts in Java.
Progamming Primer Polymorphism (Method Overloading) VBsunmitraeducation
This document provides guidance on creating a program to demonstrate method overloading in Visual Basic. It instructs the reader to create a class called My_Class with three overloaded methods called MyMethod that take different parameters. It then shows code for an event handler that creates an instance of My_Class and calls each MyMethod, displaying the output in labels. The document demonstrates how overloading allows multiple methods to have the same name but act differently based on their parameters. It also provides examples of errors that can occur if the Overloads keyword is missing or methods have identical signatures.
The document discusses various techniques for refactoring code to improve generalization through inheritance hierarchies. It describes techniques such as push down/pull up field, push down/pull up method, extract subclass, extract superclass, replace inheritance with delegation, and replace delegation with inheritance. The goal is to organize and structure code to make inheritance relationships clearer and eliminate unnecessary inheritance.
This document provides class notes on object-oriented programming concepts like inheritance, packages, and interfaces. It covers topics like method overloading, objects as parameters, returning objects, static and nested classes, inheritance basics, method overriding, abstract classes, packages, and interfaces. The document is organized into sections on each topic with examples provided. It also includes indexes listing the topics covered and their importance levels. The material is intended to complement personalized learning materials and assessment tests for students.
OOP stands for Object-Oriented Programming. It involves creating objects that contain both data and methods. Classes act as templates for objects and define their attributes and behaviors. Some advantages of OOP include reusability, organization, and reduced repetition of code. Classes contain fields to store data and methods to perform actions on that data. Objects are instances of classes that inherit all fields and methods. Constructors initialize objects and can set initial field values. Arrays can store multiple objects. Dynamic arrays allow adding elements at runtime. Partial classes allow splitting a class definition across multiple files.
Lab11bRevf.doc
Lab 11b: Alien Invasion
CS 122 • 15 Points Total
Objectives
· Integrate all the functions you implemented in part a into the final working program.
About
In most situations, you will want to implement a series of separate functions, where each function accomplishes a single task. You will then integrate those functions to make a working program. Though you may not have noticed, the skeleton code for past assignments often do this.
In part 11a, you implemented a set of functions. Now you will put them all together to make a working alien attack simulation. Pre-lab 11b must be completed before beginning this lab in order to ensure that your code is working properly.
Assignment
Recall your assignment from last lab:
Your assignment is based on the following scenario: suppose you're working for ACME Space Defense, and the central project that the company is working on is a ray-gun defense system to shoot down incoming alien invaders. A prototype has been created, but desperately needs to be tested in simulation to avoid a complete disaster when it is actually built and tested in real life
Implementation
Download the Lab11.m file and move it into your Lab11a folder. Open it up and cd into your cs122 directory. You will most likely need to add the Lab11a folder to the path again.
Inside Lab11.m, you will see a series of comments outlining the algorithm to be implemented. It can be summarized as follows:
1) Print out a message to welcome the user.
2) Use getValue() to ask the user to enter the number of simulations to run. This number should be between 25 and 5000. Make sure you store the output in a variable named num_sim.
3) Use the input function to ask the user to enter the number of alien attackers. Store in a variable named a_rate.
4) Use getValue() to ask the user to enter the percent variance of attackers. This value should be between 5 and 95. Store in a variable named var.
5) Use getFile() to get an acceptable filename. Store this in a variable named filename.
6) Use calcBounds() to calculate the upper and lower bounds of the attack rate. Pass a_rate and var as arguments to calcBounds(). Remember that calcBounds() has two return values.
7) Use writeFile() to write num_sim amount of random numbers between the lower and upper bounds calculated in step 6. Remember to also pass it the filename!
8) Print out a message that tells the user that the data has been written and tells the user the name of the file where the data can be found.
9) Load the data using the load() function with filename as the argument. The return value should be called data.
10) Calculate the mean, max, min, standard deviation and the number of data points. Be sure to store them in the correct variables (d_mean, d_max, d_min, d_std, d_size). You can use built-in functions (mean(), max(), min(), std(), and length()) to calculate the values.
11) Print your results from step 10.
12) Plot the data points with the plot function.
Once you have completed ...
This document provides an overview of object-oriented programming concepts in ABAP, including:
- Defining classes in ABAP with attributes and methods
- Creating objects from classes and assigning references
- Using constructors to initialize objects
- Inheritance relationships between classes
It discusses these concepts over the course of several examples written in ABAP code.
This document describes Assignment 2A for the CS193P class. It involves creating a custom PolygonShape class in Objective-C with properties like number of sides and angles. Students will define the class, add properties, and write methods to initialize, describe, and deallocate polygon objects. They will then create several polygon objects with different properties, add them to an array, test property constraints, and verify the objects are properly deallocated. The goal is to practice using custom classes and memory management in Objective-C.
Problem solving using computers - Chapter 1 To Sum It Up
The document discusses problem solving using computers. It begins with an introduction to problem solving, noting that writing a program involves writing instructions to solve a problem using a computer as a tool. It then outlines the typical steps in problem solving: defining the problem, analyzing it, coding a solution, debugging/testing, documenting, and developing an algorithm or approach. The document also discusses key concepts like algorithms, properties of algorithms, flowcharts, pseudocode, and complexity analysis. It provides examples of different algorithm types like brute force, recursive, greedy, and dynamic programming.
The document presents information about functions in the C programming language. It discusses what a C function is, the different types of C functions including library functions and user-defined functions. It provides examples of how to declare, define, call and pass arguments to C functions. Key points covered include how functions allow dividing a large program into smaller subprograms, the ability to call functions multiple times, and how functions improve readability, debugging and reusability of code. An example program demonstrates a simple C function that calculates the square of a number.
This document discusses advanced object-oriented programming concepts in ASP.NET such as classes, inheritance, polymorphism, and interfaces. It also covers multithreaded programming concepts like thread synchronization using events. Interfaces are defined as specifications for members without implementation. Polymorphism allows invoking derived class methods through base class references. Thread synchronization coordinates threads accessing shared data using methods like IsAlive(). Events are signals that classes can raise to be handled by other code.
Diving in OOP (Day 2): Polymorphism and Inheritance (Inheritance)Akhil Mittal
ClassA inherits from ClassB, allowing ClassA to access methods and properties defined in ClassB like Display1(). Defining a method in ClassA with the same name as one in ClassB will override and hide the base method, unless base is used to explicitly call the base method. Inheritance does not work backwards - a base class does not have access to methods defined in a derived class.
An abstract class in C# is defined using the "abstract" keyword. It can contain abstract and non-abstract methods and properties. Abstract classes cannot be instantiated but can be implemented by child classes. Abstract methods in an abstract class are declared using the "abstract" keyword but provide no implementation, while non-abstract methods do provide implementation. Child classes that inherit from an abstract class must override the abstract methods to provide an implementation. Interfaces in C# declare signatures for methods, properties, events and delegates but provide no implementation, which is instead provided by classes that implement the interface.
C++ is computer programming language.It is very important computer programming language.C++ is easy to understand but it need a lot practice and hardworking.Classes and Objects are the most important topics in C++ and it is necessary to understand it.Similarly the use of Constructors is also very important to understand to learn C++These are descriptive and easy slides about Classes in C++.By studying these slides I strongly believe that you can clear your concepts.If you are in doubt and uncleared about Classes in C++ ,then you are at the right place.Read the whole slides and make your concepts clear.
The document discusses modularization in ABAP including subroutine calls, passing parameters, function modules, function groups, and the CATCH statement. It provides examples of calling subroutines, passing different types of parameters, defining and calling function modules and groups, and using the CATCH statement to handle exceptions.
C# classes allow for modularity, data encapsulation, inheritance, and polymorphism. They act as blueprints for generating object instances. The document discusses key object-oriented programming concepts in C# like encapsulation, inheritance, polymorphism, casting, exception handling, garbage collection, interfaces, collections, comparables, and delegates. It provides examples to illustrate concepts like shallow cloning using ICloneable, implementing IComparable, overloading operators, and using XML documentation comments.
A class is a template that defines the form of an object. It specifies both the data and code that will operate on that data. Objects are instances of classes. The data and code that constitute a class are called members or instance variables. A class definition creates a new data type. Objects are created using the new operator, which dynamically allocates memory and returns a reference to the new object. Constructors initialize objects when they are created and can be used to assign initial values to data members. Methods manipulate the data defined by the class and can accept parameters. The garbage collector automatically reclaims memory occupied by objects no longer being used to prevent memory leaks.
This document provides guidance on a programming primer for encapsulation and abstraction using VB in ASP.NET. It discusses creating an Employee class with private member variables for ID and salary, along with public properties to access these privately. The example shows how to set property values and output them, demonstrating encapsulation. It also explains how abstraction relates to classes representing conceptual models without physical form. The document concludes with exercises on using different access modifiers like private, public, and protected.
The document discusses various C# object-oriented programming concepts including classes, structs, class members, passing values by value and reference, method overloading, constructors, static constructors, read-only fields, partial classes, static classes, and the Object class. It provides examples of declaring classes and structs, defining class members like fields, properties, methods, and constructors. It also covers passing parameters, calling constructors from other constructors, readonly fields, and anonymous types.
Leveraging Generative AI to Drive Nonprofit InnovationTechSoup
In this webinar, participants learned how to utilize Generative AI to streamline operations and elevate member engagement. Amazon Web Service experts provided a customer specific use cases and dived into low/no-code tools that are quick and easy to deploy through Amazon Web Service (AWS.)
A Visual Guide to 1 Samuel | A Tale of Two HeartsSteve Thomason
These slides walk through the story of 1 Samuel. Samuel is the last judge of Israel. The people reject God and want a king. Saul is anointed as the first king, but he is not a good king. David, the shepherd boy is anointed and Saul is envious of him. David shows honor while Saul continues to self destruct.
Elevate Your Nonprofit's Online Presence_ A Guide to Effective SEO Strategies...TechSoup
Whether you're new to SEO or looking to refine your existing strategies, this webinar will provide you with actionable insights and practical tips to elevate your nonprofit's online presence.
Temple of Asclepius in Thrace. Excavation resultsKrassimira Luka
The temple and the sanctuary around were dedicated to Asklepios Zmidrenus. This name has been known since 1875 when an inscription dedicated to him was discovered in Rome. The inscription is dated in 227 AD and was left by soldiers originating from the city of Philippopolis (modern Plovdiv).
Level 3 NCEA - NZ: A Nation In the Making 1872 - 1900 SML.pptHenry Hollis
The History of NZ 1870-1900.
Making of a Nation.
From the NZ Wars to Liberals,
Richard Seddon, George Grey,
Social Laboratory, New Zealand,
Confiscations, Kotahitanga, Kingitanga, Parliament, Suffrage, Repudiation, Economic Change, Agriculture, Gold Mining, Timber, Flax, Sheep, Dairying,
Beyond Degrees - Empowering the Workforce in the Context of Skills-First.pptxEduSkills OECD
Iván Bornacelly, Policy Analyst at the OECD Centre for Skills, OECD, presents at the webinar 'Tackling job market gaps with a skills-first approach' on 12 June 2024
2. 1 | P a g e S a n t o s h P
VINAYAKA
Features Of OOPS: -
1) Encapsulation
2) Data Abstraction
3) Inheritance
4) Polymorphism
Application Of OOPS: -
1) BAPI’S
2) BADI’S
3) Enhancement Frame Work
4) Webdynpro
5) HR-ABAP
6) CRM-Technical
7) SRM
8) EP
9) BSP……………
Class: - A class is a user defined data type which is the collection of different type of components.
A class only provides a template it’s doesn’t allocate a memory.
Object: - An instance of a class is called as an object.
Whenever we instance a class memory will be allocated.
Access Specifies (Visibility Section): -
Types Of Class: -
1) Local Class Local class to program (SE38-ABAP Editor).
2) Global Class Class Builder Tool (SE24).
Syntax for creating local classes: -
1) Definition of class Declaration of components.
2) Implementation of class Implementation of method.
3. 2 | P a g e S a n t o s h P
Definition of class
Class <class name> definition.
Declaration of components.
Endclass.
Implementation class
Class <class name> implementation.
Implementation of methods.
Endclass.
Object Creation: -
1) Create reference for the class
Syntax: -
Data <ref.name> type ref to <class name>
Note: - Whenever an Object is created memory will be allocated for the attributes of the class and
attribute gets initialized to default values.
Access specifiers in ABAP: -
1) Public Section
2) Protected Section
3) Private Section
Components of ABAP classes: -
Attributes Methods Events Interface aliases
Types Constants Data Special Normal Instance Static
Instance Instance
Constructor
Instance Static
Static Static
Constructor
4. 3 | P a g e S a n t o s h P
1) OOPS Concepts
2) ALV Reporting Using Class
3) ALV Reporting Using Function Modules
Procedure for creating global classes: -
1) Define and implement the class in class builder tool (SE24).
2) Access the components of the global class in the repository objects (Executable Programs,
Include Program, and Subroutine Pool). By instantiating the class.
Z915AM_OOPS1: (LOCAL CLASS)
REPORT Z915AM_OOPS1.
CLASS EMP DEFINITION.
PUBLIC SECTION.
DATA EMPNO TYPE I. "instance attribute
DATA ENAME(20) TYPE C. "instance attribute
ENDCLASS. "emp DEFINITION
DATA K TYPE REF TO EMP.
CREATE OBJECT K.
WRITE :/ K->EMPNO,
K->ENAME.
K->EMPNO = 1.
K->ENAME = 'abc'.
WRITE:/ K->EMPNO,
K->ENAME.
OUTPUT:
At any point of time they object store one set of values.
Note: - Only public component can be accessed outside of the class.
5. 4 | P a g e S a n t o s h P
Z915AM_CLASS1: (GLOBAL CLASS) SE24:
Z915AM_OOPS2:
REPORT Z915AM_OOPS2.
data m type ref to z915am_class1.
CREATE OBJECT m.
write :/ m->empno,
m->ename.
OUTPUT:
6. 5 | P a g e S a n t o s h P
Interacting with methods in local classes: -
1) Declare the method prototype in the class definition.
Syntax: -
Method/Class-Method <method name> [parameters].
2) Implement the method in the class implementation.
Syntax: -
Method <method name>.
Statements.
Endmethod.
3) Call the method.
Syntax: -
Call method <method name> [parameters]
Instance method methods
Static method class-methods
It is recommend to use in the SAP attributes/data members/Instance variables protected/private.
Method’s/member function public.
Note: - Whenever a report program contains class implementation and explicitly we need handle
the event start-of-selection to indicate the starting point of program.
Z915AM_OOPS3:
REPORT Z915AM_OOPS3.
class abc definition.
public section.
methods : m1,
m2.
protected section.
data : empno type i,
ename(20) type c.
endclass.
class abc implementation.
method m1.
empno = 1.
ename = 'xyz'.
endmethod.
method m2.
write :/ empno,
ename.
endmethod.
endclass.
start-of-selection.
data k type ref to abc.
create object k.
call method k->m2.
7. 6 | P a g e S a n t o s h P
k->m1( ).
k->m2( ).
OUTPUT:
Method with parameters: -
Methods: m1 importing X type i,
Y(20) type c.
Methods returning values: -
Returning Keyword: -
In case of other object oriented language a method can return exactly one value which
done by using return keyword.
In case of ABAP a method can return any number of values by declaring those many
number o exporting (or) importing (or) changing parameters.
To receive a method a return exactly one value we use returning parameters.
It the method contains returning parameters it cannot contains exporting (or) changing
parameters.
A method can contains only one returning parameter.
Returning parameter are always passed by value.
Z915AM_OOPS4:
REPORT Z915AM_OOPS4.
class abc definition.
public section.
methods : m1 importing x type i optional
y type c optional,
m2.
8. 7 | P a g e S a n t o s h P
protected section.
data : empno type i,
ename(20) type c.
endclass.
class abc implementation.
method m1.
empno = x.
ename = y.
endmethod.
method m2.
write :/ empno,
ename.
endmethod.
endclass.
start-of-selection.
data k type ref to abc.
create object k.
parameters : p_x type i,
p_y(20) type c.
call method k->m1
exporting
x = p_x
y = p_y.
call method k->m2.
OUTPUT:
9. 8 | P a g e S a n t o s h P
Z915AM_CLASS2:
method M1.
empno = x.
ename = y.
call method m2.
endmethod.
method M2.
write :/ empno,
ename.
endmethod.
10. 9 | P a g e S a n t o s h P
Z915AM_OOPS5:
REPORT Z915AM_OOPS5.
data k type ref to z915am_class2.
CREATE OBJECT k.
parameters : p_x type i,
p_y(20) type c.
CALL METHOD k->m1
EXPORTING
X = p_x
Y = p_y.
OUTPUT:
Z915AM_OOPS6:
REPORT Z915AM_OOPS6.
class abc definition.
public section.
methods m1 importing x type i
y type i
exporting m type i
n type i.
endclass.
class abc implementation.
method m1.
m = x + y.
n = x - y.
endmethod.
11. 10 | P a g e S a n t o s h P
endclass.
start-of-selection.
data k type ref to abc.
create object k.
data : lv_r1 type i,
lv_r2 type i.
call method k->m1
exporting
x = 200
y = 100
importing
m = lv_r1
n = lv_r2.
write :/ lv_r1,lv_r2.
OUTPUT:
Z915AM_OOPS7:
REPORT Z915AM_OOPS7.
class abc definition.
public section.
methods m1 importing x type i
y type i
returning value(z) type i.
endclass.
class abc implementation.
method m1.
z = x + y.
endmethod.
endclass.
start-of-selection.
data ob type ref to abc.
create object ob.
parameters : p_x type i,
12. 11 | P a g e S a n t o s h P
p_y type i.
data lv_z type i.
lv_z = ob->m1( x = p_x y = p_y ).
write :/ lv_z.
OUTPUT:
Exception handling in methods: -
An exception is runtime error which is raised during the program execution if the
exception is not handling the program will be terminated.
Exception handling is process of handling in runtime error and containing program
execution.
The exceptions are provided by SAP as part of standard exceptions class these exceptions
are triggered by SAP itself as a developer we need to handle these exceptions by using try
and catch block.
Inside try block we need to declare this statement where the possible exception occurs.
It the exception is raised in try blocked SAP creates the appropriate exception class object
and the control is transfer to catch block.
Inside the catch block we need to handle the exception by writing the appropriate
exception handling statements.
All the exception classes provided by SAP start with the naming standard
‘CX_SY_...........’
13. 12 | P a g e S a n t o s h P
Note: - As part of catch block declaration we need to specify the exception class which is
reasonable for rising exception if the developer is not sure of the exception class we can use the
exception class ‘CX_ROOT’.
CX_ROOT is a super class for all the exception classes and it can handle any kind of
exception.
Z915AM_OOPS8:
REPORT Z915AM_OOPS8.
class abc definition.
public section.
methods m1 importing x type i
y type i
exporting z type i.
endclass.
class abc implementation.
method m1.
try.
z = x / y.
* catch cx_sy_zerodivide.
catch cx_root.
write :/ 'Cannot divide by zero'.
endtry.
endmethod.
endclass.
start-of-selection.
data ob type ref to abc.
create object ob.
data lv_z type i.
call method ob->m1
exporting
x = 10
y = 0
importing
z = lv_z.
write :/ 'Diviison is ',lv_z.
write :/ 'end of program'.
14. 13 | P a g e S a n t o s h P
OUTPUT:
Z915AM_OOPS9:
REPORT Z915AM_OOPS9.
DATA K TYPE REF TO CX_SY_ZERODIVIDE.
DATA STR TYPE STRING.
DATA : PRGNAME TYPE SY-REPID,
INCNAME TYPE SY-REPID,
POS TYPE I.
CLASS ABC DEFINITION.
PUBLIC SECTION.
METHODS M1 IMPORTING X TYPE I
Y TYPE I
EXPORTING Z TYPE I.
ENDCLASS. "abc DEFINITION
CLASS ABC IMPLEMENTATION.
METHOD M1.
TRY.
Z = X / Y.
CATCH CX_SY_ZERODIVIDE INTO K.
CALL METHOD K->IF_MESSAGE~GET_TEXT
RECEIVING
RESULT = STR.
WRITE :/ 'short text is ',STR.
CLEAR STR.
CALL METHOD K->IF_MESSAGE~GET_LONGTEXT
RECEIVING
RESULT = STR.
WRITE :/ 'Long text is ',STR.
CALL METHOD K->GET_SOURCE_POSITION
IMPORTING
15. 14 | P a g e S a n t o s h P
PROGRAM_NAME = PRGNAME
INCLUDE_NAME = INCNAME
SOURCE_LINE = POS.
WRITE :/ 'Program name :',PRGNAME,
/ 'Include name :',INCNAME,
/ 'line no :',POS.
ENDTRY.
ENDMETHOD. "m1
ENDCLASS. "abc IMPLEMENTATION
START-OF-SELECTION.
DATA OB TYPE REF TO ABC.
CREATE OBJECT OB.
DATA LV_Z TYPE I.
CALL METHOD OB->M1
EXPORTING
X = 10
Y = 0
IMPORTING
Z = LV_Z.
WRITE :/ 'Diviison is ',LV_Z.
WRITE :/ 'end of program'.
OUTPUT:
CX_SY_ZERODIVIDE:
16. 15 | P a g e S a n t o s h P
Capturing system defined exception message: -
Procedure for handling standing exception: -
These exception are declared and raised SAP as a developer we need to handle try and catch.
User defines exception: -
These exceptions are declaring and handle are raised developers itself.
Procedure for handling user-define exception in local classes: -
1) Declare the user define exception as part of method declaration.
Syntax: -
Exception <exception name>
2) Raise the exception at appropriate place in the method implementation
Raise <exception name>
3) Handle the exception while calling the method by checking sy-subrc status.
Z915AM_OOPS10:
REPORT Z915AM_OOPS10.
class abc definition.
public section.
methods m1 importing x type i
y type i
exporting z type i
exceptions divideerror.
endclass.
class abc implementation.
method m1.
if y eq 0.
raise divideerror.
else.
z = x / y.
endif.
endmethod.
endclass.
start-of-selection.
data ob type ref to abc.
create object ob.
data lv_z type i.
call method ob->m1
exporting
17. 16 | P a g e S a n t o s h P
x = 10
y = 0
importing
z = lv_z
exceptions
divideerror = 1
others = 2.
if sy-subrc eq 0.
write :/ 'division is ',lv_z.
elseif sy-subrc eq 1.
write :/ 'Cannot divide by zero'.
elseif sy-subrc eq 2.
write :/ 'Unknown error'.
endif.
OUTPUT:
Z915AM_CLASS3:
method M1.
if y eq 0.
raise divideerror.
18. 17 | P a g e S a n t o s h P
else.
z = x / y.
endif.
endmethod.
Z915AM_OOPS11:
REPORT Z915AM_OOPS11.
data lv_z type i.
data ob type ref to z915am_class3.
create object ob.
CALL METHOD ob->m1
EXPORTING
x = 10
y = 0
IMPORTING
Z = lv_z
EXCEPTIONS
DIVIDEERROR = 11
others = 22.
if sy-subrc eq 0.
write :/ lv_z.
elseif sy-subrc eq 11.
message 'Cannot divide by zero' type 'I'.
elseif sy-subrc eq 22.
message 'Unknown error' type 'I'.
endif.
OUTPUT:
19. 18 | P a g e S a n t o s h P
Instance attribute: -
These attribute are specific to an object and they are declared by using the keyword data
in local classes.
For each instance attribute separate memory will be allocated they can be an accessed
only by using the object of the class.
Static attribute: -
They are not specific to any object and they are declared by using the keyword
‘CLASS_DATA’ in local classes.
For the static attribute memory will be allocated only when the first object is created the
remaining objects points to be same memory location they are also called as class
variables.
They can be accessed either by using the object are by using the class name.
Instance methods: -
In local classes they are declared by using the keyword methods they can be accessed only by
using the object. They can access both instance and static attributes.
Static methods: -
In local class they are declaring the keyword ‘CLASS-METHOD’ in the local classes they
can be accessed either by using object are by using class name. They access only static attributes.
Z915AM_OOPS12:
REPORT Z915AM_OOPS12.
class abc definition.
public section.
data x type i. "instance attribute
class-data y type i. "static attribute
endclass.
start-of-selection.
data ob1 type ref to abc.
create object ob1.
write :/ 'Values of object ob1'.
write :/ ob1->x,
ob1->y,
abc=>y.
ob1->x = 10.
ob1->y = 20.
write :/ 'Values of object ob1'.
write :/ ob1->x,
20. 19 | P a g e S a n t o s h P
ob1->y.
data ob2 type ref to abc.
create object ob2.
write :/ 'Values of object ob2'.
write :/ ob2->x,
ob2->y.
OUTPUT:
Z915AM_OOPS13:
REPORT Z915AM_OOPS13.
class abc definition.
public section.
methods m1.
class-methods m2.
protected section.
data x type i.
class-data y type i.
endclass.
class abc implementation.
method m1.
x = 10.
y = 20.
WRITE : x.
endmethod.
method m2.
y = 20.
* x = 10.
write: y.
endmethod.
endclass.
21. 20 | P a g e S a n t o s h P
start-of-selection.
call method abc=>m2.
abc=>m2( ).
*abc=>m1( ).
OUTPUT:
Constructors: -
A constructor is a special method used for initialized for attributes of class it special because
it cannot be called explicitly it will be called implicitly.
It is always declare in public section.
It never returns any values.
1) Instance
2) Static
Instance Constructors: - It is declared by using keyword constructor it is executed automatically
whenever we create new instance of a class. It is specific to object.
It can contain only importing parameters and exceptions.
Static Constructors: - It is declared by using the keyword ‘CLASS_CONSTRUCTORS’ it is
executed automatically whenever a class is loaded a class will be loaded in cases.
1) When we accesses the static components of the class using the class name before creating any
objects.
2) When we create the first object of the class.
3) It is not specific to any object it cannot contains any parameters and exception.
Note: -
Instance constructor is executed only once in the life time of object.
Static constructor is executed only once in a life time of class.
22. 21 | P a g e S a n t o s h P
Z915AM_OOPS14:
REPORT Z915AM_OOPS14.
class abc definition.
public section.
methods : constructor,
m2.
protected section.
data : empno type i, "INATANCE ATTRI"
ename(20) type c.
endclass.
class abc implementation.
method constructor.
empno = 1.
ename = 'abc'.
endmethod.
method m2.
write :/ empno,ename.
endmethod.
endclass.
start-of-selection.
* data ob type ref to abc.
* create object ob.
*
*call method ob->constructor. " u cannot specify constructor directly.
*call method ob->m2.
*call method ob->m2.
data ob1 type ref to abc.
create object ob1.
call method ob1->m2.
OUTPUT:
23. 22 | P a g e S a n t o s h P
Z915AM_OOPS15:
REPORT Z915AM_OOPS15.
class abc definition.
public section.
methods : constructor importing x type i optional
y type c optional,
display.
protected section.
data : empno type i,
ename(20) type c.
endclass.
class abc implementation.
method constructor.
empno = x.
ename = y.
endmethod.
method display.
write :/ empno,ename.
endmethod.
endclass.
start-of-selection.
parameters : p_x type i,
p_y(20) type c.
data ob type ref to abc.
create object ob
exporting
x = p_x
y = p_y.
call method ob->display.
OUTPUT:
24. 23 | P a g e S a n t o s h P
Z915AM_OOPS16:
REPORT Z915AM_OOPS16.
class abc definition.
public section.
methods constructor.
class-methods class_constructor.
endclass.
class abc implementation.
method constructor.
write :/ 'inside instance const'.
endmethod.
method class_constructor.
write :/ 'inside static const'.
endmethod.
endclass.
start-of-selection.
data ob1 type ref to abc.
create object ob1.
write :/ 'Second object.........'.
data ob2 type ref to abc.
create object ob2.
OUTPUT:
Note: - If a class contains both instance and static constructor and when we create the first object.
1st
the static constructor is executed and next instance constructor for rest of the objects only
instance constructor get executed.
25. 24 | P a g e S a n t o s h P
Z915AM_OOPS15:
REPORT Z915AM_OOPS15.
class abc definition.
public section.
methods : constructor importing x type i optional
y type c optional,
display.
protected section.
data : empno type i,
ename(20) type c.
endclass.
class abc implementation.
method constructor.
empno = x.
ename = y.
endmethod.
method display.
write :/ empno,ename.
endmethod.
endclass.
start-of-selection.
parameters : p_x type i,
p_y(20) type c.
data ob type ref to abc.
create object ob
exporting
x = p_x
y = p_y.
call method ob->display.
OUTPUT:
26. 25 | P a g e S a n t o s h P
Z915AM_OOPS16:
REPORT Z915AM_OOPS16.
class abc definition.
public section.
methods constructor.
class-methods class_constructor.
endclass.
class abc implementation.
method constructor.
write :/ 'inside instance const'.
endmethod.
method class_constructor.
write :/ 'inside static const'.
endmethod.
endclass.
start-of-selection.
data ob1 type ref to abc.
create object ob1.
write :/ 'Second object.........'.
data ob2 type ref to abc.
create object ob2.
OUTPUT:
27. 26 | P a g e S a n t o s h P
Z915AM_OOPS17:
REPORT Z915AM_OOPS17.
class abc definition.
public section.
methods constructor.
class-methods class_constructor.
class-data x type i.
endclass.
class abc implementation.
method constructor.
write :/ 'inside instance const'.
endmethod.
method class_constructor.
write :/ 'inside static const'.
endmethod.
endclass.
start-of-selection.
*abc=>x = 10.
data ob1 type ref to abc.
create object ob1.
OUTPUT:
28. 27 | P a g e S a n t o s h P
NORMAL METHOD SPECIAL METHOD CONSTRUCTOR
It can be declared in any of the sections. Only in public section.
It has to be called explicitly. It called implicitly.
A method can have any type o parameters. Instance constructor can have importing
parameters and static constructor cannot have
any parameters.
Methods can return values. It cannot return values.
It can be called any know of times in the
lifetime of an object.
Instance constructor will be called only once
in the lifetime of every object where as static
constructor will be called only once in the
lifetime of class.
CREATING T-CODE FOR METHOD:
29. 28 | P a g e S a n t o s h P
Z915AM_OOPS18:
REPORT Z915AM_OOPS18.
CLASS ABC DEFINITION.
PUBLIC SECTION.
METHODS M1.
PROTECTED SECTION.
DATA X TYPE I.
ENDCLASS. "abc DEFINITION
CLASS ABC IMPLEMENTATION.
METHOD M1.
BREAK-POINT.
LEAVE TO LIST-PROCESSING.
WRITE :/ 'inside method m1'.
LEAVE SCREEN.
ENDMETHOD. "m1
ENDCLASS. "abc IMPLEMENTATION
CLASS PQR DEFINITION.
PROTECTED SECTION.
DATA : X TYPE I,
Y TYPE I.
ENDCLASS. "pqr DEFINITION
(SETTING BREAK POINT IN PORGRAM FOR OUR UNDERSTANDING)
EXECUTING T-CODE: ZT35
30. 29 | P a g e S a n t o s h P
OUTPUT:
User defined exception: -
Raising: - It a method is a capable of raising the exception that enable to handle the exception then
we need to use the keyword raising as part of method declaration in this case the caller of the
method as to take the responsibility of handling the exception.
Z915AM_OOPS19:
REPORT Z915AM_OOPS19.
class abc definition.
public section.
methods m1 importing x type i
y type i
exporting z type i
raising cx_sy_zerodivide.
endclass.
class abc implementation.
method m1.
z = x / y.
endmethod.
endclass.
start-of-selection.
data ob type ref to abc.
create object ob.
data r type i.
try.
call method ob->m1
exporting
x = 10
y = 0
importing
z = r.
catch cx_sy_zerodivide.
message 'Cannot divide by zero' type 'I'.
endtry.
write :/ 'diviison is ',r.
31. 30 | P a g e S a n t o s h P
OUTPUT:
PRESS ENTER:
Z915AM_OOPS20:
REPORT Z915AM_OOPS20.
parameters : p_x type i,
p_y type i.
data z type i.
try.
perform abc using p_x p_y changing z.
catch cx_sy_zerodivide.
write :/ 'Cannot divide by zero'.
endtry.
write :/ 'Diviison is ',z.
form abc using m n changing r
raising cx_sy_zerodivide.
r = m / n.
endform.
OUTPUT:
32. 31 | P a g e S a n t o s h P
Friend classes: - By default outside the class a object can access only public components of the
class directly.
By using friend classes to enable the object to access any components of the class directly
irresponsibility of the visibility for this consider the following session.
Consider two independent classes A and B.
If class A considers class B as friend by inside class B methods we can instantiate class A
and use the instance we can access all the component of class A directly irrespective of
the visibility.
Z915AM_OOPS21:
REPORT Z915AM_OOPS21.
class pqr definition deferred.
class abc definition friends pqr.
public section.
methods m1.
protected section.
methods m2.
private section.
methods m3.
endclass.
class abc implementation.
method m1.
write :/ 'inside public method m1'.
endmethod.
method m2.
write :/ 'inside protected method m2'.
endmethod.
method m3.
write :/ 'inside private method m3'.
endmethod.
endclass.
class pqr definition.
public section.
methods m4.
33. 32 | P a g e S a n t o s h P
endclass.
class pqr implementation.
method m4.
write :/ 'inside m4'.
data ob type ref to abc.
create object ob.
call method : ob->m1.
call method : ob->m2.
call method : ob->m3.
endmethod.
endclass.
start-of-selection.
data k type ref to pqr.
create object k.
call method k->m4.
OUTPUT:
In the above case the class B should be forward declared by using the keyword ‘deferred’.
Deferred keyword indicates to SAP that the class definition has been delayed and it has been
declared same where else in the program.
Z915AM_CLASS4: (GLOBAL FRIEND CLASS)
34. 33 | P a g e S a n t o s h P
method M1.
write :/ 'inside method m1'.
endmethod.
method M2.
write :/ 'inside method m2'.
endmethod.
method M3.
write :/ 'inside method m3'.
endmethod.
Z915AM_CLASS5:
35. 34 | P a g e S a n t o s h P
method M4.
write :/ 'inside m4'.
data ob type ref to z915am_class4.
create object ob.
call method : ob->m1,
ob->m2,
ob->m3.
endmethod.
Z915AM_OOPS22:
REPORT Z915AM_OOPS22.
data ob type ref to z915am_class5.
create object ob.
call method ob->m4.
OUTPUT:
Inheritance: -
It is the process o acquiring the properties of other entity (class). The advantage of
inheritance is reusability. They are three types of inheritance.
1) Single
2) Multiple
3) Multilevel
The class which gives the properties is called as super class are base class and the class
which takes the properties is called as subclass (or) derived class.
36. 35 | P a g e S a n t o s h P
Only public and protected components can be inherited.
In local classes we need to use the keyword inheriting from for achieving inheritance.
1) Single inheritance: -
A class derived from single super class.
2) Multiple inheritance: -
A class derived from more than one super class.
Note: - In ABAP we cannot implement multiple inheritance directly we can implemented indirectly
through the concept of interface.
3) Multilevel inheritance: -
A class derived from another derived class.
Single inheritance
Multilevel inheritance Multiple inheritance
Z915AM_OOPS24:
REPORT Z915AM_OOPS24.
class cycle definition.
public section.
methods : setcycle,
display.
protected section.
data : wheels type i,
brakes type i,
colour(20) type c.
endclass.
class cycle implementation.
method setcycle.
wheels = 2.
brakes = 2.
CLASS A
CLASS B
CLASS A
CLASS C
CLASS A CLASS B
CLASS C
CLASS B
37. 36 | P a g e S a n t o s h P
colour = 'green'.
endmethod.
method display.
write :/ wheels,brakes,colour.
endmethod.
endclass.
class scooter definition inheriting from cycle.
public section.
methods setscooter.
data enginemodel type i.
endclass.
class scooter implementation.
method setscooter.
wheels = 2.
brakes = 4.
colour = 'red'.
endmethod.
endclass.
class car definition inheriting from scooter.
public section.
methods setcar.
endclass.
class car implementation.
method setcar.
wheels = 4.
brakes = 5.
colour = 'blue'.
endmethod.
endclass.
start-of-selection.
data ob1 type ref to cycle.
create object ob1.
write :/ 'CYCLE class..........'.
call method : ob1->setcycle,
ob1->display.
data ob2 type ref to scooter.
create object ob2.
write :/ 'SCOOTER class.........'.
call method : ob2->setscooter,
ob2->display.
data ob3 type ref to car.
38. 37 | P a g e S a n t o s h P
create object ob3.
write :/ 'CAR class.........'.
call method : ob3->setcar,
ob3->display.
OUTPUT:
Z915AMCYCLE:
method SETCYCLE.
wheels = 2.
brakes = 2.
colour = 'blue'.
endmethod.
method DISPLAY.
write :/ wheels,brakes,colour.
endmethod.
39. 38 | P a g e S a n t o s h P
Z915AMSCOOTER:
method SETSCOOTER.
wheels = 2.
brakes = 4.
colour = 'red'.
endmethod.
40. 39 | P a g e S a n t o s h P
Z915AMCAR:
method SETCAR.
wheels = 4.
brakes = 5.
colour = 'cyan'.
endmethod.
41. 40 | P a g e S a n t o s h P
Z915AM_OOPS25:
REPORT Z915AM_OOPS25.
data ob1 type ref to z915amcycle.
create object ob1.
data ob2 type ref to z915amscooter.
create object ob2.
data ob3 type ref to z915amcar.
create object ob3.
call method : ob1->setcycle,
ob1->display,
ob2->setscooter,
ob2->display,
ob3->setcar,
ob3->display.
OUTPUT:
42. 41 | P a g e S a n t o s h P
Z915AM_OOPS26:
REPORT Z915AM_OOPS26.
class abc definition final.
public section.
data x type i.
endclass.
class pqr definition inheriting from abc.
endclass.
OUTPUT:
Polymorphism: -
Poly Many
Morph Forms
Ism behavior
Examples: - Method overloading
Method overriding
Method overloading: -
If a class contains two method with the same name but different signature it is called as
method overloading.
ABAP doesn’t support method overloading.
Z915AM_OOPS27:
REPORT Z915AM_OOPS27.
class abc definition.
public section.
* methods m1.
methods m1 importing x type i.
endclass.
CLASS ABC IMPLEMENTATION.
METHOD M1.
43. 42 | P a g e S a n t o s h P
ENDMETHOD.
ENDCLASS.
method overloading
Z915AM_OOPS28:
REPORT Z915AM_OOPS28.
CLASS ABC DEFINITION.
PUBLIC SECTION.
METHODS M1.
ENDCLASS. "abc DEFINITION
CLASS ABC IMPLEMENTATION.
METHOD M1.
WRITE :/ 'inside m1 of super class'.
ENDMETHOD. "m1
ENDCLASS. "abc IMPLEMENTATION
CLASS PQR DEFINITION INHERITING FROM ABC.
PUBLIC SECTION.
METHODS M1 REDEFINITION.
ENDCLASS. "pqr DEFINITION
CLASS PQR IMPLEMENTATION.
METHOD M1.
WRITE :/ 'inside m1 of sub class'.
CALL METHOD SUPER->M1.
ENDMETHOD. "m1
ENDCLASS. "pqr IMPLEMENTATION
START-OF-SELECTION.
DATA OB TYPE REF TO PQR.
CREATE OBJECT OB.
CALL METHOD OB->m1.
OUTPUT:
44. 43 | P a g e S a n t o s h P
Method overriding: -
If a sub class overwrites a super class method is called as method overriding.
Whenever a sub class wants to override the super class method a sub class wants to
declare the super class method in the subclass by using REDEFINITION keyword.
While redefined the methods we cannot change the visibility of the method.
Whenever a subclass overrides the super class method it is always recommended to call
the super class method version in the subclass by using super keyword.
Super keyword is used for referring to super class components from the sub class.
To redefine a global method put cursor on the method click on redefine.
Z915AM_CLASS6:
method M1.
write :/ 'inside method m1 of super class'.
endmethod.
Z915AM_CLASS7:
45. 44 | P a g e S a n t o s h P
method M1.
write :/ 'inside m1 of subclass'.
CALL METHOD SUPER->M1.
endmethod.
Z915AM_OOPS29:
REPORT Z915AM_OOPS29.
data ob type ref to z915am_class7.
create object ob.
call method ob->m1.
OUTPUT:
Final keyword: -
Final keyword can be used at two levels.
1) Class level
2) Method level
The class created as final cannot be inherited.
A method created as final can be inherited but cannot redefine.
Z915AM_OOPS30:
REPORT Z915AM_OOPS30.
CLASS ABC DEFINITION.
PUBLIC SECTION.
METHODS M1 FINAL.
ENDCLASS. "abc DEFINITION
46. 45 | P a g e S a n t o s h P
CLASS ABC IMPLEMENTATION.
METHOD M1.
WRITE :/ 'inside m1 of super class'.
ENDMETHOD. "m1
ENDCLASS. "abc IMPLEMENTATION
CLASS PQR DEFINITION INHERITING FROM ABC.
PUBLIC SECTION.
METHODS M2.
ENDCLASS. "pqr DEFINITION
CLASS PQR IMPLEMENTATION.
METHOD M2.
WRITE :/ 'inside m2 of sub class'.
CALL METHOD M1.
ENDMETHOD. "m2
ENDCLASS. "pqr IMPLEMENTATION
START-OF-SELECTION.
DATA OB TYPE REF TO PQR.
CREATE OBJECT OB.
CALL METHOD OB->M2.
OUTPUT:
Z915AM_OOPS31:
REPORT Z915AM_OOPS31.
class abc definition.
public section.
methods m1 final.
endclass.
class abc implementation.
method m1.
write :/ 'inside m1 of super class'.
endmethod.
endclass.
47. 46 | P a g e S a n t o s h P
class pqr definition inheriting from abc.
public section.
methods m2.
methods m1 redefinition.
endclass.
class pqr implementation.
method m2.
write :/ 'inside m2'.
call method m1.
endmethod.
endclass.
start-of-selection.
data ob type ref to pqr.
create object ob.
call method ob->m2.
OUTPUT:
Z915AM_OOPS32:
REPORT Z915AM_OOPS32.
class abc definition.
public section.
methods constructor.
class-methods class_constructor.
endclass.
class abc implementation.
method constructor.
write :/ 'inside instance const. of super class'.
endmethod.
method class_constructor.
write :/ 'inside static const. of super class'.
endmethod.
endclass.
class pqr definition inheriting from abc.
public section.
48. 47 | P a g e S a n t o s h P
* methods constructor.
class-methods class_constructor.
endclass.
class pqr implementation.
* method constructor.
* write :/ 'inside instance const. of super class'.
* endmethod.
method class_constructor.
write :/ 'inside static const. of sub class'.
endmethod.
endclass.
start-of-selection.
data ob1 type ref to pqr.
create object ob1.
OUTPUT:
Hierarchy of constructor execution: -
When a super class contains static and instance constructor and id sub class contains only the static
constructor and if sub class contains only the static constructor in this case if we instantiate the sub
class then the static constructor are executed from super class to sub class and then the instantiate
constructor of the super class will be executed.
Z915AM_OOPS33:
REPORT Z915AM_OOPS33.
class abc definition.
public section.
methods constructor.
class-methods class_constructor.
endclass.
class abc implementation.
method constructor.
write :/ 'inside instance const. of super class'.
49. 48 | P a g e S a n t o s h P
endmethod.
method class_constructor.
write :/ 'inside static const. of super class'.
endmethod.
endclass.
class pqr definition inheriting from abc.
public section.
methods constructor.
class-methods class_constructor.
endclass.
class pqr implementation.
method constructor.
write :/ 'inside instance const. of sub class'.
call method super->constructor.
endmethod.
method class_constructor.
write :/ 'inside static const. of sub class'.
endmethod.
endclass.
start-of-selection.
data ob1 type ref to pqr.
create object ob1.
OUTPUT:
Note: - If the super class and sub class contains respective instance constructor it must for subclass
instance constructor to call the super class instance constructor this is done by using super keyword.
This is the only place where the constructor can be are must be called explicitly.
Note: - If the super class and sub class contains respective static and instance constructor and if
instantiate the sub class first the static constructor are executed to super class to subclass and when
the instantiate constructor will executed subclass to super class.
50. 49 | P a g e S a n t o s h P
Me keyword: - Me keyword refer to current object execution it is used to differentiate both
attribute and method parameters whenever attribute and parameter names are same.
Z915AM_OOPS34:
REPORT Z915AM_OOPS34.
class abc definition.
public section.
methods m1 importing x type i
n type i
exporting z type i.
protected section.
data : x type i,
y type i.
endclass.
class abc implementation.
method m1.
me->x = x.
y = n.
z = x + y.
endmethod.
endclass.
start-of-selection.
data ob type ref to abc.
create object ob.
data r type i.
call method ob->m1
exporting
x = 10
n = 20
importing
z = r.
write :/ 'sum is ',r.
OUTPUT:
51. 50 | P a g e S a n t o s h P
Visibility of component level: -
1) Public section
2) Protected section
3) Private section
Visibility of class level: -
1) Public
2) Protected
3) Private
4) Abstract
Public: - The default visibility of a class is public.
Public classes can be instantiated.
Public classes can be inherited.
The sub classes inherited the public class is also created as public by default.
Protected classes: - Protected classes can be inherited but cannot be instantiated outside the class
but it can be instantiated within the sub class method.
The sub class inheriting the protected class is also created as protected by default to create
the sub class as explicit public class we need to use extension create public as part of sub
class definition.
Z915AM_OOPS36:
REPORT Z915AM_OOPS36.
class abc definition create protected.
endclass.
*class pqr definition inheriting from abc.
class pqr definition create public
inheriting from abc.
public section.
methods m1.
endclass.
class pqr implementation.
method m1.
data ob type ref to abc.
create object ob.
endmethod.
endclass.
start-of-selection.
data k type ref to pqr.
create object k.
call method k->m1.
52. 51 | P a g e S a n t o s h P
OUTPUT:
protected classes.
Private classes: -
Private classes cannot be instantiated.
Private classes can be inherited.
The sub class inherited the private class is also created as private class by default.
This sub class cannot be created as explicitly public class this can be mode possible if the
super class considers the subclass as friend.
Z915AM_OOPS37:
REPORT Z915AM_OOPS37.
class abc definition create private.
endclass.
*class pqr definition inheriting from abc.
class pqr definition create public
inheriting from abc.
public section.
methods m1.
endclass.
class pqr implementation.
method m1.
data ob type ref to abc.
create object ob.
endmethod.
endclass.
OUTPUT:
53. 52 | P a g e S a n t o s h P
Z915AM_OOPS38:
REPORT Z915AM_OOPS38.
class pqr definition deferred.
class abc definition create private
friends pqr.
endclass.
class pqr definition create public
inheriting from abc.
endclass.
data ob type ref to pqr.
create object ob.
OUTPUT:
second usage of friend keyword
Abstract class: -
It is a class which contains at least one abstract method. Abstract method is a method
which is just declared but not implemented in local class they are declared by using the
keyword abstract.
It a class contains at least one abstract method then the entity class should be declared as
abstract.
Abstract methods are always declared in public (or) protected section.
We cannot instantiate the abstract classes because they are not fully implemented.
The class which ever inheritance the abstract class can implement the abstract method of
the abstract class otherwise the subclass will declared as abstract.
Abstract methods are also called as non-concerted methods.
We declared method as abstract when we are not sure about the implementation but we
are sure that the other classes as to use the same methods.
Z915AM_OOPS39:
REPORT Z915AM_OOPS39.
CLASS RESTAURANT DEFINITION ABSTRACT.
PUBLIC SECTION.
METHODS : SET,
DISPLAY,
PAYMENT ABSTRACT.
PROTECTED SECTION.
DATA : TABLENO TYPE I,
STEWARD(20) TYPE C.
ENDCLASS. "restaurant DEFINITION
54. 53 | P a g e S a n t o s h P
CLASS RESTAURANT IMPLEMENTATION.
METHOD SET.
TABLENO = 123.
STEWARD = 'abc'.
ENDMETHOD. "set
METHOD DISPLAY.
WRITE :/ TABLENO,STEWARD.
ENDMETHOD. "display
ENDCLASS. "restaurant IMPLEMENTATION
CLASS CHEQUE DEFINITION
INHERITING FROM RESTAURANT.
PUBLIC SECTION.
METHODS PAYMENT REDEFINITION.
PROTECTED SECTION.
DATA : CQNO TYPE I,
BANK(20) TYPE C,
AMT TYPE I.
ENDCLASS. "cheque DEFINITIO
CLASS CHEQUE IMPLEMENTATION.
METHOD PAYMENT.
CQNO = 3444.
BANK = 'xyz'.
AMT = 333.
WRITE :/ CQNO,BANK,AMT.
ENDMETHOD. "payment
ENDCLASS. "cheque IMPLEMENTATION
CLASS CREDITCARD DEFINITION
INHERITING FROM RESTAURANT.
PUBLIC SECTION.
METHODS PAYMENT REDEFINITION.
PROTECTED SECTION.
DATA : CCNO TYPE I,
AMOUNT TYPE I,
BANKNAME(20) TYPE C.
ENDCLASS. "creditcard DEFINITIO
CLASS CREDITCARD IMPLEMENTATION.
METHOD PAYMENT.
CCNO = 455.
AMOUNT = 432.
BANKNAME = 'abc'.
WRITE :/ CCNO,AMOUNT,BANKNAME.
ENDMETHOD. "payment
ENDCLASS. "creditcard IMPLEMENTATION
START-OF-SELECTION.
55. 54 | P a g e S a n t o s h P
DATA R TYPE REF TO RESTAURANT.
DATA CQ TYPE REF TO CHEQUE.
CREATE OBJECT CQ.
WRITE :/ 'CHEQUE class'.
CALL METHOD : CQ->SET,
CQ->DISPLAY,
CQ->PAYMENT.
DATA CC TYPE REF TO CREDITCARD.
CREATE OBJECT CC.
WRITE :/ 'CREDIT CARD class'.
CALL METHOD : CC->SET,
CC->DISPLAY,
CC->PAYMENT.
WRITE :/ 'CHEQUE ----> RESTAURANT'.
R = CQ.
CALL METHOD : R->SET,
R->DISPLAY,
R->PAYMENT.
WRITE :/ 'CREDITCARD ----> RESTAURANT'.
R = CC.
CALL METHOD : R->SET,
R->DISPLAY,
R->PAYMENT.
OUTPUT:
56. 55 | P a g e S a n t o s h P
Z915AM_REST:
method SET.
tableno = 1.
steward = 'abc'.
endmethod.
method DISPLAY.
write :/ tableno,steward.
endmethod.
Z915AM_CHEQUE:
57. 56 | P a g e S a n t o s h P
method PAYMENT.
cqno = 123.
bank = 'yes'.
amount = 455.
write :/ cqno,bank,amount.
endmethod.
Z915AM_OOPS40:
REPORT Z915AM_OOPS40.
data ob type ref to z915am_cheque.
create object ob.
CALL METHOD OB->SET.
CALL METHOD OB->DISPLAY.
CALL METHOD OB->PAYMENT.
OUTPUT:
58. 57 | P a g e S a n t o s h P
Interfaces: - It is pure abstract class i.e. by default all methods of interface are abstract. By using
interfaces we can implement multiple inheritances.
By default the visibility of the interface components are public.
Interface methods contain only declaration but not implementation the implementation
must be provided in the corresponding class. The class whichever implements the
interface is called as implementation class and this class should implement all the
methods of the interface otherwise this class should be declaration as abstract.
A local class whichever wants to implement the interface must declared the interface in
the class definition by using interface keyword.
Syntax: - interface <interface name>.
A class can implement any number of interfaces which is nothing but multiple inheritance
whenever the interface component are referred the outside of the interface they must be prefixed
with the name of the interface.
Interface is always implemented in public section.
We cannot the instantiate the interfaces because it is not implemented.
Syntax for local interfaces: -
Interface <interface name>.
Declaration of components
End interface.
Z915AM_OOPS41:
REPORT Z915AM_OOPS41.
INTERFACE RECTANGLE.
CONSTANTS : LENGTH TYPE I VALUE 10,
BREADTH TYPE I VALUE 5.
METHODS : AREA,
PERIMETER.
ENDINTERFACE. "rectangle
INTERFACE SQUARE.
CONSTANTS SIDE TYPE I VALUE 5.
METHODS : AREA,
PERIMETER.
ENDINTERFACE. "square
CLASS ABC DEFINITION.
PUBLIC SECTION.
DATA RES TYPE I.
INTERFACES RECTANGLE.
INTERFACES SQUARE.
ENDCLASS. "abc DEFINITION
59. 58 | P a g e S a n t o s h P
CLASS ABC IMPLEMENTATION.
METHOD RECTANGLE~AREA.
RES = RECTANGLE~LENGTH * RECTANGLE~BREADTH.
WRITE :/ 'Area of rectangle is :',RES.
ENDMETHOD. "rectangle~area
METHOD RECTANGLE~PERIMETER.
RES = 2 * ( RECTANGLE~LENGTH + RECTANGLE~BREADTH ).
WRITE :/ 'perimeter of rectangle is :',RES.
ENDMETHOD. "rectangle~perimeter
METHOD SQUARE~AREA.
RES = SQUARE~SIDE * SQUARE~SIDE.
WRITE :/ 'Area of square is :',RES.
ENDMETHOD. "square~area
METHOD SQUARE~PERIMETER.
RES = 4 * SQUARE~SIDE.
WRITE :/ 'perimeter of square is :',RES.
ENDMETHOD. "square~perimeter
ENDCLASS. "abc IMPLEMENTATION
START-OF-SELECTION.
DATA R TYPE REF TO RECTANGLE.
DATA S TYPE REF TO SQUARE.
DATA K TYPE REF TO ABC.
CREATE OBJECT K.
CALL METHOD : K->RECTANGLE~AREA,
K->RECTANGLE~PERIMETER,
K->SQUARE~AREA,
K->SQUARE~PERIMETER.
WRITE :/ 'RECTANGLE ---> ABC'.
R = K.
CALL METHOD : R->AREA,
R->PERIMETER.
WRITE :/ 'SQUARE ---> ABC'.
S = K.
CALL METHOD : S->AREA,
S->PERIMETER.
60. 59 | P a g e S a n t o s h P
OUTPUT:
Aliases: - aliases are the alternative names provided to the interface components i.e. whenever the
interface components is referred outside the interface declaration it must be prefixed with the name
of interface we can avoid the lengthy naming standard by declaring the aliases by the interface
components these aliases must be declared in the definition of a class whichever the implementing
the interface. By using aliases we can also change the visibility of the interface components.
ABSTRACT CLASSES INTERFACES
Can contain both abstract and non-abstract
methods.
Can contain only abstract methods.
Explicitly we need to use abstract keyword. By default all methods are abstract.
Abstract methods can be declared in public or
protected section.
All components of interface by default are
public.
A class can inherit only one abstract class. A class can implement any know of interfaces.
Abstract class components are directly referred
in subclass.
Interface components must be prefixed with the
name of the interface.
61. 60 | P a g e S a n t o s h P
Z915AM_OOPS42:
REPORT Z915AM_OOPS42.
INTERFACE ABC.
METHODS : M1,
M2.
ENDINTERFACE. "abc
CLASS PQR DEFINITION.
PUBLIC SECTION.
INTERFACES ABC.
ALIASES : A1 FOR ABC~M1.
PROTECTED SECTION.
ALIASES A2 FOR ABC~M2.
ENDCLASS. "pqr DEFINITION
CLASS PQR IMPLEMENTATION.
METHOD A1.
WRITE :/ 'inside m1'.
CALL METHOD A2.
ENDMETHOD. "a1
METHOD A2.
WRITE :/ 'inside m2'.
ENDMETHOD. "a2
ENDCLASS. "pqr IMPLEMENTATION
START-OF-SELECTION.
DATA K TYPE REF TO PQR.
CREATE OBJECT K.
CALL METHOD : K->A1.
OUTPUT:
62. 61 | P a g e S a n t o s h P
Z915AM_INT1:
Z915AM_IMPL:
method Z915AM_INT1~M1.
write :/ 'inside m1'.
call method a2.
endmethod.
method Z915AM_INT1~M2.
write :/ 'inside m2'.
endmethod.
63. 62 | P a g e S a n t o s h P
Z915AM_OOPS43:
REPORT Z915AM_OOPS43.
data ob type ref to z915am_impl.
create object ob.
call method ob->a1.
OUTPUT:
Z915AM_OOPS44:
REPORT Z915AM_OOPS44.
INTERFACE ABC.
METHODS : M1,
M2,
M3.
ENDINTERFACE. "abc
CLASS PQR DEFINITION ABSTRACT.
PUBLIC SECTION.
INTERFACES ABC ABSTRACT METHODS M2 M3.
ENDCLASS. "pqr DEFINITION
64. 63 | P a g e S a n t o s h P
CLASS PQR IMPLEMENTATION.
METHOD ABC~M1.
WRITE :/ 'inside m1'.
ENDMETHOD. "abc~m1
ENDCLASS. "pqr IMPLEMENTATION
CLASS XYZ DEFINITION INHERITING FROM PQR.
PUBLIC SECTION.
METHODS : ABC~M2 REDEFINITION,
ABC~M3 REDEFINITION.
ENDCLASS. "xyz DEFINITION
CLASS XYZ IMPLEMENTATION.
METHOD ABC~M2.
WRITE :/ 'inside m2'.
ENDMETHOD. "abc~m2
METHOD ABC~M3.
WRITE :/ 'inside m3'.
ENDMETHOD. "abc~m3
ENDCLASS. "xyz IMPLEMENTATION
START-OF-SELECTION.
DATA K TYPE REF TO XYZ.
CREATE OBJECT K.
CALL METHOD : K->ABC~M1,
K->ABC~M2,
K->ABC~M3.
OUTPUT:
65. 64 | P a g e S a n t o s h P
Z915AM_OOPS45:
REPORT Z915AM_OOPS45.
interface pqr.
methods : m1,
m3.
endinterface.
class abc definition abstract.
public section.
methods : m1 abstract,
m2.
endclass.
class abc implementation.
method m2.
write :/ 'inside m2'.
endmethod.
endclass.
class xyz definition inheriting from abc.
public section.
interfaces pqr.
methods m1 redefinition.
endclass.
class xyz implementation.
method pqr~m1.
write :/ 'inside m1 of pqr'.
endmethod.
method m1.
write :/ 'inside m1'.
endmethod.
method pqr~m3.
write :/ 'inside m3'.
endmethod.
endclass.
start-of-selection.
data ob type ref to xyz.
create object ob.
call method : ob->m1,
ob->pqr~m1,
ob->pqr~m3,
ob->m2.
66. 65 | P a g e S a n t o s h P
OUTPUT:
Persistence service: - It is used for storing the state of an object formality it is similarly to
serialization java and .net. This service is implemented by using persistence classes. This service is
implemented in two ways.
1) By using business key identity.
2) By using GUID (global unique identifier)
Storing the state of object permanently in the database is called as persistence.
By default the lifetime of the scope of an object is within the program where it is created.
Persistence class is always global and the naming standard is ‘ZCL_ (or) YCL’.
Persistence class is always created as protected class.
Whenever a persistence class is created SAP automatically create to class.
1) Base agent class naming standard is ‘ZCB_ (or) YCB_’.
2) Agent class or actor class ‘ZCA_ (or) YCA_’.
Base agent class is always created as abstract the class and it is the friend of persistence
class.
Actor class is always created as private class and it is a sub class of base agent class.
Once the persistence class is created it needs to mapped with the corresponding database
table.
Persistence class using business key identity: -
In this we consider the primary key fields of the database table as business key identity
which is used for identity the object uniquely.
In this case when the persistence class is mapped with the database tables SAP adds the
fields of the database as the attributes of the persistence class.
Also it creates the following methods as part of the base agent class.
1) Create_persistence.
2) Delete_persistence.
3) Get_persistence.
The above three method are public instance methods which gets inherited to actor class.
We need to use the above methods to interact with the persistence service.
A part from this SAP also generates getter and setter methods as part of persistence class.
Getter method is generated for all the fields of the database and setter methods are
generated for non-primary key fields of the table.
67. 66 | P a g e S a n t o s h P
To access the above three methods we require the object of base agent class. But the base
agent class is always created as abstract class and therefore cannot be instated.
Since the above three method are inherited to actor class we need to instantiate the actor
class and access these methods. But actor class is created as private class and therefore
cannot be instated.
We use the following mechanize to access these methods.
Actor class is created as singleton class.
As part of the actor class SAP as provided a public static attribute agent.
We need to access this public static attribute agent using the actor class name. When
accessed internal it execute the static constructor of actor class it is reasonable for
creating the object. This object is return back using which we access the above three
methods.
Singleton class: -
Creating a class in such way so that we can create exactly one object is called as
singleton.
Z915AM_OOPS47:
REPORT Z915AM_OOPS47.
class abc definition create private.
public section.
class-methods class_constructor.
class-methods m1 returning value(m)
type ref to abc.
methods m2.
protected section.
class-data k type ref to abc.
endclass.
class abc implementation.
method class_constructor.
write :/ 'inside static constructor,about to create object'.
create object k.
endmethod.
method m1.
write :/ 'inside static method m1,about to return object'.
m = k.
endmethod.
method m2.
write :/ 'inside instance method m2'.
endmethod.
endclass.
start-of-selection.
data r type ref to abc.
68. 67 | P a g e S a n t o s h P
*r = abc=>m1( ).
call method abc=>m1
receiving
m = r.
call method r->m2.
OUTPUT:
Z915AM_OOPS48:
REPORT Z915AM_OOPS48.
PARAMETERS : P_DEPTNO TYPE Z730CDEPT-DEPTNO,
P_DNAME TYPE Z730CDEPT-DNAME,
P_LOC TYPE Z730CDEPT-LOC.
PARAMETERS : R1 RADIOBUTTON GROUP G1,
R2 RADIOBUTTON GROUP G1,
R3 RADIOBUTTON GROUP G1.
DATA ACTOR TYPE REF TO ZCA_915DEPT.
DATA PERS TYPE REF TO ZCL_915DEPT.
START-OF-SELECTION.
ACTOR = ZCA_915DEPT=>AGENT.
IF R1 = 'X'.
TRY.
CALL METHOD ACTOR->CREATE_PERSISTENT
EXPORTING
I_DEPTNO = P_DEPTNO
I_DNAME = P_DNAME
I_LOC = P_LOC
RECEIVING
RESULT = PERS.
IF PERS IS NOT INITIAL.
69. 68 | P a g e S a n t o s h P
COMMIT WORK.
ENDIF.
CATCH CX_OS_OBJECT_EXISTING .
WRITE :/ 'Exception raised while creating'.
ENDTRY.
ELSEIF R2 = 'X'.
TRY.
CALL METHOD ACTOR->DELETE_PERSISTENT
EXPORTING
I_DEPTNO = P_DEPTNO.
COMMIT WORK.
CATCH CX_OS_OBJECT_NOT_EXISTING .
WRITE :/ 'Object not found'.
ENDTRY.
ELSEIF R3 = 'X'.
TRY.
CLEAR PERS.
CALL METHOD ACTOR->GET_PERSISTENT
EXPORTING
I_DEPTNO = P_DEPTNO
RECEIVING
RESULT = PERS.
IF PERS IS NOT INITIAL.
CLEAR : P_DNAME,
P_LOC.
TRY.
CALL METHOD PERS->GET_DNAME
RECEIVING
RESULT = P_DNAME.
CATCH CX_OS_OBJECT_NOT_FOUND .
WRITE :/ 'Exception in getter of dname'.
ENDTRY.
TRY.
CALL METHOD PERS->GET_LOC
RECEIVING
RESULT = P_LOC.
CATCH CX_OS_OBJECT_NOT_FOUND .
WRITE :/ 'Exception in getter of loc'.
ENDTRY.
WRITE :/ 'Department name :',P_DNAME,
/ 'Department location :',P_LOC.
ENDIF.
CATCH CX_OS_OBJECT_NOT_FOUND .
WRITE :/ 'Object not found'.
ENDTRY.
ENDIF.
70. 69 | P a g e S a n t o s h P
OUTPUT:
Persistence service using GUID: - In this we need to consider database table which contains
GUID as the first field. The data element of this field can be GUID/OS-GUID.
The data type of this field raw data type.
This field is used for unique identification of the object.
The value for this field is generated dynamically by SAP.
Note: - when a persistence class is mapped with the database table containing GUID also the field
expects the GUID are added as attribute of class and also getter and setter method are generated for
the entire field except GUID.
Z915AM_OOPS49:
REPORT Z915AM_OOPS49.
PARAMETERS : P_DEPTNO TYPE Z915DEPT-DEPTNO,
P_DNAME TYPE Z915DEPT-DNAME,
P_LOC TYPE Z915DEPT-LOC,
P_GUID TYPE Z915DEPT-GUID.
PARAMETERS : R1 RADIOBUTTON GROUP G1,
R2 RADIOBUTTON GROUP G1,
R3 RADIOBUTTON GROUP G1.
DATA ACTOR TYPE REF TO YCA_915DEPT.
DATA PERS TYPE REF TO YCL_915DEPT.
DATA OB TYPE REF TO OBJECT.
START-OF-SELECTION.
ACTOR = YCA_915DEPT=>AGENT.
IF R1 = 'X'.
TRY.
CALL METHOD ACTOR->CREATE_PERSISTENT
EXPORTING
I_DEPTNO = P_DEPTNO
I_DNAME = P_DNAME
71. 70 | P a g e S a n t o s h P
I_LOC = P_LOC
RECEIVING
RESULT = PERS.
IF PERS IS NOT INITIAL.
COMMIT WORK.
ENDIF.
CATCH CX_OS_OBJECT_EXISTING .
WRITE :/ 'Exception raised'.
ENDTRY.
ELSEIF R2 = 'X'.
TRY.
CALL METHOD ACTOR->IF_OS_CA_PERSISTENCY~GET_PERSISTENT_BY_OID
EXPORTING
I_OID = P_GUID
RECEIVING
RESULT = OB.
PERS ?= OB.
IF PERS IS NOT INITIAL.
TRY.
CALL METHOD ACTOR->IF_OS_FACTORY~DELETE_PERSISTENT
EXPORTING
I_OBJECT = PERS.
COMMIT WORK.
CATCH CX_OS_OBJECT_NOT_EXISTING .
WRITE :/ 'Object not found'.
ENDTRY.
ENDIF.
CATCH CX_OS_OBJECT_NOT_FOUND .
WRITE :/ 'Object not found'.
CATCH CX_OS_CLASS_NOT_FOUND .
WRITE :/ 'class not found'.
ENDTRY.
ELSEIF R3 = 'X'.
TRY.
CALL METHOD ACTOR->IF_OS_CA_PERSISTENCY~GET_PERSISTENT_BY_OID
EXPORTING
I_OID = P_GUID
RECEIVING
RESULT = OB.
PERS ?= OB.
IF PERS IS NOT INITIAL.
CLEAR : P_DEPTNO,
P_DNAME,
P_LOC.
TRY.
CALL METHOD PERS->GET_DEPTNO
RECEIVING
72. 71 | P a g e S a n t o s h P
RESULT = P_DEPTNO.
CATCH CX_OS_OBJECT_NOT_FOUND .
WRITE :/ 'Exception in getdeptno'.
ENDTRY.
TRY.
CALL METHOD PERS->GET_DNAME
RECEIVING
RESULT = P_DNAME.
CATCH CX_OS_OBJECT_NOT_FOUND .
WRITE :/ 'Exception in getdname'.
ENDTRY.
TRY.
CALL METHOD PERS->GET_LOC
RECEIVING
RESULT = P_LOC.
CATCH CX_OS_OBJECT_NOT_FOUND .
WRITE :/ 'Exception in getloc'.
ENDTRY.
WRITE :/ 'Department no :',P_DEPTNO,
/ 'Department name :',P_DNAME,
/ 'Department loc :',P_LOC.
ENDIF.
CATCH CX_OS_OBJECT_NOT_FOUND .
WRITE :/ 'Object not found'.
CATCH CX_OS_CLASS_NOT_FOUND .
WRITE :/ 'class not found'.
ENDTRY.
ENDIF.
OUTPUT:
73. 72 | P a g e S a n t o s h P
Z915_TRANS:
method M1.
data : trans_mng type ref to
if_os_transaction_manager,
trans type ref to
if_os_transaction.
CALL METHOD CL_OS_SYSTEM=>GET_TRANSACTION_MANAGER
RECEIVING
RESULT = trans_mng.
TRY.
CALL METHOD TRANS_MNG->CREATE_TRANSACTION
RECEIVING
RESULT = trans.
ENDTRY.
if trans is not initial.
TRY.
CALL METHOD TRANS->START.
call method m2.
TRY.
CALL METHOD TRANS->END.
CATCH CX_OS_CHECK_AGENT_FAILED .
CATCH CX_OS_TRANSACTION .
write :/ 'Exception in end'.
TRY.
CALL METHOD TRANS->UNDO.
ENDTRY.
ENDTRY.
CATCH CX_OS_TRANSACTION .
message 'Exception in transaction' type 'I'.
ENDTRY.
endif.
endmethod.
method M2.
data : actor type ref to zca_915dept,
74. 73 | P a g e S a n t o s h P
pers type ref to zcl_915dept.
actor = zca_915dept=>agent.
if actor is not initial.
TRY.
CALL METHOD ACTOR->CREATE_PERSISTENT
EXPORTING
I_DEPTNO = '77'
I_DNAME = 'ABAP'
I_LOC = 'Ameerpet'
RECEIVING
RESULT = pers.
CATCH CX_OS_OBJECT_EXISTING .
write :/ 'Exception in create persistent'.
ENDTRY.
endif.
endmethod.
Transaction service: - It is use for managing the object oriented transaction involving database
operations. As part of this we need to use the following class and interfaces.
1) CL_OS_SYSTEM CLASS
2) IF_OS_TRANSCATION_MANGAER INTERFACE
3) IT_OS_TRANSACTION INTERFACE
Procedure for interacting with transaction service: -
1) Start the object oriented transaction by calling the start method of the interface.
IT_OS_TRANSACTION
Start method is an instance method of interface IT_OS_TRANSACTION so we need to instantiate.
The interface IF_OS_TRANSACTION which cannot be done directly. So we need to access the
instance method Create_Transaction of the interface IF_OS_TRANSACTION_MANAGER to
access this method we required the object of transaction manger interface. To get these object of
transaction manger interface. To get this object we need to access the static method
GET_TRANSCATION_MANAGER of the class CL_OS_SYSTEM.
2) Perform the required operation: -
End the transaction by calling the end method of the interface IF_OS_TRASACTION.
When the transaction is successfully completed SAP issues commit work statement
internally for saving the transaction permanently.
If the transaction fails SAP raise the exception as part of this exception handling we need
to cancel the transaction by calling the undo method of the interface
IF_OS_TRANSCATION.
75. 74 | P a g e S a n t o s h P
Z915AM_OOPS50:
REPORT Z915AM_OOPS50.
data k type ref to z915_trans.
create object k.
CALL METHOD K->M1.
OUTPUT:
IT IS CONSIDERING IT AS TWO DIFFERENT PROGRAMS THAT’S WHY IT IS NOT
EXECUTING.
ZTR10:(TRANSACTION CODE)
Implementing persistence service using transaction service: -
Note: -
Transaction service is always implemented globally.
Since transaction service is implemented in global classes we need to attach a T-code for a
transaction class method so that everything will be executed as single process. If we access the
transaction class method form local program it executed the different process which are assuming
as two different translations.
76. 75 | P a g e S a n t o s h P
Casting: - It is the process of converting a variable from one data type to another data types they
are two types.
1) Wide casting
2) Narrow casting
Wide casting: - It is the process of converting an object from a less detailed view to more detailed
view.
Narrow casting: - It is a process of converting an object from a more details view to be less
detailed view.
Procedure for deleting the persistent object using GUID: -
Check the existent persistent object using the method gets persistent OID. If the persistent object is
available it returns the object of object class which needs to be type casted to the corresponding
persistent class object. Pass the persistent class object as an input to the method.
‘DELETE_PERSISTENT.’
Event handling in object oriented: - As part of ABAP objects SAP as provided many events as
part of standard classes. These events are used in ALV reporting work flow customization CRM
technical DSP and webdynpro programming.
As part of custom classes we can declare user defined events. These event are declared are raised
and handle by the developer itself.
Procedure for interactive with user defined events in local class: -
Declare the event in the definition of the class.
Declare the event handler method in the definition of the class.
Implemented the event handler method in the class implementation.
Raise the event in one of method implementation.
Register the handlers.
Step1 Syntax: -
Events/class-events <event name> [exporting parameters list].
Step2 Syntax: -
Methods/class-methods <method name> for event <event name> of <class name> [importing
parameter list].
Step3 Syntax: -
Raise event <event name> [exporting parameter list].
77. 76 | P a g e S a n t o s h P
Step4 Syntax: -
Set handler <handler> [for <instances>].
They are two types of events
1) Instant
2) Static
Instance events are declared by using keyword ‘events’.
Static events are declared by using keyword ‘class-events’.
Instance event is specific to an object.
They are static event is not specific to an object.
For every event there can be one are more event handler methods within the class are
across the classes.
These event handler methods are executed automatically whenever the event is raised are
triggered.
For executing the event handler methods we need to register the handlers. By using this
register handlers SAP will execute all the event handler methods. One after the other.
Accordingly to sequence of register.
Events can contains only exporting parameters which are imported by event handler
method these parameters are always passed by values. The parameter name in the event
as well as in event handler method must be same.
Note: - if the handler is not register events can be triggered but no actions can be performed
because the event handler methods will not be executed.
Z915AM_OOPS52:
REPORT Z915AM_OOPS52.
CLASS ABC DEFINITION.
PUBLIC SECTION.
EVENTS E1. "instance event
METHODS : M1 FOR EVENT E1 OF ABC, "instance event handler method
M2. "instance normal method
ENDCLASS. "abc DEFINITION
CLASS ABC IMPLEMENTATION.
METHOD M1.
WRITE :/ 'inside event handler method m1'.
ENDMETHOD. "m1
METHOD M2.
WRITE :/ 'Inside m2,About to raise event'.
RAISE EVENT E1.
ENDMETHOD. "m2
ENDCLASS. "abc IMPLEMENTATION
START-OF-SELECTION.
DATA OB TYPE REF TO ABC.
78. 77 | P a g e S a n t o s h P
CREATE OBJECT OB.
CALL METHOD OB->M2.
OUTPUT:
Z915AM_OOPS53:
REPORT Z915AM_OOPS53.
class abc definition.
public section.
events e1. "instance event
methods : m1 for event e1 of abc, "instance event handler method
m2. "instance normal method
endclass.
class abc implementation.
method m1.
write :/ 'inside event handler method m1'.
endmethod.
method m2.
write :/ 'Inside m2,About to raise event'.
raise event e1.
endmethod.
endclass.
start-of-selection.
data ob type ref to abc.
create object ob.
call method ob->m2.
set handler ob->m1 for ob.
79. 78 | P a g e S a n t o s h P
OUTPUT:
Z915AM_OOPS54:
REPORT Z915AM_OOPS54.
class abc definition.
public section.
events e1. "instance event
methods : m1 for event e1 of abc, "instance event handler method
m2. "instance normal method
endclass.
class abc implementation.
method m1.
write :/ 'inside event handler method m1'.
endmethod.
method m2.
write :/ 'Inside m2,About to raise event'.
raise event e1.
endmethod.
endclass.
start-of-selection.
data ob type ref to abc.
create object ob.
set handler ob->m1 for ob.
call method ob->m2.
OUTPUT:
80. 79 | P a g e S a n t o s h P
Z915AM_OOPS55:
REPORT Z915AM_OOPS55.
class abc definition.
public section.
events e1.
methods : m1 for event e1 of abc,
m2 for event e1 of abc,
m3.
endclass.
class abc implementation.
method m2.
write :/ 'inside second event handler method m2'.
endmethod.
method m1.
write :/ 'inside first event handler method m1'.
endmethod.
method m3.
write :/ 'inside m3,about to raise event'.
raise event e1.
endmethod.
endclass.
start-of-selection.
data ob type ref to abc.
create object ob.
set handler ob->m2 for ob.
set handler ob->m1 for ob.
call method ob->m3.
OUTPUT:
81. 80 | P a g e S a n t o s h P
Z915AM_OOPS56:
REPORT Z915AM_OOPS56.
class abc definition.
public section.
events e1.
methods : m1 for event e1 of abc,
m2 for event e1 of abc,
m3.
endclass.
class abc implementation.
method m1.
write :/ 'inside first event handler method m1'.
endmethod.
method m2.
write :/ 'inside second event handler method m2'.
endmethod.
method m3.
write :/ 'inside m3,about to raise event'.
raise event e1.
endmethod.
endclass.
start-of-selection.
data ob type ref to abc.
create object ob.
data ob1 type ref to abc.
create object ob1.
set handler ob->m2 for ob.
set handler ob->m1 for ob.
call method ob1->m3.
OUTPUT:
82. 81 | P a g e S a n t o s h P
Z915AM_OOPS57:
REPORT Z915AM_OOPS57.
class abc definition.
public section.
events e1.
methods : m1 for event e1 of abc,
m2 for event e1 of abc,
m3.
endclass.
class abc implementation.
method m1.
write :/ 'inside first event handler method m1'.
endmethod.
method m2.
write :/ 'inside second event handler method m2'.
endmethod.
method m3.
write :/ 'inside m3,about to raise event'.
raise event e1.
endmethod.
endclass.
start-of-selection.
data ob type ref to abc.
create object ob.
data ob1 type ref to abc.
create object ob1.
set handler ob->m2 for ob1.
set handler ob->m1 for ob1.
call method ob1->m3.
OUTPUT:
83. 82 | P a g e S a n t o s h P
Z915AM_OOPS58:
REPORT Z915AM_OOPS58.
class abc definition.
public section.
events e1.
methods : m1 for event e1 of abc,
m2.
endclass.
class abc implementation.
method m1.
write :/ 'inside m1, first event handler'.
endmethod.
method m2.
write :/ 'inside m2, about to raise event'.
raise event e1.
endmethod.
endclass.
class pqr definition.
public section.
methods m3 for event e1 of abc.
endclass.
class pqr implementation.
method m3.
write :/ 'inside m3, second event handler'.
endmethod.
endclass.
start-of-selection.
data ob1 type ref to abc.
create object ob1.
data ob2 type ref to pqr.
create object ob2.
set handler ob1->m1 for ob1.
set handler ob2->m3 for ob1.
call method ob1->m2.
84. 83 | P a g e S a n t o s h P
OUTPUT:
For all instance: - while register the handler for register events as part of set handler statement we
need to specify the object name after for keyword. This is reasonable for raising the event. This as
to be done for every object separately which is raising the event instead of this we can use ‘FOR
ALL INSTANCE’ keyword.
As part of handler such that the event handler method will executed irrespective of object
used for raising the event.
Z915AM_OOPS59:
REPORT Z915AM_OOPS59.
class abc definition.
public section.
events e1.
methods : m1 for event e1 of abc,
m2.
endclass.
class abc implementation.
method m1.
write :/ 'inside event handler m1'.
endmethod.
method m2.
write :/ 'inside m2, about to raise event'.
raise event e1.
endmethod.
endclass.
start-of-selection.
data ob1 type ref to abc.
create object ob1.
data ob2 type ref to abc.
create object ob2.
*set handler ob1->m1 for ob1.
*set handler ob1->m1 for ob2.
85. 84 | P a g e S a n t o s h P
set handler ob1->m1 for all instances.
call method ob1->m2.
call method ob2->m2.
OUTPUT:
Static event: - While registering the handlers for static even we should not specify the object which
is reasonable raising the static event. Because static event is not specific to on object i.e. for
keyword is not allowed for the static event part of set handler this similarly for all instances in case
of instance event.
Z915AM_OOPS60:
REPORT Z915AM_OOPS60.
class abc definition.
public section.
class-events e1.
methods : m1 for event e1 of abc,
m2.
endclass.
class abc implementation.
method m1.
write :/ 'inside m1 event handler'.
endmethod.
method m2.
write :/ 'inside m2 about to raise static event'.
raise event e1.
endmethod.
endclass.
start-of-selection.
data ob1 type ref to abc.
create object ob1.
data ob2 type ref to abc.
86. 85 | P a g e S a n t o s h P
create object ob2.
set handler ob1->m1.
call method ob1->m2.
call method ob2->m2.
OUTPUT:
Static event handler method: -
Instance event can be raised only in instance methods.
Static event can be raised either in instance are static method.
Z915AM_OOPS61:
REPORT Z915AM_OOPS61.
class abc definition.
public section.
class-events e1.
class-methods m1 for event e1 of abc.
methods m2.
endclass.
class abc implementation.
method m1.
write :/ 'inside m1, static event handler'.
endmethod.
method m2.
write :/ 'inside m2'.
raise event e1.
endmethod.
endclass.
start-of-selection.
data ob type ref to abc.
create object ob.
set handler ABC=>m1.
CALL METHOD OB->m2.
87. 86 | P a g e S a n t o s h P
OUTPUT:
Z915AM_OOPS62:
REPORT Z915AM_OOPS62.
class abc definition.
public section.
events e1.
class-methods m1 for event e1 of abc.
methods m2.
endclass.
class abc implementation.
method m1.
write :/ 'inside m1, static event handler'.
endmethod.
method m2.
write :/ 'inside m2'.
raise event e1.
endmethod.
endclass.
start-of-selection.
data ob type ref to abc.
create object ob.
set handler abc=>m1 for ob.
call method ob->m2.
88. 87 | P a g e S a n t o s h P
OUTPUT:
Z915AM_OOPS63:
REPORT Z915AM_OOPS63.
CLASS ABC DEFINITION.
PUBLIC SECTION.
EVENTS E1 EXPORTING VALUE(X) TYPE I OPTIONAL.
METHODS : M1 FOR EVENT E1 OF ABC
IMPORTING X,
M2 IMPORTING Y TYPE I.
ENDCLASS. "abc DEFINITION
CLASS ABC IMPLEMENTATION.
METHOD M1.
WRITE :/ 'inside event handler m1'.
WRITE :/ 'parameter received is ',X.
ENDMETHOD. "m1
METHOD M2.
WRITE :/ 'inside m2,about to raise event'.
RAISE EVENT E1
EXPORTING
X = Y.
ENDMETHOD. "m2
ENDCLASS. "abc IMPLEMENTATION
START-OF-SELECTION.
DATA OB TYPE REF TO ABC.
CREATE OBJECT OB.
PARAMETERS R TYPE I.
SET HANDLER OB->M1 FOR OB.
CALL METHOD OB->M2
EXPORTING
Y = R.
89. 88 | P a g e S a n t o s h P
OUTPUT:
Z915AM_CLASS11:
method M1.
WRITE :/ 'INSIDE EVENT HANDLER'.
WRITE :/ 'PARAMETER RECEIVED IS ',P1.
endmethod.
method M2.
WRITE :/ 'INSIDE M2'.
RAISE EVENT E1
EXPORTING
P1 = 10.
endmethod.
90. 89 | P a g e S a n t o s h P
Z915AM_OOPS64:
REPORT Z915AM_OOPS64.
data ob type ref to z915am_class11.
create object ob.
set handler ob->m1 for ob.
call method ob->m2.
OUTPUT:
91. 90 | P a g e S a n t o s h P
Z915AM_RESTAURANT:
method SET.
TABLENO = 10.
STEWARD = 'ABC'.
endmethod.
method DISPLAY.
WRITE :/ TABLENO,STEWARD.
endmethod.
Z915AMCYCLE:
92. 91 | P a g e S a n t o s h P
method SETCYCLE.
wheels = 2.
brakes = 2.
colour = 'blue'.
endmethod.
method DISPLAY.
write :/ wheels,brakes,colour.
endmethod.
Z915AMSCOOTER:
93. 92 | P a g e S a n t o s h P
method SETSCOOTER.
wheels = 2.
brakes = 4.
colour = 'red'.
endmethod.
Z915AMCAR:
94. 93 | P a g e S a n t o s h P
method SETCAR.
wheels = 4.
brakes = 5.
colour = 'cyan'.
endmethod.