2007 Jul 02 7:24 PM
I can think of the following coding practises which will avoid any pitfalls in terms of performance and defects. If you can think of any other please let me know
1.Avoid writing a select condition in Loop endloop.
Try retrieving all entries before the loop , and instead use READ table.
2.Before using for all entries make sure you sort the table by field1
and delete duplicates comparing field1.
3.Before using read table with binary search , make sure the table is sorted.
4.Avoid using direct updates to table, if yes try using enque ,
dequee function modules
5.Avoid using check statements in user exits,Use IF statements.
6.When write commands used with currency or quantity fields,
make sure appropriate additions added.
7.If some data is being updated in SAP database tables then try updating
them using function module which has Update task enabled.
8.Checking of sy-subrc outside a function module call with all exceptions
commented will always return sy-subrc = 0.Hence never do that.
9.Use EQ/GT/LE instead of =/ > / <
10.Avoid move-corresponding.
11.Avoid into corresponding fields
12.Is select single used with all key fields,
if all fields cannot be specified then use select upto 1 rows.
13.Use select into table is used instead of select and then append
14.Use Function module XXX_SINGLE_READ (i.e.: -MARA_SINGLE_READ) instead of
reading of material directly from XXX (i.e.: - MARA) using SELECT SINGLE
15.Avoid using Select Endselect.
16.Clear internal tables and variables( Free Memories)
I can think of the following coding practises which will avoid any pitfalls in terms of performance and defects. If you can think of any other please let me know
1.Avoid writing a select condition in Loop endloop.
Try retrieving all entries before the loop , and instead use READ table.
2.Before using for all entries make sure you sort the table by field1
and delete duplicates comparing field1.
3.Before using read table with binary search , make sure the table is sorted.
4.Avoid using direct updates to table, if yes try using enque ,
dequee function modules
5.Avoid using check statements in user exits,Use IF statements.
6.When write commands used with currency or quantity fields,
make sure appropriate additions added.
7.If some data is being updated in SAP database tables then try updating
them using function module which has Update task enabled.
8.Checking of sy-subrc outside a function module call with all exceptions
commented will always return sy-subrc = 0.Hence never do that.
9.Use EQ/GT/LE instead of =/ > / <
10.Avoid move-corresponding.
11.Avoid into corresponding fields
12.Is select single used with all key fields,
if all fields cannot be specified then use select upto 1 rows.
13.Use select into table is used instead of select and then append
14.Use Function module XXX_SINGLE_READ (i.e.: -MARA_SINGLE_READ) instead of
reading of material directly from XXX (i.e.: - MARA) using SELECT SINGLE
15.Avoid using Select Endselect.
16.Clear internal tables and variables( Free Memories)
2007 Jul 02 8:31 PM
Are you doing some sort of Answer's Database?
Anyway -:)
Instead of doing CLEAR and REFRESH for Internal Table...Use this macro...
DEFINE CLEAN.
CLEAR &1
REFRESH &1
END-OF-DEFINITION.
CLEAN MY_TABLE.
Can't think of anything else right now -;)
Greetings,
Blag.
2007 Jul 02 8:41 PM
what would be the advantage to the macro instead? I thought SAP was moving away from using macros.
2007 Jul 02 8:48 PM
That's right, macros are not really the direction SAP would like its developers to go in. They are good when you want to take some logic and shrink it into one-liners, but the logic must be 100% and simply, because you can not debug a macro. Lesson here, use them sparingly, and intelligently.
In Blag's example, this is a situation where I think that it is ok, because it is simple. But again, there is no reason why you could write both statements on one line as I commonly do.
clear itab. refresh itab.Regards,
Rich Heilman
2007 Jul 02 9:38 PM
Well....I might be kinda lazy -:) Anyway, that's the only macro I use...You don't need to Debug a CLEAR/REFRESH right? LOL
Greetings,
Blag.
2009 Mar 01 7:03 PM
2009 Mar 01 7:08 PM
>
> Any more insights into this ?
> Ajay
Sure - search the forum
Rob
Edited by: Rob Burbank on Mar 2, 2009 9:32 AM
2007 Jul 02 8:59 PM
Hi,
- Avoid Using SELCT *
- Always check sy-subrc after SELECT, READ etc.
- Avoid Joins
- Try to use unique composite keys while fetching data from database
- Mention Appropriate Comments
- Use BAPI's instead of direct OPEN SQL statements for database operations
- Try to avoid internal tables with header lines
- Use work area
- Use Pretty Printer
- Use Extended Program Check
- Use Code Inspector
Regards,
Mukul
2009 Mar 02 9:18 PM
"Avoid Joins"
performence is okay and its recommended, right?
some more points,
-- before using of FOR ALL ENTRIES; pl. check weather the itab has any content or not?
-- DONT DIVIDE WITH ZERO check
-- go with text elements
-- go woth constants, instead of hard coding
-- avoide usage of STOP
-- perform input check against selection criteria
-- dont throw error messages in batch jobs
-- if there language dependent data records in any DB table, like MAKT, use sy-langu in WHERE cluse
-- some times, u need to prefix the zeros to the MATNR, cost center, intenal order etc. fields, while using these in WHER clause
-- dont write logic by depending on sy-tcode for BATCH JOBS
thanq
Edited by: SAP ABAPer on Mar 2, 2009 10:46 PM