ABAP tips and tricks for better programming. ABAP as such is a very simple programming language and it’s very easy to learn but there are certain things which determine a good programmer from an average programmer.
- Use the CHECK command instead of an IF statement whenever possible.Â This reduces processing time and improves readability.
- Use the ON CHANGE OF command instead of developing code to compare current and previous values of a data field.
- Reduce expense by using SELECT SINGLE * FROM instead of SELECT * FROM for retrieving a table entry when the full key is known. use buffered data selecting technique rather than fetching the data from the database directly.
- Use the EXIT command to leave a loop structure as soon as a specified condition is met.Â This reduces needless loop processing.
- Use APPEND instead of COLLECT to add entries to an internal table whenever possible.Â The former command has less overhead.
- Use the AT command within loop processing whenever possible.
- Initialization Event:
This event is executed before the output of the selection screen.Â The INITIALIZATION section is only performed when the ABAP is started directly and is not executed if the ABAP is called or executed by another ABAP.Â This event is also ignored in a batch environment.Â It is frequently used to calculate special defaults for the selection screen.
- Table Loop:
Whenever looping on a table, always CLEAR the table header or fill it with a generic key before the LOOP statement.
- Structured And Modular Programming Techniques :
The use of structured and modular programming techniques, along with extensive but reasonable comments, greatly enhances the readability and maintainability of a program.
- Make use of CASE structures in place of extensive nested IFâ€™
- When one uses the MOVE statement, try to keep the destination operands as the same data type as the ‘from’ operands.
- Use the FREE <table> command once the program has completed using the table. If the program ends on completion of the table processing, this is obviously not required even though SAP has a robust garbage collection in place.
- When defining DATA statements only define variable required throughout the program as global (i.e. at the top of the program). If variables are only required for processing within a FORM/ METHODS, then define the variable within the FORM/METHODS itself.
- When using the SORT statement, always specify the sort key. Try to keep the key as short as possible.
- When processing an internal table using the LOOP instead of an SQL select statement. When using the LOOP statement use the LOOP…AT…WHERE instead of a LOOP…AT…CHECK and if possible use parallels cursors inside loops.
- When the LOOP…AT…WHERE is used ensure the condition variables have been defined with the same data type.
- Use the BINARY SEARCH, when performing a direct read on an internal table.
- Use a BINARY SEARCH read and MODIFY instead of COLLECT if the internal table is large.
- Use the CASE statement instead of a nested IF.
- lastly… Beautify the program, use the pretty printer.
- Some common errors and how to fix the errors related to SAP variants.
- Did some one create a protected variant?Â Run Program RSVARENT, this will allow you to cancel the protected variant.
- Incase if you made some changes like the field length, or changed the type, run the program RSVARFIT, it will allow you to adjust variants to modified selection criteria.
- Have any obsolete variants?Â run the program RSVARDOC
- What to find out were a particular variant is used in SAP? Run the program RSVARVAR. It will list the programs where ever the variant name is used.
- Parameter ID is a three character ID that represents specific SAP fields.Â For example, BUK is associated with Company code, GJR is associated with Fiscal Year and so..on. This saves a lot of time during transaction entries and would avoid potential data entry errors.
How to find out the Parameter IDs in SAP?Â on Any screen field, Press F1 and click on Technical Information.
You can either go to transaction SU3 or follow the path System ->user profile -> own data -> parameters and then give the parameter name and the parameter value to maintain the values.