Professional Documents
Culture Documents
Modularization Techniques
Objectives
Subroutine
Calculate_tax
Modularization
External FunctionModule
Call Call
REPORT YEXAMS1. ABAP Function Builder
Function module
Form sub ZZCALC
Main 99 1
Program a1 a2 a3
Call Calculate_tax
Transfer values of fields a1 a2
Get value of field a3
Actual parameters a1 a2 a3
Parameter transfer
Pass by Value a1
b r ou tine
Su
Pass by Value and Result
f1
a1
Subro
u tine
Pass by Reference a1 f1
r ou t ine
Su b
f1
REPORT Y170D091.
TABLES: ....
DATA: .…
.
.
.
PERFORM <name> USING
<a1> <a2>
<a3> <a4>.
.
.
.
FORM <name> USING
VALUE(<f1>)
VALUE(<f2>)
<f3> Pass by value
<f4>.
<statements> Pass by reference
ENDFORM.
* ------------------------------------------------------------------------------------------------*
* FORM SUB1 *
* ------------------------------------------------------------------------------------------------*
form sub1.
data: begin of tab occurs 10, “ <----------- local data
id like tabna-id,
name1 like tabna-name1, Local Data
end of tab.
local: num . “ <----------- local data
. . . <statements>
endform.
STATICS Whatever the local If declared globally, Last set value from
STATICS statement returns to old value, inside subroutine
initializes otherwise not
recognized
LOCAL Last set value from Last set value from Last set value from
main program main program main program
REPORT Y170D095.
TABLES: TABNA. This is passing the
DATA: ZTAB LIKE TABNA. TABNA work area
DATA: FLAG. only
.
.
PERFORM SUB1 USING TABNA. This is passing the
PERFORM SUB1 USING ZTAB. ZTAB structure
.
.
.
ENDFORM.
External Subroutines
Demonstration
Practice
Function Modules
Function Builder
FM Group : FIBU
FM_01 ...
Program 1 FM_02 ... Program 2
FM Group : XYZ
CALL FUNCTION CALL FUNCTION
FM_03 ...
‘FM_02’ ‘FM_02’
FM_04 ... ...
...
Program 3
CALL FUNCTION
‘FM_02’
...
FM -02
Section I … Administration FM Group : FIBU
Section II … Interface
FM_01 ...
Chapter 1 … Import FM_02 ...
Chapter 2 … Changing
Chapter 3 … Export
Chapter 4 … Tables
Chapter 5 … Exceptions
FM Group : XYZ
Section III … Documentation
FM_03 ...
Section IV … Source Code
FM_04 ...
Section V … Global Data
Function Module
Interfaces
Program XYZ.
Call function
‘Y_DEMO_FUNC’
Import
Changing
Export
Tables
Function Module
Exceptions Y_DEMO_FUNC
Pass parameter
Parameter name by reference
‘LIKE’
Flag parameter
as optional
Parameter name
‘TYPE’
Exceptions
INVALID_OPERATOR
Function Module
...
IF...
RAISE INVALID_OPERATOR.
* MESSAGE. . . RAISING
INVALID_OPERATOR.
ENDIF.
...
case sy-subrc.
when 1.
message e001.
when 2.
message e005.
when 3.
message e007.
endcase.
Program Organisation
SAPL <gr>
L<gr>TOP
*System-defined include files
FUNCTION-POOL <gr>
INCLUDE L<gr>TOP. Message-ID ZZ.
INCLUDE L<gr>UXX DATA: “Global DATA
*User-defined include files
L<gr>UXX
INCLUDE L<gr> U01.
L<gr>U01 INCLUDE L<gr> U02.
FUNCTION FA. .
.
L<gr>U02 .
FUNCTION FB.
Main Program
Global Data
L <gr> TOP
FUNCTION-POOL <gr>.
DATA: X
TABLES: . . .
Program Subroutines
FUNCTION . . . L <gr> F01
DATA: . . . FORM SUB1 USING...
MOVE X TO . . . DATA: . . .
ENDFUNCTION. MOVE. . . TO X.
ENDFORM.
Test Environment
Export Parameters
Administration
External program
RFCLid
External Program. . .
RfcOpen (. . .)
RfcCallReceive (. . .)
RfcClose (. . .)
Demonstration
Practice
Summary
Questions