Professional Documents
Culture Documents
Sapchap 05
Sapchap 05
ABAP/4
ABAP/4 4
ABAP/4
Modularization
Logical Database
ABAP/4
2.
3.
Modularization 3
1. Internal Call
2. External Call
3. Function Call
Function Module
Internal Call
PERFORM
( 30 )
FORM
ENDFORM
REPORT ZTEST.
107
5
Modularization Logical Database
* Global Data
TABLES
DATA
* Subroutine Calls
PERFORM routine1.
PERFORM routine2.
* Subroutine routine1
FORM routine1.
DATA Local Data
<Statements>
ENDFORM.
* Subroutine routine2
FORM routine2.
<Statements>
ENDFORM.
2
routine1
routine2
Local Data
Local Data
108
5
Modularization Logical Database
Parameter Output Parameter
3
1. Call by Value
Call by Value Read-only
Formal Parameter
Memory Space Copy
Actual Parameter Formal Parameter
Call by Value
Memory Space( )
Space( )
Memory
a1(Actual Parameter)
f1(Formal Parameter) Memory Space copy
a1 f1
f1 a1
Copy
Call by Value
a1
f1
109
5
Modularization Logical Database
Memory Space( )
Memory Space( )
Address Passing
a1
f1
Address
a1 Pointer f1
a1
f1 a1
(Address Memory Space)
USING
Memory
Space( )
110
5
Modularization Logical Database
Actual Parameter Formal Parameter
Copy Actual Parameter Formal Parameter
Copy Formal Parameter Actual Parameter
f1 a1
VALUE )
CHANGING Call by
Value and Result
Parameter Structure
Structure Structure
Structure Table Work Area Structure DATA BEGIN OF
Structure Structure Memory Space
TABLES customers.
SELECT * FROM customers.
PERFORM sub1 USING customers.
PERFORM sub2 USING customers.
ENDSELECT.
FORM sub1 USING rec.
WRITE: / rec.
ENDFORM.
FORM sub2 USING rec LIKE customers.
WRITE: / rec-id, rec-name.
ENDFORM.
PERFORM Structure Structure
customers Table Work Area
sub1 Formal
Parameter
rec Structure Rec Structure
rec-id sub1
Line-oriented Structure
sub2 Formal Parameter
rec
Structure
LIKE customers
( customers Structure)
111
5
Modularization Logical Database
sub2 Structure (Single field of
Field String) WRITE rec-id Structure
Call by Reference
Parameter Internal Table
Parameter
Structure Internal Table Internal Table
Internal Table Header Line
Internal Table Internal Table
Call by Reference Internal Table
Internal Table
112
5
Modularization Logical Database
REPORT ZTEST1.
WRITE: / sy-repid.
PERFORM subroutine(ZTEST2).
REPORT ZTEST2.
FORM subroutine.
WRITE: / sy-repid.
ENDFORM.
subroutine ZTEST2
( )
PERFORM Runtime
Function Call
Function Library
Return
Transaction Code SE37
Function
Group Import/Export Parameter
Import Parameter
Export Parameter
Parameter Goto-> Imp./exp.
Interface
113
5
Modularization Logical Database
Export Parameter
1 result_degree
Import/Export Parameter
Exception
Exception
Exception
Exception Goto-> Tab./exc interface
114
5
Modularization Logical Database
Exception
incorrect
Table/Exception
Internal Table
Editor
Goto-> Function module Editor
Editor
Celsius Fahrenheit Fahrenheit Celsius
FUNCTION Z_TEST.
IF t_unit = F.
result_degree = ( degree - 32 ) * 5 / 9.
ELSEIF t_unit = C.
result_degree = ( degree * 9 / 5 ) + 32.
ELSE.
RAISE incorrect.
ENDIF.
ENDFUNCTION.
RAISE Function Module RAISE
Exception incorrect t_unit F C
Exception
incorrect
115
5
Modularization Logical Database
displaytemp = Fahrenheit.
ENDIF.
WRITE:
Temperature of , t_degree
, t_temp
, is ,ZTEST2.
deg , displaytemp.
REPORT
REPORT/ ZTEST1.
Call
Finish.
CALL FUNCTION
( ABAP/4
CALL FUNCTION Z_TEST )
Z_TEST Formal Parameter ( t_unit degree
result_degree incorrect) Actual Parameter
Formal Parameter Function Module Transaction Code
SE37
Actual Parameter
Exception incorrect
1
incorrect Exception
sy-subrc
sy-subrc
Exception RAISE
sy-subrc 1 t_temp
C F Exception 1
Insert Statement Editor
Formal Parameter
Linking Component
Linking Component Transaction
2
1. Submit Report Without Return
SUBMIT
2 ZTEST1 ZTEST2
116
5
Modularization Logical Database
ZTEST2 SUBMIT
ZTEST2
ZTEST2
REPORT ZTEST1.
PARAMETERS tmp TYPE D.
SUBMIT ZTEST2
WITH tmp1 = tmp
AND RETURN
VIA SELECTION-SCREEN.
WRITE: / ZTEST1 Finish.
Call
REPORT ZTEST2.
PARAMETERS tmp1 TYPE D.
WRITE: / ZTEST2 Finish.
Return
ZTEST2 SUBMIT
ZTEST2 tmp tmp1
ZTEST2
ZTEST1 SUBMIT
SUBMIT
START-OF-SELECTION
Transaction Transaction
2
1. Call Transaction Without Return Transaction
Transaction
LEAVE TO TRANSACTION Transaction
REPORT ZTEST.
117
5
Modularization Logical Database
ZTEST Transaction Code SU01
LEAVE TO TRANSACTION SU01 Transaction
Transaction SU01
ZTEST Report Finish
REPORT ZTEST.
TABLES equi.
START-OF-SELECTION.
SELECT * FROM equi.
WRITE: / equi-equnr, equi-eqart.
HIDE equi-equnr.
ENDSELECT.
AT LINE-SELECTION.
SET PARAMETER ID EQN FIELD equi-equnr.
CALL TRANSACTION IE02 AND SKIP FIRST SCREEN.
CLEAR equi-equnr.
SET PARAMETER ID EQN FIELD equi-equnr equi-equnr
Basic List
Equipment
Equipment equi-equnr
Equipment Parameter ID
EQN
Parameter ID
F1
F9 (Technical Info) Parameter ID
118
5
Modularization Logical Database
CALL TRANSACTION
SKIP FIRST SCREEN
Transaction IE02
Transaction IE02 Equipment Transaction IE02
SET
Logical Database
Logical
119
5
Modularization Logical Database
Logical Database
Selection Screen Logical Database
SELECT
Logical Database
sflight sbook
2
sflight
CARRID
CONNID
FLDATE
LH
0400
28/02/1995
LH
0454
17/11/1995
LH
0455
06/06/1995
LH
3577
28/04/1995
SQ
0026
28/02/1995
sbook
CARRID
CONNID
FLDATE
CUSTOMID
LH
0400
28/02/1995
01
LH
0400
28/02/1995
02
LH
0400
28/02/1995
03
LH
0454
17/11/1995
01
LH
0454
17/11/1995
02
LH
0455
06/06/1995
01
LH
3577
28/04/1995
01
SQ
0026
28/02/1995
01
SQ
0026
28/02/1995
02
LH 28/02/1995
SELECT
120
5
Modularization Logical Database
sflight sbook
Logical Database
Logical Database
Logical Database
F1S (F1 Logical Database S S
Basis
) Logical Database
Transaction SE36 Tools-> ABAP/4 Workbench-> Development-> Programming environ.->
Logical databases
121
5
Modularization Logical Database
Logical Database
F1S 3 spfli
sflight sbook Parent Table
2
sflight sbook spfli
Selections Selection Screen
122
5
Modularization Logical Database
SELECTION-SCREEN SELECT-OPTIONS
Logical Database
Database program SAP
SELECT
Logical Database
Event Logical Database (GET)
Event
GET Logical Database
GET GET sflight Logical Database
Attribute
Selection Screen Event
GET Evet
Top-down Method of Flow
Hierarchy Logical Database
Logical Database F1S Event GET spfli
GET sflight GET sbook sflight
sbook GET sflight
GET sbook Event GET
Event-driven Programming
GET sbook.
WRITE: / sbook-customid.
GET sflight.
WRITE: / sflight-carrid, sflight-connid, sflight-fldate.
GET sflight
Selection Screen Table Work Area
GET sbook GET Logical Database
( sflight)
sbook
GET sflight sflight Event GET sflight
( Hierarchy Logical
Database ) GET sbook
ENDSELECT.
ENDSELECT.
123
5
Modularization Logical Database
Event
START-OF-SELECTION END-OF-SELECTION
Logical Database
GET LATE
Event GET
Logical Database
LATE GET
Hierarchy Logical Database
Event GET LATE
Logical Database
GET sflight.
WRITE: / sflight-carrid, sflight-connid, sflight-fldate.
GET sbook.
WRITE: / sbook-customid.
LH
01
02
03
0400
28/02/1995
01
02
03
LH
0400
28/02/1995
sflight sbook
Logical Database Selection Screen
Selection Screen
Selection Screen Selection Screen
Event GET
Database Program Logical Database CHECK
124
5
Modularization Logical Database
Selection Screen
Selection Screen
Logical
Database
Logical Database
Transaction SE36 Structure
Selection Screen Database Program
Database Program
SELECT Logical
Database
125