ABAP Review Check List
Siva Kumar at sthiagarajan@unicef.org
Mandatory Checks
I. Documentation
- Program documentation
- Function Module documentation
- Include documentation
- In source documentation
- Beginning block of source code documentation
II. Naming Conventions
Variable Names
- Selection options = s_
- Internal tables (global) = t_
- Internal tables (local) = lt_
- Constants = c_
- Ranges = r_
- Form parameter = p_ (Used in the actual form not the Perform statement.)
- Screen Parameters = a_ or p_
Program & Function Group Names
- UNICEF SAP development guidelines Appendix B (You need to log in to Unicef's intranet to get this document)
-
ABAP programs (reports), function groups and module pools all use a 2 character application name abbreviation. The list of current UNICEF applications will be maintained in Appendix B.
III. Attributes
- Authorization Group in attributes - Programs that can be executed by all UNICEF users must be configured using the Authorization Group 'ZOPN2ALL' for Application '*'.
- Development Class needs to be application specific. This standard is a work in process.
IV. Return Codes
- Test return codes (sy-subrc) for success and failure after any I/O and calls to function modules (database selects, internal table reads, call transactions, I/O to UNIX or workstation files, etc)
V. Transaction Code assigned to executable programs
Every type "executable program" must have an assigned transaction code which is used to execute the program.
VI. Authorization Checks for HR custom programs
Methods to accomplish authorization checks for HR are illustrated below:
1. Use function module "HR_READ_INFOTYPE" instead of direct SELECT
statements when reading a specific infotype.2. Use logical database PNP to leverage SAP authorizations (caveat:
performance can be slow)3. SELECT statements should only be used when the SAP documented data
interfaces which incorporate the SAP authorization checks (Logical
DataBases, function modules, and BAPI's) cannot provide the functionality
required. If it is necessary to use SELECT's, then you must perform your
own AUTHORITY-CHECK on the data selected.4. Place a strict authorization group at the program (transaction)
level. If a wide variety of data for a large group of individuals is
needed in a single program, then this program must have a very strict
authorization on who can run it (definitely not on any menu path).
VII. Parameter, P_BOUNCED_EMAIL, should be passed to Z_SENDMAIL
In order of preference, please provide one of the following for P_BOUNCED_EMAIL :
- A mailing list of people from the business process side who can recognize and have the ability to resolve the issue of a bounced mail (e.g. CAO maintains a master email list of cost object approvers).
- A mailing list of people from an Admin Computing support or project team who can resolve the bounced mail.
- "sap-bounces.unicef@gmail.com". This mail will go to Siva Kumar, Amina Alavi and Victor Lee for resolution.
VIII. Separate Dialog Program Includes
- PBO
- PAI
- Global data
- Forms
IX. Standards
- Development
- Quality Assurance
- Change Request
Strongly Recommended Practices
I. Non Database Performance
- Dead Code (Program -> Check -> Extended Prog. Check) - unused subroutines appear as warnings under PERFORM/FORM interfaces. - unused variables appear as warnings under Field attributes. Transaction code is SLIN. This will also catch literals (section III below).
- When possible use MOVE instead of MOVE-CORRESPONDING (move bseg to *bseg or move t_prps[] to t_prps2[] if you want to copy entire table or t_prps to t_prps2 if you only want to copy header line.)
- Code executed more than once should be placed in a form routine.
- http://docs.google.com/View?docID=dhs6z73_45f5r2q9fd&revision=_latest when possible especially against non-buffered table (Data Dictionary -> Technical Info)
- SORT tables BY fields
- Avoid unnecessary moves to table header areas.
- Subroutine parameters should be typed for efficiency and to help prevent coding and runtime errors.
II. Database Performance
- Avoid ORDER BY unless there is index on the columns - sort internal table instead
- SELECT SINGLE when possible
- SELECT fields FROM database table INTO TABLE t_tab (an internal table) - Lengthy discussion.
- Views (inner join) are a fast way to access information from multiple tables. Be aware that the result set only includes rows that appear in both tables.
- Use subqueries when possible.
- "Sample Code" (outer join) are very fast but keep in the mind the special features and 3 pitfalls of using it.
(a) Duplicates are removed from the answer set as if you had specified "SELECT DISTINCT"... So unless you intend for duplicates to be deleted include the unique key of the detail line items in your select statement. In the data dictionary (SE11) the fields belonging to the unique key are marked with an "X" in the key column.
(b) If the "one" table (the table that appears in the clause FOR ALL ENTRIES IN) is empty, all rows in the "many" table (the table that appears in the SELECT INTO clause ) are selected. Therefore make sure you check that the "one" table has rows before issuing a select with the "FOR ALL ENTRIES IN..." clause.
(c) If the 'one' table (the table that appears in the clause FOR ALL ENTRIES IN) is very large there is performance degradation Steven Buttiglieri created sample code to illustrate this. - Where clause should be in order of index See example.
This is important when there are multiple indexes for a table and you want to make sure a specific index is used. This will change when we convert from a "rules based" Oracle optimizer to a "cost based" Oracle optimizer. You should be aware of a bug in Oracle, lovingly referred to as the "3rd Column Blues". Click here for more information on indexes. - Where clause should contain key fields in an appropriate db index or buffered tables. As long as we are using the Oracle Cost Based Optimizer, be aware fo the "Third Column Blues", an Oracle bug.
- Avoid nested SELECTs (SELECT...ENDSELECT within another SELECT...ENDSELECT). Load data in internal tables instead. See item 3 above.
- Use SQL statistical functions when possible (max, sum, ...)
- Delete all rows from a table. A where clause is mandatory. Specifying the client is the most efficient way.
- Put Check statements into where clause - caveat: Make sure that the index is still being used after you add the additional selection criteria. If the select statement goes from using an index to doing a db scan (reading each row in the database without going through an index) get it out of the where clause and go back to using "Check"!
III. Literals
- Codes ('MD') should use contants (c_medical)
- Longer text should use text elements. Sample code is a good example because it uses the text element in conjunction with the hard coded text. This documents the text element and provides for the possibility of multi-language support.
IV. Miscellaneous
- Use CASE statement instead of IF...ELSEIF when possible (It is only possible in equality tests)
- Nested If - encounter most likely to fail first (specific to general)
- And - encounter most likely to fail first (specific to general)
- OR's - encounter most likely to succeed first (general to specific)
- Variables should use Like when possible
- Subroutine usage - don't place decision to execute in the subroutine
- If not ( t_prps[] is initial ) (instead of describe table t_prps lines sy-tfill, if sy-tfill > 0...)
- New document types confirmed with the configuration team via UNICEF-ABAP mail list prior to coding a report to access the data.
- Dates need to be properly formatted using the user's default settings. For the explanation of the BDC example check out the developer's standards.
Function Module documentation
ZFUNCDOC
REPORT ZFUNCDOC.
************************************************************************
* INSTRUCTIONS FOR COPYING DOCUMENTATION TEMPLATE *
************************************************************************
*1) SELECT THE ENTIRE TEMPLATE BY PLACING THE CURSOR IN THE FIRST
* COLUMN double clicking three times on the Select button.
*
*2) SELECT COPY.
*
*3) GO TO THE FUNCTION YOU ARE DOCUMENTING. SELECT DOCUMENTATION AND
* CHANGE. PRESS BUTTON 'FUNCTION MOD. DOC F9'.The documentation window
* appears, showing the SAP default documentation
*
*4) DELETE THE DEFAULT TEXT. PASTE THE TEMPLATE INTO THE WINDOW USING
* PASTE. The template and text formatting tags appear.
*
***************** TIPS FOR ENTERING INFORMATION ************************
*
* IF YOU WANT TO AVOID ACCIDENTALLY DELETING FORMATTING TAGS, START EACH
* LINE of your documentation on a new line.
*
* At the end of each line you type, press return; otherwise, your text
* will spill into the first column, which is used only for paragraph
* formatting.
*
************************************************************************
* END OF INSTRUCTIONS *
************************************************************************
Include documentation
ZDOCUINM
************************************************************************** INSTRUCTIONS FOR COPYING DOCUMENTATION TEMPLATE **
************************************************************************
* Updated on 05/27/2007. *
************************************************************************
*1- Place cursor beneath the INCLUDE comment.
*2- Click on the Pattern soft button.
*3- Select the "Other pattern" radio button.
*4- Enter ZDOCUINM in the search box beneath this button.
*5- Follow instructions in the pattern copied to your program (below).
************************************************************************
************************************************************************
* Instructions: 1. When inserting this template in your source code,
* please replace only the angle brackets and the text
* between them.
* 2. If it is not applicable simply enter N/A.
* 3. If you need more space, use additional lines starting
* with an asterisk ONLY and kindly indent. Thanks!
* 4. Lastly, remove these instructions from your include
* documentation block. Thanks!
************************************************************************
*^ Written By : <Author>
*^ Date Written : <Date>
*^ Include Name : <Name of the include>
*^ Used in Programs: <Programs referencing this include>
*^ System Name : <System name/application area>
*^ Purpose : <Form routines, PAI/PBO modules, data declarations>
* <Kindly indent subsequent lines>
*^ Other Considerations: <anything else a developer might find helpful>
**--------------------------------------------------------------------**
*^ Maintenance History (latest on top)
*
*^ Date: <MM/DD/YY> Author: <USERID> Transport: <Transport #>
*^ Description of Change:
*
************************************************************************
No comments:
Post a Comment