Application Development Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 

writing the perfect code

Former Member
0 Kudos
111

Hi,

In your opinion, what would define the perfect code.How can we optimise our code,by using less loop statement / avoiding select * ??

Once we receive the Functional specifications,what should we keep in mind before we start wriitng the code.

Please advice.

Thanks

1 ACCEPTED SOLUTION

Former Member
0 Kudos
67

Hi,

Before u start ur coding see tht u do not make use of nested loops nor the nested select staements. u shold not use select * option because with this will fetch all the records frm the database. that is it hits the database evry time.

try avoiding loops rather try using read statements.

Later check for Slin errors and run code inspector then u can code the error free program//

Regards,

Sana.

Reward with points if found helpful//

5 REPLIES 5

Former Member
0 Kudos
68

Hi,

Before u start ur coding see tht u do not make use of nested loops nor the nested select staements. u shold not use select * option because with this will fetch all the records frm the database. that is it hits the database evry time.

try avoiding loops rather try using read statements.

Later check for Slin errors and run code inspector then u can code the error free program//

Regards,

Sana.

Reward with points if found helpful//

Kanagaraja_L
Active Contributor
0 Kudos
67

Hi Sneha,

Some of the following Points we can consider at that time of developing our code

1.Avoid using SELECT...ENDSELECT... construct and use SELECT ... INTO TABLE.

2.Use WHERE clause in your SELECT statement to restrict the volume of data retrieved.

3.Design your Query to Use as much index fields as possible from left to right in your WHERE statement

4.Either enable buffering in your database table or create Indexes to speed up the query.

5.Use FOR ALL ENTRIES in your SELECT statement to retrieve the matching records at one shot.

6.Avoid using nested SELECT statement, SELECT within LOOPs.

7.Avoid using INTO CORRESPONDING FIELDS OF TABLE. Instead use INTO TABLE.

8.Avoid using SELECT * and Select only the required fields from the table.

9.Avoid nested loops when working with large internal tables.

10. Use assign instead of into in LOOPs for table types with large work areas

11.When in doubt call transaction SE30 and use the examples and check your code

12.Whenever using READ TABLE use BINARY SEARCH addition to speed up the search. Be sure to sort the internal table before binary search.

13.Use "CHECK" instead of IF/ENDIF whenever possible.

14.Use "CASE" instead of IF/ENDIF whenever possible.

15. Use "MOVE" with individual variable/field moves instead of "MOVE-CORRESPONDING", creates more coding but is more effcient.

and some more Analysis Transactions

SM51 – App. Servers Overview

STAT – Display Statistical Records

ST05 – SQL Trace

SE30 – Runtime Analysis

ST03 – Analysis of Workload

DB02 – Database Performance : Tables and Indexes.

DB05 – Analysis of Table w.r.t. Indexed Fields

ST04 – Database Performance Analysis : Oracle View

SM66 – Global Work Process Overview (Over All App Servers)

SM50 – Process Overview

Kanagaraja L

former_member188827
Active Contributor
0 Kudos
67

first of all if u need to retrieve data from database try looking for suitable logical database program..

if u cannot find one fulfilling ur requirement, u've to write ur own select statements...

Reading multiple database tables requires careful consideration and considerable analysis to ensure

that the data retrieval is efficient.

To ensure optimal database performance, follow these general rules:

Keep the amount of selected data as small as possible. Use WHERE conditions on all SELECT

statements. Rather than accumulating values programmatically, see if you can use the SQL

aggregate functions MIN, MAX, AVG, SUM, and COUNT(*). Use the DISTINCT phrase as

opposed to an array fetch, sort, and DELETE ADJACENT DUPLICATES. Use subqueries and

HAVING clauses where appropriate. Whenever possible, pass the data filtering and

summarization off to the database engine rather than in your program logic.

Keep data transfer between the application server and the database to a minimum. Do not use

SELECT * in report programs. Instead, use a field list and ensure the fields are retrieved in the

same sequence as they are defined in the data dictionary.

Never use CORRESPONDING to move data.

Reduce the number of database inquiries and avoid nested SELECT statements.

When coding a WHERE clause, ensure that the conditions match an existing database index

whenever possible. The database optimizer can only use an index for data retrieval up to the point

where the index fields match the WHERE condition. Run a SQL trace (transaction ST05) and

evaluate the result of the SQL you coded in your program.

plz reward points if dis helps

former_member188770
Active Participant
0 Kudos
67

Hi ,

Go to transcation SE30

See Button 'Tips and Tricks'.

It is very help ful which coding.

Thanks,

Poonam.

Former Member
0 Kudos
67

Thanks for all the replies,I am closing this thread...Thanks