SELECT STATEMENT| SAP ABAP TRICKS AND TIPS| STRING OPERATIONS
1 Select Where clause
Always mention your conditions with the Where-clause in select statement instead of checking with check keyword in select statement. The database system can use an index (if it’s possible) then load is considerably less.
2 Select statement with Index keyword Support
For all frequently used Select statements try to use index keyword or index number. If you always use an index, you are specifying the index fields concatenated with logical operators in the select statements with where clause.
complex where clause condition is hazardous for the statement optimizer in any database system.
3 Select single statement V/S Select-End select statement
If single record exists in database table or view with a certain condition, use select single statement with where clause instead of select end select loop because select single run only one time and select end select loop run for the same at least two times due to this process time will increase. Or in other words select single requires one time communication with the database system, whereas select end select needs two-time communication with the database system.
4 Select Into table (Internal table name)
It is always good to use Into Table (Internal table) version of a select statement than the Append statements. By into table (Internal table) version all records inserted in once according to condition instead on using append statements which will add all records in table one by one.
5 Select aggregates functions
If you want to find the maximum, minimum, sum and average value or the count of records from a table in database system. Use selects with aggregate functions instead of computing the aggregates value. Database load considerably less.
6 Select End select V/S Array Select
In your code or according to your requirements your process will run only once of retrieve data from the table then use select end select loop instead of storing data into an internal table then processing the internal table for required process. Internal table handling will take much more space.
7 Select from database table or select from database view
Retrieving data from the multiple tables using join statement, instead of join use database view of those multiple tables if exist. It will table considerably less time to process the statement.
8 Select with field lists
Use a select fields name or a view instead of select * from table name, if you are only interested in specific fields of the table.
9 Array insert V/S Single-row Insert
If possible, use array operations instead of single-row operations to modify or insert data in your database tables. Frequent communication between the application program and database system generates considerable overhead.
10 Using subqueries
If you are using select * from table name into internal table for all entries in internal table to proceed in any process and if possible, to avoid select for all entries and can use subqueries then process the same with subqueries.
STRING MANIPULATIONS/ STRING OPERATIONS
1 Special Operators in If (CA, CO, CP, CN, NA)
Use the special string operators CO, CA, CP, CN, NA instead of programming logic.
CA: CA stands for Contains Any: If variable1 contains at least one character from variable2 then it will return true. Upper/lower case and trailing blanks are considered for both variables.
CP: CP stands Covers Pattern: If the content of variable1 fits the pattern in variable2 then it will return true.
CO: CO stands Contains Only: If varialbe1 only contains characters from variable2 then it will return true.
CN: CN stands Contains Not Only: If variable1 not contains characters from variable2 then it will return true.
NA: NA stands Contains Not Any: If variable1 does not contain any characters from variable2 then it will return true.
2 String Concatenation
Some function modules for string manipulation and string operations have become obsolete and replaced by ABAP/4 statements and functions. Use CONCATENATE keyword instead of programming logic to concatenation of string.
3 Shift deleting leading spaces
We can use Shift statement or Shift keyword only for character fields such as which data type is C, N, D, T, and string only.
If we want to delete the leading spaces in a string or character fields, we can use ABAP/4 statement or Keyword SHIFT LEFT DELETING LEADING.
Shift Field name left deleting leading spaces.
avoid using SHIFT inside a While Loop.
4 String Split Statement
Use the SPLIT statement/Keyword to split the string or character fields instead of programming logic.
5 String Length Statement
To get length of your string or character fields use STRLEN () function instead of writing a program to get length of your string or character fields.
SOME OTHER KEYWORDS/ STATEMENT
To clear or delete the data from any field or work area we will use Clear keyword/Statement.
Using an Explicit Work Area instead of filling the data into header line
To avoid unwanted MOVE statements use explicit work area operations
APPEND work area TO internal table
INSERT work area INTO internal table
COLLECT work area INTO internal table.
MODIFY internal table FROM work area.
READ TABLE internal table INTO work area.
LOOP AT internal table INTO work area.
Linear Search VS Binary Search
If internal tables have many (Greater than 20 records) entries, a linear search through all records is very time-consuming, try to keep the internal table in sorted ordered and use binary search use internal table type SORTED TABLE.
Creating a Secondary Index to avoid Linear Search
If you want to access an internal table with different keys continuously, keep your own secondary index. With the help of secondary index you can replace linear search with binary search plus an index access.
Key Access to multiple Lines Loop/Check V/S Loop with Where clause
LOOP with WHERE clause is faster than LOOP/CHECK because LOOP with WHERE clause evaluates the condition internally with any logical expressions.
Thanks For Visit!!!!