Académique Documents
Professionnel Documents
Culture Documents
ISG QUALITY PROGRAM GUIDELINE Template Name: Document ID: Template Version: SAP Coding Standards COD-003 Ver. 3.0, 04/20/2006
Template Overview Description
The SAP Coding Standards document describes the standards to be followed when creating and modifying an ABAP object. This workbook has 8 worksheets, grouping the SAP standards into the following categories: Style, Naming Convention, Internal Table, Data Dictionary, SQA, Object Oriented, Transport Request, and General. In each worksheet, standards are labeled 'standard' if following them is required, or 'recommended' if they are optional. The worksheets can also be used as checklists. 1. Use the worksheets that correspond to the type of code that is being developed. 2. Lines that are classified as "standard" must be followed. 3. Lines that are classified as "recommendation" are optional, but recommended. 4. Use the standards as guidelines during code development. 5. Use the worksheets as checklists when code is being reviewed. 6. If code was developed using an earlier standard, modifications to that code can be made using that same standard. This is at the discretion of the Lead.
Purpose
Guideline
References
Document Name
Electronically distributed, uncontrolled if printed. Use the Quality Website to verify that this is the current version. Software Coding Process SAP Coding Standards
ST-02 ST-03
ST-04
Pretty Printer
ST-05 ST-06
All programs must follow the default indentation offered Standard by Pretty Printer. ABAP Pretty Printer settings should have lower case option on and keyword Uppercase option should be on Modification search key Use UCM, JIRA or Project Number number as Standard modification search key. Modularization All global variables should be declared in a TOP Standard include and all subroutines should be defined in a F01 include Modularization for Report programs Modularization for Report programs Processing blocks must precede with a label header. Following is the best optimized sequence in which various event statements (if they are coded) within a report program should be defined: * Events in the sequence of processing LOAD-OF-PROGRAM. INITIALIZATION. AT SELECTION-SCREEN OUTPUT. AT SELECTION-SCREEN. START-OF-SELECTION. PERFORM read_data. PERFORM process_data. END-OF-SELECTION. *Events that occur more than once during processing TOP-OF-PAGE. TOP-OF-PAGE DURING LINE-SELECTION. END-OF-PAGE. * Interactive events AT LINE-SELECTION. AT USER-COMMAND Standard Standard
ST-07 ST-08
ST-09
Code deletion
In most situations comment unneeded code, do not delete it. However, use your discretion to delete code in situations where doing so will improve readability. If standard report/screen headers are defined and in use for a team/project , then they must be used.
Recommendation
ST-10
Recommendation
ISG-QMS-COD003-3.0
NC-01 NC-02 NC-03 NC-04 NC-05 NC-06 NC-07 NC-08 NC-09 NC-10 NC-11 NC-12
Data Elements Message Class PBO PAI POV POH Function Group Names Normal Function Module Name RFC Function Module Name Update Function Module Name BAPI Function Module Name Type Group
<namespace or Z><Name> <namespace or Z><Functional Area>_<Name> PBO modules should start with PBO PAI Modules should start with PAI POV should start with POV POH modules should start withPOH <namespace or Z><2 to 3 character Functional_area>_name <namespace or Z>_<Functional_area>_<Name> <namespace or Z>_RF_<Functional_area>_<Name> <namespace or Z>_UPD_<functional_area>_<Name> <namespace or Z>_BAPI_<functional_area>_<Name> Type Groups should not be prefixed with namespace; and hence must follow the following guidelines: Z<XX><YY> where XX is the 2-character abbreviation for the project and YY is a 2-character code (a combination of alphabets and/or digits).
Standard Standard Standard Standard Standard Standard Standard Standard Standard Standard Standard Standard
Transparent Table Names View Names Structure Names Domains Table Types Search helps Adding fields to a standard table Enhancements Package
<namespace or Z><Name> <namespace or Z>V_<Name> <namespace or Z>S_<Name> <namespace or Z><Name> <namespace or Z>_TT_<Name> <namespace or Z><Field Short Desription>_SHLP Column/Field names should start with ZZ** To hold components related to SAP enhancements, package should be named as: Z<Project name>_<Functional area abbreviation>_SAP_ENHANCEMENTS
NC-21
Naming Packages
To hold Type Groups and other exceptional Standard dictionary objects, package should be named as: Z<Project name>_<Functional area abbreviation>_DICT_OBJ
ISG-QMS-COD003-3.0
NC-23
NC-24 NC-25
Standard Standard
/ILAP/BAPI_DIS_GET_WDRWL_APPL I_CONTRACT_NUM
NC-26 NC-27
<Namespace><Functional area>_<Name> Standard Function groups that are to be used for Standard storing code generated by table maintenance generator option should be created based on following naming standards: If multiple functions for withdrawal application processing are to be combined in different function groups, it is recommended to create function groups as WDRL_APPL_01, WDRL_APPL_02, etc. It would provide easy access to find all function Certain tables require inclusion of an Standard internal ID to uniquely identify the rows. Such internal IDs, which are not usually visible to end-users, should be named using following standards:<Table abbreviation>_INTL_ID <Namespace><Functional area>_<Name> Standard <Search help name>SH_EXIT Standard
NC-28
Tables
<Namespace>E_<Name> Keep the Name Standard same as the actual table name for which the lock object is defined (or abbreviate the actual table name if it is lengthy for lock object). <Namespace><Object ID> Standard /ILAP/ITXN
NC-32
ISG-QMS-COD003-3.0
NC-35 NC-36
<namespace or Z>R<2 to 3 character Functional_area>_name <namespace or Z>I<2 to 3 character Functional_area>_name <namespace or Z>B<2 to 3 character Functional_area>_name <MAIN_PRG_NAME><3 Char Value>
Standard Standard
A Report program should start with ZRMM_** An interface program name should start with ZIMM_ A BDC program name should start with ZBMM_ ZRMM_**TOP for data declaration, ZRMM_**F01 for subroutines SAPFZ_SMRTFORM_ROUTINS
NC-37 NC-38
Standard Standard
NC-39
Standard
NC-40 NC-41
Standard
F_GET_PO_DETAILS LCL_FRONTEND_SERVICES
<Namespace><Class Standard visibility>_<Functional area>_<Name> Namespace prefix in Class Name should be used only for defining global classes. Class visibility-> LCL Local class (defined within the program), CL Global class (defined using Class Builder). All global classes must belong to namespace (or begin with pre-defined custom prefix for the project, if namespace is not available). Local classes need not be prefixed with namespace and functional area. <Namespace><Interface Standard Visibility>_<Functional area>_<Name> Interface visibility->LIF Local interface (use of namespace and function area prefixes not required), IF Global interface <verb>_<noun> GET_<ATTRIBUTE> or SET_<ATTRIBUTE> ON_<EVENT_NAME> IS_<Adjective> <Noun>_<Past_tense_verb> CHECK_<object> Standard Standard Standard Standard Standard Standard
NC-42
Interfaces
LIF_FRONTEND_SERVICES
General Method Names Attribute Access Methods Event Related Methods Boolean Methods Event Names Check methods(CHECK methods are same as Boolean methods except the fact that they can raise exceptions)
CREATE_CONTRACT GET_UPDATE_MODE, SET_UPDATE_MODE ON_MGR_APPROVAL IS_APPROVED, IS_CANCELLED CONTRACT_APPROVED CHECK_CONTRACT_STAT CHECK_AUTHORIZATION CHECK_APPRV_CONDNS
ISG-QMS-COD003-3.0
NC-51
Function Module / Form Changing parameter Function Module / Form Table parameters Function Module Import Parameter / Form Using Parameter Function Module Export Parameter
XV for Variable, XS for Structures, XT for Internal table (based on the internal table type follow rules)
Standard
NC-52
T for standard table, TH for hashed table, TI Standard for Indexed table, TS for sorted table IV for Variable, IS for Structure, IT for Internal table (based on the internal table type follow rules). Note use the I prefix for forms Using paameter also; do not use U prefix. EV for Variable, ES for Structures, ET for Internal table (based on the internal table type follow rules) IV for Variable, IS for Structure, IT for Internal table (based on the internal table type follow rules) EV for Variable, ES for Structures, ET for Internal table (based on the internal table type follow rules) Standard
XV_EBELN, XS_EKKO, XT_EKKO, XTH_EKBE for hashed table, ITI_EKBE for indexed table, ITS_EKBE for sorted table. T_EKKO, TH_EKBE, TS_EKBE, TI_EKBE IV_EBELN, IS_EKKO, IT_EKKO, ITH_EKBE for hashed table, ITI_EKBE for indexed table, ITS_EKBE for sorted table. EV_EBELN, ES_EKKO, ET_EKKO, ETH_EKBE for hashed table, ETI_EKBE for indexed table, ETS_EKBE for sorted table. IV_EBELN, IS_EKKO, IT_EKKO, ITH_EKBE for hashed table, ITI_EKBE for indexed table, ITS_EKBE for sorted table. EV_EBELN, ES_EKKO, ET_EKKO, ETH_EKBE for hashed table, ETI_EKBE for indexed table, ETS_EKBE for sorted table. RV_EBELN, RS_EKKO, RT_EKKO, RTH_EKBE for hashed table, RTI_EKBE, RTS_EKBE. XV_EBELN, XS_EKKO, XT_EKKO, XTH_EKBE for hashed table, XTI_EKBE, XTS_EKBE. T_EKKO, TH_EKBE, TS_EKBE, TI_EKBE FPV_EBELN, FPS_EKKO, FPT_EKKO, FPTH_EKBE for hashed table, FPTI_EKBE, PTS_EKBE.
NC-53
NC-54
Standard
NC-55
Standard
NC-56
Standard
NC-57
Method Changing parameter Method Returning parameter Method table parameters Subroutine Formal Parameters
NC-58
NC-59
XV for Variable, XS for Structures, XT for Standard Internal table (based on the internal table type follow rules) RV for Variable, RS for Structures, RT for Standard Internal table (based on the internal table type follow rules) T for standard table, TH for hashed table, TI Standard for Indexed table, TS for sorted table FPV for Variable, FPS for Structure, FPT for Standard Internal table (based on the internal table type follow rules)
NC-60
ISG-QMS-COD003-3.0
Custom Control CUSCTRL_** for Custom Control Screen input/output IP_** For Screen Input Variable Variable Screen output Variable Screen text OP_** For screen Output Variable If not used in programs leave it blank, system will assign default value. STX_** for screen texts. ICO_ For screen Icon If not used in programs leave it blank, system will assign default value. BX_** for screen texts. <Field type>_<Name>
NC-76 NC-77
Standard Standard
NC-78 NC-79
Standard Standard
NC-80
Class/Interface attributes
Standard
V_EBELN for single field, S_EKKO for structure, T_EKKO for standard table, TH_EKKO for hashed internal table, TS_EKBE for Sorted Internal table, TI_EKBE for indexed internal table
NC-81 NC-82
<Parameter interface><Parameter type>_<Parameter name> **_ERR if error occurred, **_NOT_FOUND if <**> not found, **_NOT_SUPPORTED if <**> not supported etc. There is no standard way of coding exceptions. Make sure it concise and meaningful
NC-83 NC-84
Authorization Z<Project name><Name> Objects Transport Requests Transport requests must be named based on following standards: <Project name> <Functional area>: <Requestor initial (if applicable)> <Description> - <Creator initial><Creation date>
Standard Standard
ISG-QMS-COD003-3.0
NC-86
Exception Class
Standard
ISG-QMS-COD003-3.0
IT-02 IT-03
Standard Standard
IT-04
Modify Index
Standard
IT-05 IT-06
Standard Standard
IT-07 IT-08
Standard Standard
IT-09
Insert Lines of
Standard
Free internal tables Work Area Copying Internal tables Delete adjacent duplicates Collect
IT-14
IT-15 IT-16
ISG-QMS-COD003-3.0
DD-03
If table name is ZTEST, SM30 access for this table will be driven by the transaction code ZTEST
DD-04 DD-05
DD-06
Data Elements
Try to use existing DD elements. If you are using Recommencustom data elements make sure they are part of dation your application/package/module. If data elements from other packages/modules/applications are used make sure it is properly communicated to other teams. Use append structure to add new fields to standard tables. Recommendation
DD-07
10
ISG-QMS-COD003-3.0
Standard
Try to use index wherever applicable Standard Always use logical operators in where conditions Standard
SQ-06
Always follow the field positions when using the fields in where conditions
Standard
Where MANDT eq SY_MANDT and NOT where MANDT = SYMANDT Where MANDT eq SY_MANDT and EBELN eq PO_NUM and NOT where EBELN eq PO_NUM and MANDT = SYMANDT
SQ-07
Database fields
SQ-08
Always select the required fields from the Standard database table instead of using select * unless all the fields have to be selected from the database table Always use alias names in database joins even if Standard the fields are unique in both the tables Do not use nested select statements Avoid using select statements inside internal table loops. Use for all entries wherever applicable If you are selecting multiple records, try to avoid select processing loop (SELECT... ENDSELECT), by using into table or appending table statements. Use 'SORT' statement instead of using ORDER BY sql statement to sort records in internal table. Join table only if they have foreign key relationship For entries' will be faster only if all the fields in the where condition are checked with 'EQ' logical operator If the data from a particular table is used in an application at a single one time validation (example initialization), it is better to use SELECTENDSELECT statement than using an internal table. Standard Standard
SQ-09 SQ-10
SQ-11
Select Statement
Standard
SQ-12
Select Statement
Standard
SQ-13 SQ-14
SQ-15
Select Statement
11
ISG-QMS-COD003-3.0
SQ-17
Select Statement
12
ISG-QMS-COD003-3.0
OO-02
Class Methods
OO-03
Exception Class
Exception handling in the programs can be made Standard more flexible by making it class-based. Common errors like divide by zero, overflow errors, etc can be caught using SAP pre-delivered exception conditions (implemented via class-based exceptions) whereas exceptions specific to a project needs (custom exceptions) can also be defined by the programmers. Programmers are encouraged to use class-based exceptions henceforth, unless absolute necessary to deviate based on specific needs of the project.
OO-04
Messages
In object oriented programming, when using dynamic messages, make sure message class, type and number are filled in before calling the message to avoid short dump. Free created objects after usage Handle exceptions when calling class methods Check for an object existence before using it In ABAP OO (Object Oriented) Programming, if any initialization has to be performed every time an object is created, consider using CONSTRUCTOR method instead of creating a custom defined method to achieve the same results.
Standard
OO-09
Exception Class
It is encouraged not to use Exception Class texts Recommenas an interface for communication with end user dation (e.g. as message text for end-users, etc). Instead, when an exception is caught/handled, make use of appropriate message class and message number (from SAP Message Class, transaction SE91) to get message text (for error, warning, information, etc) and use that to interact with end-users.
13
ISG-QMS-COD003-3.0
TR-02
TR-03
Before releasing request, complete object syntax Standard check, request consistency check and display inactive object. When you are working on a medium/large Recommenapplication where multiple developers are dation accessing the same objects, store all the data dictionary objects in a separate request. So the objects can be tranported/released anytime. Use transport copies to move program copies/application to another system during development phase. Recommendation Two modifications have to be done on a program and both have to be moved together to PRD. But only one modification is completed and this has to be tested in quality system. Instead of releasing the development/correction request, create a transport copy MM-STC Days validation changes. 01/02/05
TR-04
Transport Copies
TR-05
Provide a concise, meaningful description. Use a Recommen2 to 4 character functional area prefix. This will be dation useful when you are working on multiple projects/functional areas. When creating a transport request make sure to add creation date to the end of the TR
14
ISG-QMS-COD003-3.0
G-01
Development Class
Do not assign non-production ABAP objects (Dummy objects created for testing/proof of concept etc) to production development class. Always save them in your local objects or use a development class lke ZTEST or ZJUNK. Always use Modification assistant to modify standard SAP Programs All programs have to undergo SLIN check (Extended program check) Never use BREAK-POINT statement in productive code. Statement, if used for testing, should be commented/deleted prior to transport to production. Concise, Meaningful and easily identifiable title Should have Customer Production Program status before transporting to Production Should be assigned to appropriate Application component Should be on. If unchecked, should justify Should not enable editor lock Should be enabled Always specify types for routines formal parameters. Helps in code optimization and performance Self-explanatory checkbox should be checked if the message is a single message and there is no long text for the message Messages should be meaningful to the end users.. Avoid descriptions like Project Sector not found. Instead, construct it as Project Sectors not maintained for the Project. Message variable should not be a character values. They should be defined as a variable, constant or a text element When using dynamic messages, make sure message class, type and number are filled in before calling the message to avoid short dump When comparing a character variable with constants, always declare values within codes
Standard
Program Title G-05 G-06 G-07 Production Program Status Application Component Assignment Fixed point arithmetic indicator Editor Lock Unicode Subroutine Formal Parameters types Single Messages
G-12
Standard
G-13
Message Text
Standard
G-14
Message Variable
Standard
G-15
Dynamic Messages
Standard
G-16
Standard
15
ISG-QMS-COD003-3.0
G-18 G-19
Standard Standard If an integer has to be checked for initial value use is initial statement than checking for '0'.
G-20
IF vs Case
G-21
Coding
When a variable has to be checked for more than two values use case condition than if condition. Case will be litte faster than If condition Do not code business logic inside Modules. Code all the logic in a subroutine call them in modules
Standard
Standard
G-22 G-23
G-24
FM Interface parameters Do not globalize interface parameters, if globalized, Standard should justify Type Group If you are using type group, it is not necessary to use Standard TY prefix because all data types declared in type group should start with type group id. Function Module **_ERR if error occurred, **_NOT_FOUND if <**> not Standard Exceptions found, **_NOT_SUPPORTED if <**> not supported etc. There is no standard way of coding exceptions. Make sure it concise and meaningful Structure Names All structure fields must refer (if possible) data Standard elements and should not explicitly refer standard data types like NUMC, DEC, etc unless otherwise necessary. Use/Change existing global variables only if it is Standard necessary. Avoid declaring global variables unless it is necessary Exceptions must be qualified to specifically indicate the Standard process, step, object, etc that caused the exception. E.g. Instead of using exception FAILED; qualify it as, e.g., AUTHORIZATION_FAILED When processing multiple parameters, check for the Standard basic conditions (like is not null, is greater than zero, etc) for all parameters first before pulling relevant information (table records, etc) for each parameter. This will not only improve interaction with end-user but will also improve the network traffic of making database calls. Proper spacing must be maintained within the program Standard statements for ease in readability. Insert a blank line before and after important control blocks and statements
UPI_NOT_FOU ND
G-25
G-26
Global Variables
G-27
BAPI Exceptions
G-28
Coding
G-29
16
ISG-QMS-COD003-3.0
G-32 G-33
Standard Standard
Standard Standard
G-38
G-39
No hard coding of texts. Standard If an import parameter is optional/mandatory, then the Standard method or function module should work accordingly. It should check the values and return proper error messages. Standard Standard SAP tables should never be updated directly. It can be changed only through transactions. Following sequence must be followed: As soon as the Standard data is retrieved for the purpose of making updates, acquire an optimistic lock on the data (lock mode O),(b) After making required changes (through screen or background job etc), convert the already acquired optimistic lock to exclusive lock (lock mode E). All operands for group statements (e.g. WRITE:, CLEAR:, REFRESH:, etc) should appear on a new line. Use this to improve the performance of the code Recommendation WRITE: gv_UPI, gv_name.
G-40
Code Layout and Presentation Code Inspector Boolean Variable Numeric : Data type N Negative statements
Recommendation SAP standard data element BOOLE_D can be used as Recommenreference data type dation Avoid using Numeric data type for calculations. Use Recommenthem for numeric character fields only dation Avoid using negative condition if positive condition is Recommeneasier to comprehend. dation
Telephone numbers, date If a variable has to be checked for value 'X' in it. Use 'EQ' 'X' statement than if v_ch 'NE' space.
G-45
While vs Do
Use while statement than do statement wherever possible. While statement is faster and easier to understand
Recommendation
17
ISG-QMS-COD003-3.0
G-47
Modularization
Recommendation Recommendation
G-48
Recommendation Sort internal table before Read statement to avoid Recommenunpredictable result. dation If a similar type of SAP delivered DD object already Recommenexists for the custom DD object being defined, then the dation custom DD object must be defined with same data type and size as the one existing in SAP so as to maintain consistency unless absolutely necessary to deviate. Recommendation Performance hint Policy
Message Numbers
Always use the next immediate available number for new messages FM Interface parameters Always call by reference (performance) unless it is necessary to call by value (example RFC) Outbound emails As per policy which is described in Stephen Sebastian's email of 4/6/2006, which is filed in IRIS: http://WBLN0036.worldbank.org/85256B52005840BB/( ViewContentTransaction)?OpenAgent&DOCID=8F5B5 498524B19158525714800470DD9&Framework=IRIS&
18
ISG-QMS-COD003-3.0
Initial release of the new standards in spreadsheet format. This new standard will also replace the SAP Code Review Checklist (COD-004).
19