0% found this document useful (0 votes)
65 views13 pages

SAP R/3: ABAP/4 Development Code Efficiency Guidelines

The document provides guidelines for writing efficient ABAP/4 code when developing SAP R/3 systems. It discusses optimizing code related to physical I/O, memory consumption, network communication, and other areas. Specific recommendations are given for writing efficient SELECT statements, updates, inserts, and other SQL operations. The document also briefly discusses designing secondary database indexes and logical databases.

Uploaded by

w1r41984
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
65 views13 pages

SAP R/3: ABAP/4 Development Code Efficiency Guidelines

The document provides guidelines for writing efficient ABAP/4 code when developing SAP R/3 systems. It discusses optimizing code related to physical I/O, memory consumption, network communication, and other areas. Specific recommendations are given for writing efficient SELECT statements, updates, inserts, and other SQL operations. The document also briefly discusses designing secondary database indexes and logical databases.

Uploaded by

w1r41984
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
You are on page 1/ 13

SAP R/3 : ABAP/4 Development Code Efficiency Guidelines

ABAP/4 (Advanced Business Application Programming 4GL) language is an "eventdriven", "top-down", well-structured and powerful programming language. !e ABAP/4 processor controls t!e e"ecution of an event. Because t!e ABAP/4 language incorporates man# "event" $e#words and t!ese $e#words need not %e in an# specific order in t!e code, it is wise to implement in-!ouse ABAP/4 coding standards. &AP-recommended customer-specific ABAP/4 development guidelines can %e found in t!e &AP-documentation. !is page contains some general guidelines for efficient ABAP/4 Program 'evelopment t!at s!ould %e considered to improve t!e s#stems performance on t!e following areas(

P!#sical )*+ - data must %e read from and written into )*+ devices. !is can %e a potential %ottle nec$. A well configured s#stem alwa#s runs ,)*+-%ound, - t!e performance of t!e )*+ dictates t!e overall performance. -emor# consumption of t!e data%ase resources eg. %uffers, etc. .P/ consumption on t!e data%ase and application servers 0etwor$ communication - not critical for little data volumes, %ecomes a %ottle nec$ w!en large volumes are transferred.

Policies and procedures can also %e put into place so t!at ever# &AP-customer development o%1ect is t!oroug!l# reviewed (2ualit# 3 program correctness as well as code-efficienc#) prior to promoting t!e o%1ect to t!e &AP-production s#stem. )nformation on t!e &AP 4*5 ABAP/4 'evelopment 6or$%enc! programming tools and its features can %e found on t!e &AP Pu%lic 6e%-&erver.

.LA&&). G++' 4GL P4+G4A--)0G .+'7-P4A. ).7& G/)'7L)07&


Avoid dead-code 4emove unnecessar# code and redundant processing &pend time documenting and adopt good c!ange control practices &pend ade2uate time ana#8ing %usiness re2uirements, process flows, data-structures and data-model

9ualit# assurance is $e#( plan and e"ecute a good test plan and testing met!odolog# 7"perience counts

&7L7. : ;4+- < ABL7= .>7.?( <.+0') )+0= 70'&7L7. vs.

&7L7. : ;4+- < ABL7= 6>747 <.+0') )+0= 70'&7L7.

)n order to $eep t!e amount of data w!ic! is relevant to t!e 2uer# t!e !it set small, avoid using &7L7. @.>7.? statements w!erever possi%le. As a general rule of t!um%, alwa#s specif# all $nown conditions in t!e 6>747 clause (if possi%le). )f t!ere is no 6>747 clause t!e 'B-& !as no c!ance to ma$e optimi8ations. Alwa#s specif# #our conditions in t!e 6!ere-clause instead of c!ec$ing t!em #ourself wit! c!ec$statements. !e data%ase s#stem can also potentiall# ma$e use a data%ase inde" (if possi%le) for greater efficienc# resulting in less load on t!e data%ase server and considera%l# less load on t!e networ$ traffic as well. Also, it is important to use 79 (A) in t!e 6>747 clause w!erever possi%le, and anal#8e t!e &9L-statement for t!e optimum pat! t!e data%ase optimi8er will utili8e via &9L-trace w!en necessar#. Also, ensure careful usage of "+4", "0+ " and value range ta%les ()0 are used inappropriatel# in +pen &9L statements. AB) t!at

&7L7. : vs.

