EFFECTIVE CODING IN ABAP 1

Posted by Krishh Webworld | 6:26 PM | | 0 comments »

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


ABAP/4 (Advanced Business Application Programming 4GL) language is an "event-driven", "top-down", well-structured and powerful programming language. The ABAP/4 processor controls the execution of an event. Because the ABAP/4 language incorporates many "event" keywords and these keywords need not be in any specific order in the code, it is wise to implement in-house ABAP/4 coding standards.


SAP-recommended customer-specific ABAP/4 development guidelines can be found in the SAP-documentation. This page contains some general guidelines for efficient ABAP/4 Program Development that should be considered to improve the systems performance on the following areas:-


• Physical I/O - data must be read from and written into I/O devices. This can be a potential bottle neck. A well configured system always runs 'I/O-bound' - the performance of the I/O dictates the overall performance.


• Memory consumption of the database resources eg. buffers, etc.
• CPU consumption on the database and application servers
• Network communication - not critical for little data volumes, becomes a bottle neck when large volumes are transferred.


Policies and procedures can also be put into place so that every SAP-customer development object is thoroughly reviewed (quality – program correctness as well as code-efficiency) prior to promoting the object to the SAP-production system.

CLASSIC GOOD 4GL PROGRAMMING CODE-PRACTICES GUIDELINES


Avoid dead-code
Remove unnecessary code and redundant processing
Spend time documenting and adopt good change control practices
Spend adequate time anayzing business requirements, process flows, data-structures and data-model

Quality assurance is key: plan and execute a good test plan and testing methodology


SELECT * FROM TABLE
CHECK: CONDITION
ENDSELECT
vs.


SELECT * FROM TABLE
WHERE CONDITION
ENDSELECT



In order to keep the amount of data which is relevant to the query the hit set small, avoid using SELECT+CHECK statements wherever possible. As a general rule of thumb, always specify all known conditions in the WHERE clause (if possible). If there is no WHERE clause the DBMS has no chance to make optimizations.

Always specify your conditions in the Where-clause instead of checking them yourself with check-statements. The database system can also potentially make use a database index (if possible) for greater efficiency resulting in less load on the database server and considerably less load on the network traffic as well.


Also, it is important to use EQ (=) in the WHERE clause wherever possible, and analyze the SQL-statement for the optimum path the database optimizer will utilize via SQL-trace when necessary.


Also, ensure careful usage of "OR", "NOT" and value range tables (INTTAB) that are used inappropriately in Open SQL statements.



SELECT *
vs.


SELECT SINGLE *

If you are interested in exactly one row of a database table or view, use the SELECT SINGLE statement instead of a SELECT * statement. SELECT SINGLE requires one communication with the database system whereas SELECT * requires two.



SELECT * FROM TABLE INTO INT-TAB
APPEND INT-TAB
ENDSELECT
vs.


SELECT * FROM TABLE INTO TABLE INT-TAB

It is usually faster to use the INTO TABLE version of a SELECT statement than to use APPEND statements



SELECT ... WHERE + CHECK
vs.


SELECT using aggregate function

If you want to find the maximum, minimum, sum and average value or the count of a database column, use a select list with aggregate functions instead of computing the aggregates within the program. The RDBMS is responsible for aggregated computations instead of transferring large amount of data to the application. Overall Network, Application-server and Database load is also considerably less.



SELECT INTO TABLE INT-TAB + LOOP AT T
…………
SELECT * FROM TABLE INTO TABLE INT-TAB.
LOOP AT INT-TAB.
ENDLOOP.

vs.


SELECT * FROM TABLE
……….
ENDSELECT


If you process your data only once, use a SELECT-ENDSELECT loop instead of collecting data in an internal table with SELECT ... INTO TABLE. Internal table handling takes up much more space



Nested SELECT statements:
SELECT * FROM TABLE-A
SELECT * FROM TABLE-B
……..
ENDSELECT.
ENDSELECT
vs.


Select with view
SELECT * FROM VIEW
ENDSELECT

To process a join, use a view wherever possible instead of nested SELECT statements.


Using nested selects is a technique with low performance. The inner select statement is executed several times which might be an overhead. In addition, fewer data must be transferred if another technique would be used eg. join implemented as a view in ABAP/4 Repository.


• SELECT ... FORM ALL ENTRIES
• Explicit cursor handling


Nested select:
SELECT * FROM pers WHERE condition.
SELECT * FROM persproj WHERE person = pers-persnr.
... process ...
ENDSELECT.
ENDSELECT.

vs.


SELECT persnr FROM pers INTO TABLE ipers WHERE cond. ……….
SELECT * FROM persproj FOR ALL ENTRIES IN ipers
WHERE person = ipers-persnr
………... process .……………
ENDSELECT.


In the lower version the new Open SQL statement FOR ALL ENTRIES is used. Prior to the call, all interesting records from 'pers' are read into an internal table. The second SELECT statement results in a call looking like this (ipers containing: P01, P02, P03):

(SELECT * FROM persproj WHERE person = 'P01')
UNION
(SELECT * FROM persproj WHERE person = 'P02')
UNION
(SELECT * FROM persproj WHERE person = 'P03')

0 comments

Archives

Subscribe Now: Feed Icon