You are on page 1of 19

5

Modularization Logical Database


5

ABAP/4

ABAP/4 4

ABAP/4

Modularization


Logical Database

ABAP/4

Logical Database Modularization


Modularization
Modularization
Main Program
Subroutine
3
1.

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

DATA tmp TYPE I VALUE 1.


WRITE tmp.
PERFORM test.
WRITE tmp.
FORM test.
DATA tmp TYPE I.
tmp = 9.
WRITE tmp.
ENDFORM.

tmp Local data



Global Data Local Data Memory Space
Global Data

Local Data Release Memory Space

Parameter
( PARAMETERS
) Parameter 2 Input

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

DATA a1 TYPE I VALUE 9.


PERFORM subroutine USING a1.
FORM subroutine USING VALUE(f1).
f1 = 99.
WRITE f1.
ENDFORM.
PERFORM
USING

USING VALUE

VALUE Call by Value



2. Call by Reference
Call by Reference Address
Actual Parameter Memory Space Actual Parameter
Formal Parameter Actual Parameter Memory Space
Call by Reference

109

5
Modularization Logical Database
Memory Space( )

Memory Space( )

Address Passing

a1

f1

Address
a1 Pointer f1
a1
f1 a1

(Address Memory Space)

DATA a1 TYPE I VALUE 9.


PERFORM subroutine USING a1.
FORM subroutine USING f1.
f1 = 99.
WRITE f1.
ENDFORM.
PERFORM
USING

USING

USING

VALUE Call by Reference



Copy
3. Call by Value and Result
a1
f1
Call by Value and Result
Copy

Call by Value Memory Space


Copy Actual Parameter Formal Parameter
Call by Value
Copy Formal Parameter Actual Parameter
Call by Value and Result
Memory Space( )

Memory

Space( )

110

5
Modularization Logical Database
Actual Parameter Formal Parameter
Copy Actual Parameter Formal Parameter
Copy Formal Parameter Actual Parameter
f1 a1

DATA a1 TYPE I VALUE 9.


PERFORM subroutine USING a1.
FORM subroutine CHANGING f1.
f1 = 99.
WRITE f1.
ENDFORM.
PERFORM
USING

CHANGING (

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

DATA: BEGIN OF itab OCCURS 2,


tmp1(10),
tmp2 TYPE I,
END OF itab.
itab-tmp1 = First.
itab-tmp2 = 1.
APPEND itab.
itab-tmp1 = Second.
itab-tmp2 = 2.
APPEND itab.
PERFORM routine1 TABLES itab.
FORM routine1 TABLES rtab STRUCTURE itab.
LOOP AT rtab.
rtab-tmp2 = rtab-tmp2 * 10.
MODIFY rtab.
ENDLOOP.
ENDFORM.
PERFORM
TABLES Internal Table
Internal Table
TABLES Internal Table

STRUCTURE Internal Table
Formal Parameter rtab
itab Call by Reference

Factorial
Factorial
ABAP/4
Factorial

DATA: result TYPE I.

112

5
Modularization Logical Database

PARAMETERS number TYPE I.


PERFORM factorial.
WRITE: / result.
FORM factorial.
IF number <= 1.
EXIT.
ENDIF.
result = result * number.
number = number - 1.
PERFORM factorial.
ENDFORM.
External Call
External Call

PERFORM External Call

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

Import Parameter 2 t_unit degree


Reference Type
Proposal

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

DATA deg TYPE P,


displaytemp(15).
PARAMETERS: t_temp TYPE C DEFAULT F,
t_degree TYPE P DECIMALS 2.
CALL FUNCTION Z_TEST
EXPORTING
t_unit
=
t_temp
degree
=
t_degree
IMPORTING
result_degree = deg
EXCEPTIONS
incorrect = 1.
IF sy-subrc = 1.
WRITE: / Temperature unit not specified .
EXIT.
ENDIF.
IF t_temp = F.
displaytemp = Celsius.
ELSE.

115

5
Modularization Logical Database

displaytemp = Fahrenheit.
ENDIF.
WRITE:
Temperature of , t_degree
, t_temp
, is ,ZTEST2.
deg , displaytemp.
REPORT
REPORT/ ZTEST1.
Call

PARAMETERS tmp1 TYPE D.


PARAMETERS tmp TYPE D.
WRITE: / ZTEST2 Finish.
SUBMIT ZTEST2.
WRITE:
/ ZTEST1

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

ZTEST1 ZTEST1 Finish



2. Submit Report With Return
SUBMIT
SUBMIT

WITH RETURN 2
ZTEST1 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

AND RETURN ZTEST2

ZTEST1 SUBMIT

VIA SELECTION-SCREEN Selection Screen


ZTEST2

SUBMIT

START-OF-SELECTION
Transaction Transaction
2
1. Call Transaction Without Return Transaction
Transaction
LEAVE TO TRANSACTION Transaction

REPORT ZTEST.

LEAVE TO TRANSACTION SU01.


WRITE: / Report Finish.

117

5
Modularization Logical Database
ZTEST Transaction Code SU01
LEAVE TO TRANSACTION SU01 Transaction
Transaction SU01
ZTEST Report Finish

2. Call Transaction With Return Transaction


Transaction CALL
TRANSACTION Transaction

REPORT ZTEST.

CALL TRANSACTION SU01.


WRITE: / Report Finish.
ZTEST Transaction SU01
CALL TRANSACTION SU01 Transaction SU01
ZTEST Report Finish
ZTEST
Call Transaction Transaction
CALL TANSACTION


Transaction
Equipment Transaction
Equipment Transaction IE02 Equipment
Basic List

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

PARAMETER ID EQN FIELD equi-equnr



SKIP FIRST SCREEN
CALL TRANSACTION Transaction 2
Enter Transaction
Logical Database
Logical Database
SAP Database Server
Logical Database
SELECT SAP

Logical Database

Logical

Database (Separated Program)


SAP (Readonly Access)
Logical Database Logical Database
SELECT Return
Logical Database
Logical Database Logical
Database SELECT

Primary Key
SELECT Logical Database


Where Clause Logical Database Selection Screen
Selection Screen
Logical Database
Selection Screen Logical Database

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

TABLES: sflight, sbook.


SELECT * FROM sflight WHERE carrid = LH AND
connid = 19950228.
WRITE: / sflight-carrid, sflight-connid, sflight-fldate.
SELECT * FROM sbook WHERE carrid = sflight-carrid AND
connid = sflight-connid AND
fldate = sflight-fldate.
WRITE: / sbook-customid.
ENDSELECT.
ENDSELECT.

120

5
Modularization Logical Database
sflight sbook
Logical Database

TABLES: sflight, sbook.


GET sflight.
WRITE: / sflight-carrid, sflight-connid, sflight-fldate.
GET sbook.
WRITE: / sbook-customid.
Logical Database



Logical Database Logical Database
Logical Database

Attribute

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

Structure Logical database



Hierarchy

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

SELECT * FROM sflight


SELECT * FROM sbook WHERE

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

LATE GET sflight

GET sflight LATE.


WRITE: / sflight-carrid, sflight-connid, sflight-fldate.
GET sbook.
WRITE: / sbook-customid.

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

TABLES: sflight, sbook.


SELECT-OPTIONS custid FOR sbook-customid.
GET sflight.
WRITE: / sflight-carrid, sflight-connid, sflight-fldate.
GET sbook.
CHECK custid.
WRITE: / sbook-customid.
custid sbook
CHECK custid

Logical Database Logical Database

Logical
Database
Logical Database
Transaction SE36 Structure
Selection Screen Database Program
Database Program

SELECT Logical
Database

125

You might also like