&7L7. &)0GL7 :

)f #ou are interested in e"actl# one row of a data%ase ta%le or view, use t!e &7L7. &)0GL7 statement instead of a &7L7. : statement. &7L7. &)0GL7 re2uires one communication wit! t!e data%ase s#stem w!ereas &7L7. : re2uires two.

&7L7. : ;4+- < ABL7= )0 + <)0 AB= APP70' <)0 - AB= 70'&7L7. vs.

&7L7. : ;4+- < ABL7= )0 + ABL7 <)0 - AB=

)t is usuall# faster to use t!e )0 + ABL7 version of a &7L7. statement t!an to use APP70' statements

&7L7. ... 6>747 @ .>7.? vs.

&7L7. using aggregate function

)f #ou want to find t!e ma"imum, minimum, sum and average value or t!e count of a data%ase column, use a select list wit! aggregate functions instead of computing t!e aggregates wit!in t!e program. !e 4'B-& is responsi%le for aggregated computations instead of transferring large amount of data to t!e application. +verall 0etwor$, Application-server and 'ata%ase load is also considera%l# less.

&7L7. )0 + ABL7 <)0 - AB= @ L++P A BBBB &7L7. : ;4+- < ABL7= )0 + ABL7 <)0 - AB=. L++P A <)0 - AB=. 70'L++P. vs.

&7L7. : ;4+- < ABL7= BBB. 70'&7L7.

)f #ou process #our data onl# once, use a &7L7. -70'&7L7. loop instead of collecting data in an internal ta%le wit! &7L7. ... )0 + ABL7. )nternal ta%le !andling ta$es up muc! more space

0ested &7L7. statements( &7L7. : ;4+- < ABL7-A= &7L7. : ;4+- < ABL7-B= BB.. 70'&7L7. . 70'&7L7. vs.

&elect wit! view &7L7. : ;4+- <C)76= 70'&7L7.

o process a 1oin, use a view w!erever possi%le instead of nested &7L7. statements. /sing nested selects is a tec!ni2ue wit! low performance. !e inner select statement is e"ecuted several times w!ic! mig!t %e an over!ead. )n addition, fewer data must %e transferred if anot!er tec!ni2ue would %e used eg. 1oin implemented as a view in ABAP/4 4epositor#. D &7L7. ... ;+4- ALL 70 4)7& D 7"plicit cursor !andling (for more information, goto ransaction &75E 3 ips F ric$s)

0ested select( &7L7. : ;4+- pers 6>747 condition. &7L7. : ;4+- perspro1 6>747 person A pers-persnr. ... process ... 70'&7L7. . 70'&7L7. . vs.

&7L7. persnr ;4+- pers )0 + ABL7 ipers 6>747 cond. BBB. &7L7. : ;4+- perspro1 ;+4 ALL 70 4)7& )0 ipers 6>747 person A ipers-persnr BBB... process .BBBBB 70'&7L7. .

)n t!e lower version t!e new +pen &9L statement ;+4 ALL 70 4)7& is used. Prior to t!e call, all interesting records from ,pers, are read into an internal ta%le. !e second &7L7. statement results in a call loo$ing li$e t!is (ipers containing( PEG, PEH, PE5)( (&7L7. : ;4+- perspro1 6>747 person A ,PEG,) /0)+0 (&7L7. : ;4+- perspro1 6>747 person A ,PEH,) /0)+0 (&7L7. : ;4+- perspro1 6>747 person A ,PE5,) )n case of large statements, t!e 4*5,s data%ase interface divides t!e statement into several parts and recom%ines t!e resulting set to one. !e advantage !ere is t!at t!e num%er of transfers is minimi8ed and t!ere is minimal restrictions due to t!e statement si8e (compare wit! range ta%les).

&7L7. : ;4+- < ABL7= vs.

&7L7. <column(s)= ;4+- < ABL7=

/se a select list or a view instead of &7L7. :, if #ou are onl# interested in specific columns of t!e ta%le. )f onl# certain fields are needed t!en onl# t!ose fields s!ould %e read from t!e data%ase. &imilarl#, t!e num%er of columns can also %e restricted %# using a view defined in ABAP/4 'ictionar#. +verall data%ase and networ$ load is considera%l# less.

&7L7. wit!out ta%le %uffering support vs.

&7L7. wit! ta%le %uffering support

;or all fre2uentl# used, read-onl#(few updates) ta%les, do attempt to use &AP%uffering for eimproved performance response times. !is would reduce t!e overall 'ata%ase activit# and 0etwor$ traffic.

