subroutines and functions l.
Download
Skip this Video
Loading SlideShow in 5 Seconds..
Subroutines and Functions PowerPoint Presentation
Download Presentation
Subroutines and Functions

Loading in 2 Seconds...

play fullscreen
1 / 12

Subroutines and Functions - PowerPoint PPT Presentation


  • 159 Views
  • Uploaded on

Subroutines and Functions. MINS298c Fall 1998 Chapters 10. Overview. Subroutines What they are Why to include in program Forms Implementing and using Functions. Scope of the Program. Global: Applies to all programs or parts of programs running at the time

loader
I am the owner, or an agent authorized to act on behalf of the owner, of the copyrighted work described.
capcha
Download Presentation

Subroutines and Functions


An Image/Link below is provided (as is) to download presentation

Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author.While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server.


- - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - -
Presentation Transcript
subroutines and functions

Subroutines and Functions

MINS298c

Fall 1998

Chapters 10

Subroutines

overview
Overview
  • Subroutines
    • What they are
    • Why to include in program
  • Forms
    • Implementing and using
  • Functions

Subroutines

scope of the program
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

Subroutines

subroutines normal scope
Subroutines (Normal Scope)

Line

Program

DATA A, B, C

According to normal

rules of “scope,” which

Write statements are

legal and which are not?

1

2

3

4

5

6

Write A

Write F

Form

DATA X, Y, Z

Write A

Write F

Form

DATA D, E, F

Write A

Write F

Subroutines

subroutine
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

Subroutines

mapping abap concepts to 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

Subroutines

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

Subroutines

perform syntax
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

Subroutines

perform syntax cont
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 ??

Subroutines

example
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.

WRITE x, y, z.

FORM add_em a1 a2 CHANGING a3.

a1 = a1 + 1.

a2 = a2 + 2.

a3 = a1 + a2.

ENDFORM..

Subroutines

functions
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

Subroutines

programming assignment 2
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

Subroutines