Subroutines and Functions

Slides:



Advertisements
Similar presentations
ABAP Chapter 5 Modularization Catch Statement.
Advertisements

Programming C/C++ on Eclipe Trình bày : Ths HungNM C/C++ Training.
Chapter 3: Modularization
Program Slice Program slice was a concept first discussed by Mark Weiser in the early 1980’s –He especially noticed that when people debug, they trace.
Chapter 7 User-Defined Methods. Chapter Objectives  Understand how methods are used in Java programming  Learn about standard (predefined) methods and.
Chapter 9 Subprogram Control Consider program as a tree- –Each parent calls (transfers control to) child –Parent resumes when child completes –Copy rule.
An Introduction to Programming with C++ Fifth Edition
 SAP AG CSU Chico MINS298c ABAP/4 Programming Gail Corbitt Fall 1998 Chapter 1-3.
CS 330 Programming Languages 10 / 16 / 2008 Instructor: Michael Eckmann.
FunctionsFunctions Systems Programming. Systems Programming: Functions 2 Functions   Simple Function Example   Function Prototype and Declaration.
1 CSC 1401 S1 Computer Programming I Hamid Harroud School of Science and Engineering, Akhawayn University
FunctionsFunctions Systems Programming Concepts. Functions   Simple Function Example   Function Prototype and Declaration   Math Library Functions.
Performing Computations C provides operators that can be applied to calculate expressions: example: tax is 8.5% of the total sale expression: tax =
ABAP/4 PROGRAMMING Menu Painter Modularization 講 師:呂 昇 燦 2000 年 9 月 28 日.
©Ian Sommerville 2000 Software Engineering, 6th edition. Chapter 10Slide 1 Architectural Design l Establishing the overall structure of a software system.
Procedures and Functions Computing Module 1. What is modular programming? Most programs written for companies will have thousands of lines of code. Most.
C++ Programming: From Problem Analysis to Program Design, Fifth Edition, Fifth Edition Chapter 7: User-Defined Functions II.
SE: CHAPTER 7 Writing The Program
Computer Science: A Structured Programming Approach Using C1 4-6 Scope Scope determines the region of the program in which a defined object is visible.
Introduction to Computers and Programming Lecture 14: User defined methods (cont) Professor: Evan Korth New York University.
Programming Logic and Design Using Methods. 2 Objectives Review how to use a simple method with local variables and constants Create a method that requires.
CPS120: Introduction to Computer Science Functions.
CPS120: Introduction to Computer Science Lecture 14 Functions.
7 1 User-Defined Functions CGI/Perl Programming By Diane Zak.
Chapter 3 Functions, Events, and Control Structures JavaScript, Third Edition.
Procedures and Modular Programming Part # 2. Interface Block ► Functions do not have to be internal to main program ► They can be stand-alone ► In this.
Implementing Subprograms What actions must take place when subprograms are called and when they terminate? –calling a subprogram has several associated.
I Power Higher Computing Software Development High Level Language Constructs.
CNS 1120 Exam 1 Review. Programming Language Elements Syntax = the rules to follow Syntax = the rules to follow Semantics = the meaning of symbols Semantics.
Concepts of programming languages Chapter 5 Names, Bindings, and Scopes Lec. 12 Lecturer: Dr. Emad Nabil 1-1.
Computing Higher – SD Unit - Topic 8 – Procedure and Standard Algorithms P Lynch, St Andrew’s High School Unit 2 Software Development Process Topic.
Functions Math library functions Function definition Function invocation Argument passing Scope of an variable Programming 1 DCT 1033.
Modularity using Functions Chapter 4. Modularity In programming blocks of code often can be "called up" and reused whenever necessary, for example code.
 2008 Pearson Education, Inc. All rights reserved Introduction to Classes and Objects.