&ingle-line inserts L++P A <)0 - AB= )0&74 )0 + < ABL7= CAL/7& <)0 -

AB= 70'L++P vs.

Arra# inserts

6!enever possi%le, use arra# operations instead of single-row operations to modif# t!e data%ase ta%les ;re2uent communication %etween t!e application program and data%ase s#stem produces considera%le over!ead

&ingle-line updates &7L7. : ;4+- < ABL7= <.+L/-0-/P'A 7 & A 7-70 = /P'A 7 < ABL7= 70'&7L7. vs.

.olumn updates /P'A 7 < ABL7= &7 <.+L/-0/P'A 7 & A 7-70 =

6!erever possi%le, use column updates instead of single row updates to update #our data%ase ta%les

'+....70''+ loop wit! ;ield-&#m%ol vs.

/sing .A operator

/se t!e special operators .+, .A, .& instead of programming t!e operations #ourself )f ABAP/4 statements are e"ecuted per c!aracter on long strings, .P/ consumprion can rise su%stantiall#

/se of a .+0.A 70A 7 function module vs.

/se of a .+0.A 70A 7 statement

&ome function modules for string manipulation !ave %ecome o%solete, and s!ould %e replaced %# ABAP statements or functions

& & & & &

4)0GI.+0.A 70A 7... ---= .+0.A 70A 7 4)0GI&PL) ... ---= &PL) 4)0GIL70G >... ---= strlen() 4)0GI.70 74... ---= 64) 7.. +. ...70 747' 4)0GI-+C7I4)G> ---= 64) 7... +...4)G> -J/& );)7'

-oving wit! offset vs.

/se of t!e .+0.A 70A 7 statement

/se t!e .+0.A 70A 7 statement instead of programming a string concatenation of #our own

/se of &7A4.> and -+C7 wit! offset vs.

/se of &PL) statement

/se t!e &PL) statement instead of programming a string split #ourself

&!ifting %# &K-;'P+& places vs

/sing &>); ...L7; '7L7 )0G L7A')0G...

)f #ou want ot delete t!e leading spaces in a string use t!e ABAP/4 statements &>); ...L7; '7L7 )0G L7A')0G... +t!er constructions (wit! .0 and &>); ... BK &K-;'P+& PLA.7&, wit! .+0'70&7 if possi%le, wit! .0 and A&&)G0 .LA@&K-;'P+&(L70) ...) are not as fast

Get a c!ec$-sum wit! field lengt! vs

Get a c!ec$-sum wit! strlen ()

/se t!e strlen () function to restrict t!e '+ loop to t!e relevant part of t!e field, eg.

w!en determinating a c!ec$-sum

Quick ote on Desi!n of second"#y d"t"$"se inde%es


;irst it must %e stated t!at ta%le design is a more logical wor$ w!ile inde" design is rat!er tec!nical. )n ta%le design it mig!t ma$e sense to place certain fields (client, compan# code, ...) in t!e %eginning. )n inde" design, t!is is not advisa%le. Cer# important for an inde" is t!at it contains ver# selective fields in t!e %eginning. !ose are fields li$e o%1ect num%ers. 0ot selective are client, compan# code, ...

)nde"es s!ould %e small (few fields). more inde"es to e"ecute a 2uer#.

!e 'ata%ase optimi8er can com%ine two or

)nde"es of one ta%le s!ould %e dis1oint (!ave few common fields), in order not to confuse t!e optimi8er w!ic! inde" to use.

0ote t!at eac! inde" slows t!e inserts into t!e ta%le down. /pdates are onl# slowed down if inde"ed fields are updated. )n general, !eav# inserted ta%les s!ould !ave onl# few inde"es w!ile !eav# selected ta%les mig!t !ave more.

Quick ote on Desi!n of lo!ic"l d"t"$"ses


/sing logical data%ases is a good met!od to write reports. Logical data%ases can %e optimi8ed centrall#. But ensure t!at t!e structure of t!e logical data%ase fits well to #our report. +t!erwise t!e effect can %e t!e opposite. ;or more information a%out more &AP ABAP/4 'evelopment code-efficienc# standards, esp. on non-data%ase related tips and tric$s, please goto transaction &75E and clic$ on ips F ric$s section, w!ic! served as t!e main source of reference for t!is section of t!is document.

Cisit m# !omepage

Thanks for stopping by. 7-mail some reall# cool stuff to

aut!or

You might also like