This action might not be possible to undo. Are you sure you want to continue?
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. Information on the SAP R/3 ABAP/4 Development Workbench programming tools and its features can be found on the SAP Public Web-Server. 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 • Experience counts 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
The RDBMS is responsible for aggregated computations instead of transferring large amount of data to the application. WHERE + CHECK vs. Always specify your conditions in the Where-clause instead of checking them yourself with check-statements. . minimum. SELECT SINGLE requires one communication with the database system whereas SELECT * requires two. use the SELECT SINGLE statement instead of a SELECT * statement. and analyze the SQL-statement for the optimum path the database optimizer will utilize via SQL-trace when necessary. ensure careful usage of "OR". Overall Network. SELECT * FROM <TABLE> INTO <INT-TAB> APPEND <INT-TAB> ENDSELECT vs. SELECT using aggregate function If you want to find the maximum. SELECT * vs. it is important to use EQ (=) in the WHERE clause wherever possible. Also.known conditions in the WHERE clause (if possible). use a select list with aggregate functions instead of computing the aggregates within the program. If there is no WHERE clause the DBMS has no chance to make optimizations. Application-server and Database load is also considerably less. "NOT" and value range tables (INTTAB) that are used inappropriately in Open SQL 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. SELECT SINGLE * If you are interested in exactly one row of a database table or view. SELECT * FROM <TABLE> INTO TABLE <INTTAB> It is usually faster to use the INTO TABLE version of a SELECT statement than to use APPEND statements SELECT . Also. sum and average value or the count of a database column.
. Internal table handling takes up much more space Nested SELECT statements: SELECT * FROM <TABLE-A> SELECT * FROM <TABLE-B> ……. Using nested selects is a technique with low performance. INTO TABLE... ENDSELECT If you process your data only once.SELECT INTO TABLE <INT-TAB> + LOOP AT T ………… SELECT * FROM <TABLE> INTO TABLE <INTTAB>. ENDLOOP. ENDSELECT. fewer data must be transferred if another technique would be used eg. The inner select statement is executed several times which might be an overhead. SELECT * FROM persproj WHERE person = pers-persnr. use a view wherever possible instead of nested SELECT statements. . join implemented as a view in ABAP/4 Repository. FORM ALL ENTRIES · Explicit cursor handling (for more information. ENDSELECT.. vs. use a SELECT-ENDSELECT loop instead of collecting data in an internal table with SELECT .. Select with view SELECT * FROM <VIEW> ENDSELECT To process a join... vs. process . . · SELECT . SELECT * FROM <TABLE> ……….. ENDSELECT vs. LOOP AT <INT-TAB>. In addition. ENDSELECT.. goto Transaction SE30 – Tips & Tricks) Nested select: SELECT * FROM pers WHERE condition.
SELECT with table buffering support For all frequently used. This would reduce the overall Database activity and Network traffic. The second SELECT statement results in a call looking like this (ipers containing: P01. If only certain fields are needed then only those fields should be read from the database. all interesting records from 'pers' are read into an internal table. ………. SELECT without table buffering support vs.…………… ENDSELECT. if you are only interested in specific columns of the table. Single-line inserts .. the number of columns can also be restricted by using a view defined in ABAP/4 Dictionary. do attempt to use SAP-buffering for eimproved performance response times.SELECT persnr FROM pers INTO TABLE ipers WHERE cond. SELECT * FROM <TABLE> vs. SELECT <column(s)> FROM <TABLE> Use a select list or a view instead of SELECT *. read-only(few updates) tables. P02. Similarly. The advantage here is that the number of transfers is minimized and there is minimal restrictions due to the statement size (compare with range tables).. Prior to the call. P03): (SELECT * FROM persproj WHERE person = 'P01') UNION (SELECT * FROM persproj WHERE person = 'P02') UNION (SELECT * FROM persproj WHERE person = 'P03') In case of large statements. SELECT * FROM persproj FOR ALL ENTRIES IN ipers WHERE person = ipers-persnr ………. process . Overall database and network load is considerably less. the R/3's database interface divides the statement into several parts and recombines the resulting set to one. In the lower version the new Open SQL statement FOR ALL ENTRIES is used.
.. Using CA operator Use the special operators CO. Array inserts Whenever possible. use column updates instead of single row updates to update your database tables DO. CPU consumprion can rise substantially Use of a CONCATENATE function module vs. use array operations instead of single-row operations to modify the database tables Frequent communication between the application program and database system produces considerable overhead Single-line updates SELECT * FROM <TABLE> <COLUMN-UPDATE STATEMENT> UPDATE <TABLE> ENDSELECT vs. CS instead of programming the operations yourself If ABAP/4 statements are executed per character on long strings.ENDDO loop with Field-Symbol vs. CA.. Column updates UPDATE <TABLE> SET <COLUMN-UPDATE STATEMENT> Wherever possible.LOOP AT <INT-TAB> INSERT INTO <TABLE> VALUES <INT-TAB> ENDLOOP vs. Use of a CONCATENATE statement .
..RIGHT-JUSTIFIED Moving with offset vs......LEFT DELETING LEADING. BY SY-FDPOS PLACES....) are not as fast Get a check-sum with field length vs Get a check-sum with strlen () Use the strlen () function to restrict the DO loop to the relevant part of the field.. ---> CONCATENATE STRING_SPLIT...CENTERED STRING_MOVE_RIGHT ---> WRITE.... with CN and ASSIGN CLA+SY-FDPOS(LEN) . and should be replaced by ABAP statements or functions STRING_CONCATENATE. Other constructions (with CN and SHIFT... If you want ot delete the leading spaces in a string use the ABAP/4 statements SHIFT. eg...TO. . ---> strlen() STRING_CENTER... ---> WRITE. Use of the CONCATENATE statement Use the CONCATENATE statement instead of programming a string concatenation of your own Use of SEARCH and MOVE with offset vs..Some function modules for string manipulation have become obsolete. ---> SPLIT STRING_LENGTH...LEFT DELETING LEADING. with CONDENSE if possible. when determinating a check-sum . Use of SPLIT statement Use the SPLIT statement instead of programming a string split yourself Shifting by SY-FDPOS places vs Using SHIFT.TO..
this is not advisable. • Indexes of one table should be disjoint (have few common fields). Logical databases can be optimized centrally. esp. heavy inserted tables should have only few indexes while heavy selected tables might have more. please goto transaction SE30 and click on Tips & Tricks section. which served as the main source of reference for this section of this document. Note that each index slows the inserts into the table down. Otherwise the effect can be the opposite. The Database optimizer can combine two or more indexes to execute a query. Updates are only slowed down if indexed fields are updated. . on non-database related tips and tricks. • Indexes should be small (few fields).. Those are fields like object numbers. in order not to confuse the optimizer which index to use. For more information about more SAP ABAP/4 Development code-efficiency standards.. . In general.. Very important for an index is that it contains very selective fields in the beginning.Quick Note on Design of secondary database indexes First it must be stated that table design is a more logical work while index design is rather technical. company code. Not selective are client. Quick Note on Design of logical databases Using logical databases is a good method to write reports.) in the beginning. In table design it might make sense to place certain fields (client. . But ensure that the structure of the logical database fits well to your report. In index design.. company code.
This action might not be possible to undo. Are you sure you want to continue?