You are on page 1of 12

Performance tuning and control statements.

Run-time analysis
+ -
Run-time analysis is used to check the efciency of a program or function module
or t-code in terms of what is the load on the database server, application server,
presentation server etc.
The run-time analysis will display the load in a graph with !s and the time in
micro seconds.
The graph will be displayed with either red color or green color.
"f the graph contains green color, then the program e#ecution time is very good
or very less.
"f the graph contains red color, the program e#ecution time is very bad or very
long .
$lways make sure the the load on database server should be less than %& and
should be green.
T-code for run-time analysis is '()& or '$T*+atest ,ersions-.
(#ample program on run time analysys in '$P $.$P
Program/0 1reate a program to get 2$R$ details and display as below.
R(P3RT 4'$56'()&.
77Runtime analysis using '()&
8$T$ 0 "T62$R$ T9P( T$.+( 3: 2$R$.
8$T$ 0 ;$62$R$ T9P( 2$R$.
'(+(1T 7 :R32 2$R$ "5T3 T$.+( "T62$R$ <P T3 =&& R3;'.
+33P $T "T62$R$ "5T3 ;$62$R$.
;R"T(0> ;$62$R$-2$T5R, ;$62$R$-2T$RT, ;$62$R$-2.R'?, ;$62$R$-2$T@+,
;$62$R$-2("5'.
(58+33P.
Ao to '()&, provide program name, click on e#ecute button, the out put will bi
displayed, click on back and click on evaluate to see run-time analysis.
The result will be like below*may vary based on server capacity-.
"n the above image you can see $.$P and database layers are in red color, means the
time taken to process these layers is more.
Program0B
5ow change the above program like below and test again.
R(P3RT 4'$56'()&.
T9P('0 .(A"5 3: T962$R$,
2$T5R T9P( 2$R$-2$T5R,
2T$RT T9P( 2$R$-2T$RT,
2.R'? T9P( 2$R$-2.R'?,
2$T@+ T9P( 2$R$-2$T@+,
2("5' T9P( 2$R$-2("5',
(58 3: T962$R$.
77Runtime analysis using '()&
8$T$ 0 "T62$R$ T9P( T$.+( 3: T962$R$.
8$T$ 0 ;$62$R$ T9P( ty62$R$.
'(+(1T 2$T5R 2T$RT 2.R'? 2$T@+ 2("5' :R32 2$R$ "5T3 T$.+( "T62$R$ <P T3 =&&
R3;'.
+33P $T "T62$R$ "5T3 ;$62$R$.
;R"T(0> ;$62$R$-2$T5R, ;$62$R$-2T$RT, ;$62$R$-2.R'?, ;$62$R$-2$T@+,
;$62$R$-2("5'.
(58+33P.
5ow go to '()& and follow the above process.
5ow the evaluation will be like below.
9ou can see the database layer is in green color means the standards are good.
$ good program with coding standards always have database layers is in green color
'T&= is a T-code which is used to trace performance of '$P 3bCects, things we can done
using 'T&= are below.
'D+ Trace which is used to trace time e#ecution for open 'D+ statements like
select, insert, update, delete etc.
(nEueue Trace which is used to trace locking and unlocking of lock obCects.
.uFer Trace, this is used to monitor table buFer accesses.
R:1 Trace, this is used to trace remote calls made of a application.
?TTP Trace which is used to trace ?TTP reEuests*e#0 browser reEuests- of '$P
applications.
To perform trace operations go to 'T&=, select trace, activate trace, open another
session and e#ecute the application which we wants to trace, comeback to 'T&=,
deactivate the trace and display the trace.
+ -
Programming Standard Bad example Good example
5ever use select 7, always
use select with list of
Gelds because if you use
select 7 it will get all
columns from database, if
you use select list of Gelds
it will get selected
columns only.
'(+(1T 7 :R32 2$R$
"5T3 T$.+( ...
'(+(1T 2$T5R 2T$RT 2("5'
2.R'? :R32 2$R$ ..
$lways specify key Gelds
in where condition,
because it will be having
primary inde#.
'(+(1T 7 :R32 2$R$
"5T3 T$.+( "T62$R$
;?(R( 2T$RT H !:(RT!.
'(+(1T 2$T5R 2T$RT 2("5'
:R32 2$R$
"5T3 T$.+( "T62$R$
;?(R( 2$T5R H !&&&/!.
'ome times we may need
to use non-key Gelds in
where condition, in such
cases create secondary
inde# to improve
performance.

5ever use select with
corresponding .
'(+(1T 7 :R32 2$R$
"5T3 13RR('P358"5A :"(+8'
3: T$.+( "T62$R$.
'(+(1T 2$T5R 2T$RT 2("5'
:R32 2$R$
"5T3 T$.+( "T62$R$.
$lways use read table key
with binary search, binary
search will improve
performance.
R($8 T$.+( "T62$R$ "5T3
;$62$R$ ;"T? @(9 2$T5R H
!&&/!
."5$R9 '($R1?.
R($8 T$.+( "T62$R$ "5T3
;$62$R$ ;"T? @(9 2$T5R H
!&&/!.
$void using select Coins
for more than ) database
tables.
'elect Ioins in '$P $.$P <sing select for all entries
$lways use select for all
entries for more than
three tables.
'elect Ioins in '$P $.$P <sing select for all entries
;hen using select for all
entries, check whether
the parent internal table
is initial or not .
'(+(1T 7 :R32 2$@T
"5T3 "T62$@T
:3R $++ (5TR"(' "5
"T62$R$
;?(R( 2$T5R H "T62$R$-
2$T5R.
": "T62$R$ "' 53T "5"T"$+.
'(+(1T 7 :R32 2$@T "5T3
"T62$@TJbrK :3R $++ (5TR"('
"5 "T62$R$JbrK ;?(R(
2$T5R H "T62$R$-2$T5R.
(58":.
Programming Standard Bad example Good example
5ever use nested loops.
+33P $T "T62$R$ "5T3
;$62$R$.
+33P $T "T62$@T "5T3
;$62$@T.
(58+33P.JbrK(58+33P.JbrK
+33P $T "T62$R$ "5T3
;$62$R$.JbrKR($8 T$.+(
"T62$@T "5T3 ;$62$@T ;?(R(
2$T5R H ;$62$R$-
2$T5R.JbrKJbrK(58+33P.
5ever use select
statements inside loops .
JbrK+33P $T "T62$R$ "5T3
;$62$R$.JbrK'(+(1T 7 :R32
2$@T ...JbrKJbrK(58+33P.
"5'T($8 <'( :3R $++ (5TR"('
+ -
The Grst thing that comes into the mind of a good $.$Per is performance of his obCect,
the main problem for performance issues are bad 'elect statements e#0 select Coins for
more than ) tables, nested +oops, how ever there is a concept of parallel cursor in '$P
$.$P to avoid performance issues with nested loops with where condition.
To understand parallel cursor, follow and understand the below programs.
Program without parallel cursor
R(P3RT 4'$56P$R$++(+61<R'(R.
T9P('0 .(A"5 3: T962$R$,
2$T5R T9P( 2$R$-2$T5R,
2T$RT T9P( 2$R$-2T$RT,
2.R'? T9P( 2$R$-2.R'?,
2$T@+ T9P( 2$R$-2$T@+,
2("5' T9P( 2$R$-2("5',
(58 3: T962$R$.
8$T$ 0 "T62$R$ T9P( T$.+( 3: T962$R$,
;$62$R$ T9P( T962$R$.
T9P('0 .(A"5 3: T962,@(,
2$T5R T9P( 2,@(-2$T5R,
,@3RA T9P( 2,@(-,@3RA,
,T;(A T9P( 2,@(-,T;(A,
(58 3: T962,@(.
8$T$ 0 "T62,@( T9P( T$.+( 3: T962,@(,
;$62,@( T9P( T962,@(.
'(+(1T
2$T5R
2T$RT
2.R'?
2$T@+
2("5' :R32 2$R$ "5T3 T$.+( "T62$R$ <P T3 =&& R3;'.
'3RT "T62$R$.
8(+(T( $8I$1(5T 8<P+"1$T(' :R32 "T62$R$ 132P$R"5A $++ :"(+8'.
'(+(1T 2$T5R
,@3RA
,T;(A :R32 2,@( "5T3 T$.+( "T62,@(
:3R $++ (5TR"(' "5 "T62$R$ ;?(R( 2$T5R H "T62$R$-2$T5R.
+33P $T "T62$R$ "5T3 ;$62$R$.
+33P $T "T62,@( "5T3 ;$62,@( ;?(R( 2$T5R H ;$62$R$-2$T5R.
;R"T(0> ;$62$R$-2$T5R, ;$62$R$-2T$RT, ;$62$R$-2$T@+, ;$62,@(-,@3RA,
;$62,@(-,T;(A.
(58+33P.
(58+33P.
Program with parallel cursor.
R(P3RT 4'$56P$R$++(+61<R'(R.
T9P('0 .(A"5 3: T962$R$,
2$T5R T9P( 2$R$-2$T5R,
2T$RT T9P( 2$R$-2T$RT,
2.R'? T9P( 2$R$-2.R'?,
2$T@+ T9P( 2$R$-2$T@+,
2("5' T9P( 2$R$-2("5',
(58 3: T962$R$.
8$T$ 0 "T62$R$ T9P( T$.+( 3: T962$R$,
;$62$R$ T9P( T962$R$.
T9P('0 .(A"5 3: T962,@(,
2$T5R T9P( 2,@(-2$T5R,
,@3RA T9P( 2,@(-,@3RA,
,T;(A T9P( 2,@(-,T;(A,
(58 3: T962,@(.
8$T$ 0 "T62,@( T9P( T$.+( 3: T962,@(,
;$62,@( T9P( T962,@(.
'(+(1T
2$T5R
2T$RT
2.R'?
2$T@+
2("5' :R32 2$R$ "5T3 T$.+( "T62$R$ <P T3 =&& R3;'.
'3RT "T62$R$.
8(+(T( $8I$1(5T 8<P+"1$T(' :R32 "T62$R$ 132P$R"5A $++ :"(+8'.
'(+(1T 2$T5R
,@3RA
,T;(A :R32 2,@( "5T3 T$.+( "T62,@(
:3R $++ (5TR"(' "5 "T62$R$ ;?(R( 2$T5R H "T62$R$-2$T5R.
'3RT0 "T62$R$, "T62,@(.
8$T$ ,6"58(L T9P( '9-T$."L.
+33P $T "T62$R$ "5T3 ;$62$R$.
R($8 T$.+( "T62,@( "5T3 ;$62,@( ;"T? @(9 2$T5R H ;$62$R$-2$T5R ."5$R9
'($R1?.
": '9-'<.R1 H &.
,6"58(L H '9-T$."L.
+33P $T "T62,@( "5T3 ;$62,@( :R32 ,6"58(L. Mno where condition for loop
": ;$62,@(-2$T5R JK ;$62$R$-2$T5R.
(L"T.
(58":.
;R"T(0> ;$62$R$-2$T5R, ;$62$R$-2T$RT, ;$62$R$-2$T@+, ;$62,@(-,@3RA,
;$62,@(-,T;(A.
(58+33P.
(58":.
1+($R0 ;$62$R$, ;$62,@(.
(58+33P.
/. ;hen reading data from database table, never use '(+(1T 7,
always use select with list of Gelds.
B. $lways specify key Gelds in where conditions of '(+(1T
statements, because these will have primary inde#.
). 'ometimes we may need to use non-key Gelds in where
conditions of '(+(1T statements, in that case create
secondary inde#es and use.
%. 5ever use select with corresponding in '(+(1T statements.
=. $lways use read table with binary search and make you have
sorted the internal table in ascending order before using read
table binary search.
N. 5ever use select Coins for more than ) tables.
O. $lways use select for all entries for more than ) tables.
P. $lways check whether the parent internal table is initial or not
before using for all entries.
Q. 5ever use nested loops, instead use parallel cursor .
/&. 5ever use select statements inside loops, instead use for
all entries.
$lso read performance truing in '$P $.$P programming , binary search mechanism in
'$P $.$P
1ontrol break statements are statements which are used to control the seEuence of
e#ecution of statements with in loop.....endloop.
These statements are e#ecuted only with in loop...endloop.
1ontrol break statements are
$T :"R'T - This statement is e#ecuted>triggered for the Grst iteration of loop *'9-T$."L H
/ -.
$T +$'T - This statement is e#ecuted>triggered for the last iteration of loop.
$T 5(; JGeld nameK - This is e#ecuted when ever there is a new value on speciGed Geld.
$T (58 3: JGeld nameK - This statement is e#ecuted whenever the new value ends on
speciGc Geld.
35 1?$5A( 3: JGeld nameK - "t is same as $T 5(; and is obsolete in (11 N.&.
Requirement: 8evelop a report to display list of sales orders with totals and page sub-
totals for a particular date.
'election-screen 0 input date.
SUM 0 '<2 is a key word which is used to add numerical values of a Geld in control
break statements.
R(P3RT 4'$P56135TR3+6.R($@.
T9P(' 0 .(A"5 3: T96,.$P,
,.(+5 T9P( ,.$P-,.(+5,
2$T5R T9P( ,.$P-2$T5R,
42(5A T9P( ,.$P-42(5A,
5(TPR T9P( ,.$P-5(TPR,
(58 3: T96,.$P.
8$T$ 0 "T6,.$P T9P( T$.+( 3: T96,.$P.
8$T$ 0 ;$6,.$P T9P( T96,.$P.
P$R$2(T(R' 0 P68$T( T9P( ,.$P-(R8$T .
'T$RT-3:-'(+(1T"35.
'(+(1T ,.(+5 2$T5R 42(5A 5(TPR
:R32 ,.$P "5T3 T$.+( "T6,.$P
;?(R( (R8$T H P68$T(.
+33P $T "T6,.$P "5T3 ;$6,.$P.
$T :"R'T .
;R"T( 0>B !'$+(' 831!, /P !2$TR"$+!, BP!D<$5T"T9!, %& !PR"1(!.
(58$T.
$T 5(; ,.(+5.
;R"T( 0>B ;$6,.$P-,.(+5, /P ;$6,.$P-2$T5R, BP ;$6,.$P-42(5A, %& ;$6,.$P-
5(TPR.
(58$T.
$T (58 3: ,.(+5.
'<2.
;R"T( 0>B) !'<. T3T$+ "' 0! 13+3R N, ;$6,.$P-5(TPR.
(58$T.
$T +$'T.
'<2.
;R"T(0>B) !Total is0!, ;$6,.$P-5(TPR .
(58$T.
(58+33P.