Functions  A Function is a self contained block of one or more statements or a sub program which is designed for a particular task is called functions.
SAP DEVELOPMENT BASICS Bohuslav Tesar. TRAINING OVERVIEW Amazing life of ABAP developer ;) SAP introduction ABAP basics ABAP Reporting.
10-1 Chapter 10: Implementing Subprograms The General Semantics of Calls and Returns Implementing “Simple” Subprograms Implementing Subprograms with Stack-Dynamic.
Oracle10g Developer: PL/SQL Programming1 Objectives Named program units How to identify parameters The CREATE PROCEDURE statement Creating a procedure.
PHP Reusing Code and Writing Functions 1. Function = a self-contained module of code that: Declares a calling interface – prototype! Performs some task.
Lesson 9: Modular Programming Todd A. Boyle, Ph.D. St. Francis Xavier University.
JavaScript Modularity. Goals By the end of this lecture, you should … Understand why programmers use modularity. Understand how to create a function in.
Slide 1 Chapter 8 Architectural Design. Slide 2 Topics covered l System structuring l Control models l Modular decomposition l Domain-specific architectures.
Programming Logic and Design Fifth Edition, Comprehensive Chapter 7 Using Methods.
©2004 Joel Jones 1 CS 403: Programming Languages Lecture 3 Fall 2004 Department of Computer Science University of Alabama Joel Jones.
Component 1.6.
Chapter 7: Function.
Coupling and Cohesion Rajni Bhalla.
Oracle11g: PL/SQL Programming Chapter 5 Procedures.
Chapter 7: User-Defined Functions II
Names and Attributes Names are a key programming language feature
CS 326 Programming Languages, Concepts and Implementation
Value-Returning Functions
Review: Chapter 5: Syntax directed translation
UNIT - V STORED PROCEDURE.
Topic: Functions – Part 2
Function There are two types of Function User Defined Function
C-language Lecture By B.S.S.Tejesh, S.Neeraja Asst.Prof.
PHP Functions, Scope MIS 3501, Fall 2015 Jeremy Shafer
CMPE 152: Compiler Design October 4 Class Meeting
Topics discussed in this section:
Programming Logic and Design Fourth Edition, Comprehensive
Chapter 9: Value-Returning Functions
Names and Binding In Text: Chapter 5.
Topics Introduction to Functions Defining and Calling a Function
Methods.
Communication between modules, cohesion and coupling
Chapter 10: Void Functions
CPS125.
Presentation transcript:

Subroutines and Functions MINS298c Fall 1998 Chapters 10 11/29/2018 Subroutines

Overview Subroutines Forms Functions What they are Why to include in program Forms Implementing and using Functions 11/29/2018 Subroutines

Scope of the Program Global: Applies to all programs or parts of programs running at the time Not advised if can be avoided Prone to errors Difficult to track Local: Applies to only the subprogram running at the time Increases modularity of code (good thing) Easy to debug and track 11/29/2018 Subroutines

Subroutines (Normal Scope) Line Program DATA A, B, C 1 2 3 4 5 6 According to normal rules of “scope,” which Write statements are legal and which are not? Write A Write F Form DATA X, Y, Z Write A Write F Form DATA D, E, F Write A Write F 11/29/2018 Subroutines

Subroutine Self contained blocks of code that can be reused by different parts of a program Advantages: Self contained code = Easy to maintain and debug Changes in subroutine do not affect rest of program Reduces complexity -- more modular Consistent with code quality: Highly Cohesive Loosely Coupled 11/29/2018 Subroutines

Mapping ABAP Concepts to Subroutines Subroutine = Form Explicit to program by being a block of code within the program Implicit to program by using INCLUDE Both are called using PERFORM 11/29/2018 Subroutines

Subroutines Defined by FORM and ENDFORM Executed with PERFORM verb Can call by value or call by reference by reference is implied VALUE clause passes by value ABAP does number and type checking at runtime 11/29/2018 Subroutines

PERFORM Syntax PERFORM subroutine_name [USING p1 p2 p3….] [CHANGING p1 p2 p3 …] [TABLES itab1 itab2 itab3 …..] USING passes p1, p2, … pn single variables by reference USING VALUE p1 p2 …p3 passes values to subroutine but return values do not replace original p1, p2, pn Example of use: depreciation or tax calculation changes original value of asset during calculation 11/29/2018 Subroutines

PERFORM Syntax cont. CHANGING nearly the same as USING Values are changed in the subroutine Passed back to the calling program, but changes are not passed back until the subroutine ends TABLES passes a whole table(s) by reference Uses internal table(s) Can not pass by Value only Reference ?? 11/29/2018 Subroutines

Example ASSUME: x, y, and z are integer and x = 4; y = 5; z =10 WRITE x, y, z. PERFORM add_em CHANGING VALUE(x) y CHANGING z. FORM add_em a1 a2 CHANGING a3. a1 = a1 + 1. a2 = a2 + 2. a3 = a1 + a2. ENDFORM.. 11/29/2018 Subroutines

Functions Functions are global -- available to all programs from the library: Created outside the program Created with FUNCTION and ENDFUNCTION statement Called from programs with CALL FUNCTION ABAP/4 Development Workbench > Function Group Objects > Single Object Name the function and click on Create Parameters of a function = Import, Export, Change See pages 216-230 11/29/2018 Subroutines

Programming Assignment 2 Write a program to create a list of the top five companies with the highest sales Use SAP Table TABNA and pick up country, name of company, address, sales, and currency Call the function CONVERT_TO_LOCAL_CURRENCY properly Transfer conversion date, foreign currency amount, foreign currency key, and target currency key Use a subroutine to rank the companies by sales where we can get the top N companies 11/29/2018 Subroutines