Академический Документы
Профессиональный Документы
Культура Документы
Modularization Techniques
Modularization Techniques |
Dec-2008
Objectives
The participants will be able to:
Create Subroutines
Describe the various methods for passing Parameters to Subroutines
Create Function Modules
Call Function Modules from ABAP Programs
Modularization Techniques |
Dec-2008
REPORT YEXAMPLE2.
Calculate tax
Call calculated_tax
Calculate tax
Call calculated_tax
Subroutine
Calculate_tax
Modularization Techniques |
Dec-2008
Modularization
REPORT YEXAM1.
REPORT YEXAM2.
REPORT YEXAM3.
Perform sub(YDEMOSB1)
Perform sub
Form sub
External
Call
REPORT YEXAMS1.
Form sub
Modularization Techniques |
FunctionModule
Call
ABAP Function Builder
Function module
ZZCALC
Dec-2008
99
a1
a2
a3
Call Calculate_tax
Transfer values of fields a1 a2
Get value of field a3
Actual parameters
a1
a2
a3
Parameter transfer
ine
t
u
o
r
Sub
Formal parameters
f1
f2
f3
Subroutine calculate_tax
99
1
f1
f2
f3
f3 = f1 +f2 . . . .
Modularization Techniques |
Dec-2008
a1
tine
u
o
r
b
Su
f1
Pass by Reference
a1
Subro
u
tine
f1
ine
t
u
o
r
Sub
f1
Modularization Techniques |
Dec-2008
<statements>
Pass by value
Pass by reference
ENDFORM.
Modularization Techniques |
Dec-2008
Modularization Techniques |
Dec-2008
y170dm86.
id
type id,
name type name1.
. . . <statements>
perform sub1.
. . . <statements>
Global Data
* ------------------------------------------------------------------------------------------------*
*
FORM SUB1
*
* ------------------------------------------------------------------------------------------------*
form sub1.
data: begin of tab ,
<----------- local data
id
type id,
Local Data
name1 type name1,
end of tab.
local: num
.
<----------- local data
. . . <statements>
endform.
Modularization Techniques |
Dec-2008
Value Upon
Entering
Subroutine First
Time
Value Upon
Value Upon
Returning to Main Entering
Program
Subroutine Next
Time
DATA
If declared globally,
returns to old value,
otherwise not
recognized
Re-initializes based
on local DATA
statement
STATICS
If declared globally,
returns to old value,
otherwise not
recognized
LOCAL
10
Modularization Techniques |
Dec-2008
11
Modularization Techniques |
Dec-2008
12
Modularization Techniques |
Dec-2008
External Subroutines
PERFORM <name>(<prog name>) USING . . .
REPORT Y170D096.
DATA:
TABNA TYPE TABNA,
T001 TYPE T001,
T005 TYPE T005.
.
.
.
START-OF-SELECTION.
.
.
.
PERFORM
SUB1(Y170D097) . . . .
.
.
.
13
REPORT Y170D097.
DATA :
TABNA TYPE TABNA,
T001 TYPE T001,
T001G TYPE T001G.
.
.
.
START-OF-SELECTION
.
.
.
FORM SUB1 . . . .
.
.
NEW-PAGE.
.
.
ENDFORM
Modularization Techniques |
Roll Area
TABNA
T001
T005
T001G
Y170D108
Y170D109
Storage Allocation
Dec-2008
Demonstration
Creating a subroutine in a program to modularize the logic.
14
Modularization Techniques |
Dec-2008
Practice
Creating a subroutine in a program to modularize the logic.
15
Modularization Techniques |
Dec-2008
Function Modules
Function Builder
Program 1
CALL FUNCTION
FM_02
...
FM Group : FIBU
FM_01 ...
FM_02 ...
Program 2
FM Group : XYZ
FM_03 ...
FM_04 ...
CALL FUNCTION
FM_02
...
Program 3
CALL FUNCTION
FM_02
...
16
Modularization Techniques |
Dec-2008
FM -02
Section I Administration
Section II Interface
Chapter 1 Import
Chapter 2 Changing
Chapter 3 Export
Chapter 4 Tables
Chapter 5 Exceptions
FM Group : FIBU
FM_01 ...
FM_02 ...
FM Group : XYZ
FM_03 ...
FM_04 ...
17
Modularization Techniques |
Dec-2008
18
Modularization Techniques |
Dec-2008
Function Module
19
Modularization Techniques |
Dec-2008
Interfaces
Program XYZ.
Call function
Y_DEMO_FUNC
Import
Changing
Export
Tables
Exceptions
20
Modularization Techniques |
Function Module
Y_DEMO_FUNC
Dec-2008
Default value
Pass parameter
by reference
Parameter name
TYPE
21
Modularization Techniques |
Flag parameter
as optional
Dec-2008
Flag parameter
as optional
Parameter name
TYPE
22
Modularization Techniques |
Dec-2008
23
Modularization Techniques |
Dec-2008
Exceptions
INVALID_OPERATOR
Function Module
...
IF...
RAISE INVALID_OPERATOR.
* MESSAGE. . . RAISING
INVALID_OPERATOR.
ENDIF.
...
24
Modularization Techniques |
Dec-2008
25
Modularization Techniques |
Dec-2008
26
Modularization Techniques |
Dec-2008
27
Modularization Techniques |
Dec-2008
Program Organisation
SAPL <gr>
*System-defined include files
L<gr>TOP
INCLUDE L<gr>TOP.
INCLUDE L<gr>UXX
FUNCTION-POOL <gr>
Message-ID ZZ.
DATA: Global DATA
L<gr>UXX
L<gr>U01
FUNCTION FA.
L<gr>U02
FUNCTION FB.
28
Modularization Techniques |
Dec-2008
Call
29
Modularization Techniques |
FUNCTION . . .
.
.
.
PERFORM SUB1 USING . . .
.
.
.
ENDFUNCTION.
Dec-2008
Program
FUNCTION . . .
DATA: . . .
MOVE X TO . . .
ENDFUNCTION.
30
Modularization Techniques |
Subroutines
L <gr> F01
FORM SUB1 USING...
DATA: . . .
MOVE. . . TO X.
ENDFORM.
Dec-2008
Test Environment
Import parameters
Tables
Does it work?
Export Parameters
31
Modularization Techniques |
Dec-2008
32
Modularization Techniques |
Dec-2008
External program
Function Group
ABAP
FUNCTION-POOL . . . .
Function
Function Module
Module
FUNCTION REMOTE_CALL
...
RAISE ERROR.
...
ENDFUNCTION.
RFCLid
External Program. . .
RfcOpen (. . .)
RfcCallReceive (. . .)
RfcClose (. . .)
33
Modularization Techniques |
Dec-2008
34
Modularization Techniques |
Dec-2008
* At the end
If errors = E.
*---------------------------------------------------------------------*
*
YINCLUDE_TECHNIQUE_SUBROUTINES
*---------------------------------------------------------------------*
FORM sub_print_report_heading.
PERFORM sub_print_report_heading.
* Write rest of report
Write : /
/
/
/
ENDFORM. SUB_PRINT_REPORT_HEADING
35
Modularization Techniques |
Dec-2008
Demonstration
Creating a function module and using it in a program.
36
Modularization Techniques |
Dec-2008
Practice
Creating a function module and using it in a program.
37
Modularization Techniques |
Dec-2008
Summary
Redundancy in program can be avoided using subroutines.
Subroutines are used in three different ways: internal call, external call, a function
module stored centrally in the Function Builder.
Parameters passed to the subroutine using one of the following three methods.
Pass by value, Pass by value and result, Pass by reference.
The benefit of function modules lies in their reusability, which saves developers
from creating redundant code and increases programming efficiency.
Function groups are collections of logically related functions modules.
Specification of a function group is required when creating a function module.
The additional parameter DESTINATION is required for the remote call of a
Function Module.
38
Modularization Techniques |
Dec-2008
Questions
Why subroutine is used in the program?
What is function module? What is the advantage of using it in the program?
What are the different parameters of a function module?
What is function group?
How a function module can be remote enabled?
39
Modularization Techniques |
Dec-2008