Vous êtes sur la page 1sur 19

The World Bank

Official Use Only

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 Identification Number COD-001

Document Name

Software Coding Process

Electronically distributed, uncontrolled if printed. Use the Quality Website to verify that this is the current version. Software Coding Process SAP Coding Standards

Ver. 3.0 04/20/2006

Official Use Only SAP Standards: Style


ID ST-01 Guidelines Program Header Standard/ Recommendation Class Developers can refer the standard template from Standard program /ILAP/SAMPLE_PROG_ABAP_1, copy it into their own program, and modify accordingly. Variable Indentation Each Variable should be in a new line. Standard Variable Documentation All variables should have a meaningful comment next Standard to it. Example

ST-02 ST-03

Data: GV_UPD. " Update Indicator

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

ZR**TOP for variables, ZR**F01 for subroutines

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

Output display header

Recommendation

ISG-QMS-COD003-3.0

SAP Standards: Style

Official Use Only

SAP Standards: Naming Convention


ID Guidelines Standard/ Recommendation Class Example Y prefix namespace is supposed to be used by third-party vendors and not customers. Currently, there are a few cases in which WBG has used "Y" prefix for custom objects. In future, no additional custom objects should be defined with the "Y" prefix. This comment is applicable to all custom objects defined in the Naming Conventions worksheet. ZFISCAL_YR ZMM_PO_CLS PBO_INITIALIZE PAI_FCODE POV_PO_VALUES POH_F1_FOR_XYZ ZMM_STC Z_CREATE_VENDOR Z_RF_CREATE_VENDOR_PARA Z_UPD_VENDOR_MASTER_DB Z_BAPI_CREATE_VENDOR A constant declaration within a Type Group ZIL01 should be like ZIL01_C_SUCCESS

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

NC-13 NC-14 NC-15 NC-16 NC-17 NC-18 NC-19 NC-20

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

Standard Standard Standard Standard Standard Standard Standard Standard

ZSTC_HDR ZV_STC_HDR_ITM ZS_STC_SCR_ITM ZFISCAL_YR Z_TT_EKBE ZPONUM_SHLP

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

SAP Standards: Naming Convention

Official Use Only

SAP Standards: Naming Convention


ID NC-22 Guidelines Standard/ Recommendation Class Method parameters <Parameter interface><Parameter Standard type>_<Parameter name> Parameter Interface => I Importing, E Exporting, X Changing, R Returning. Parameter Type => V (optional) Variable (i.e. all types of elementary data types based variables, like CHAR, NUMC, STRING, etc), S Structure, T table, P Pointer(type ref to) Includes Custom developed INCLUDE files (excluding the ones that are proposed by SAP, e.g. when creating function modules, etc) must be named based on following standards: <Namespace><Functional area>_Name <Namespace>BAPI_<Functional area>_<Name> <Parameter interface><Parameter type>_<Parameter name> Parameter Interface => I Importing, E Exporting, X Changing, T table. Parameter Type => V (optional) Variable, S structure, T Table type, P pointer (Type ref to data) Standard Example

NC-23

NC-24 NC-25

BAPI BAPI Parameters

Standard Standard

/ILAP/BAPI_DIS_GET_WDRWL_APPL I_CONTRACT_NUM

NC-26 NC-27

Function Group Function Group

<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

NC-29 NC-30 NC-31

SEARCH HELP SEARCH HELP EXIT LOCK OBJECT

<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

Number range objects

ISG-QMS-COD003-3.0

SAP Standards: Naming Convention

Official Use Only

SAP Standards: Naming Convention


ID NC-33 NC-34 Guidelines Transactions Transactions for Table Maintenance Executable Report Program names Executable Interface Program Name Executable BDC Program Name Include Program Names with Main program Include Program Names without Main program (Subroutine Pool) Subroutine Names Classes Standard/ Recommendation Z<Project name>_<Functional area>_<Name> Z<Project name>_TM_<Name> Class Standard Standard Example

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

SAPFZ<2 to 3 character Functional_area>_name

Standard

NC-40 NC-41

Should start with F_** to represent form

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

NC-43 NC-44 NC-45 NC-46 NC-47 NC-48

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

SAP Standards: Naming Convention

Official Use Only

SAP Standards: Naming Convention


ID NC-49 NC-50 Guidelines Validate methods Variables and Constants Standard/ Recommendation Class VALIDATE_<object> Standard <Visibility><Data type>_<Name> Visibility - Standard > C Constant, L Local, G Global, I Import parameter, E Export parameter, X Changing, R Returning. Datatype -> V Variable (optional), S Structure, T Table, R Range table(selection table), P Pointer (type ref to data) Example VALIDATE_WDRAWAL_APPL GV_** for Global Variable GS_** for Global Structure GC_** for Global Constants GP_** for Class Reference(Global Type ref to) GT_ for global standard internal table GTH_ for global Hashed Internal Table GTI_ for global indexed Internal Table GTS_ for global sorted Internal Table LV_** for Local Variable LS_** for Local Structure LP_** for local Class Reference LT_ for local standard internal table LTH_ for local Hashed Internal Table LTI_ for local indexed Internal Table LTS_ for local sorted Internal Table

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

Method Import Parameter

Standard

NC-56

Method Export Parameter

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

SAP Standards: Naming Convention

Official Use Only

SAP Standards: Naming Convention


ID NC-61 NC-62 NC-63 NC-64 NC-65 NC-66 NC-67 NC-68 NC-69 NC-70 NC-71 NC-72 NC-73 NC-74 NC-75 Guidelines Global selection Range Local selection Range Field Symbols Global Field Symbols Data References Data Types Select-options Parameters Checkbox Radiobutton Table Control Tab Strip Subscreen Standard/ Recommendation GR_** for Selection Range LR_** for Selection Range <<Visibility>FS_<Name>> <GFS_**> for field symbols <Visibility>DR_<Name> TY_<Data type>_Name S_** for select-options P_ for Parameters CBX_** for Checkbox RB_** for radiobutton TC_** for Table Control TS_** for Tab strip SUBSCR_nnnn for Sub screen Class Standard Standard Standard Standard Standard Standard Standard Standard Standard Standard Standard Standard Standard Standard Standard Example GR_DATUM for SY-DATUM LR_DATUM for SY-DATUM <LFS_EKKO> <GFS_EKKO> LDR_EKKO <TY_S_EKKO>, TY_EBELN, TY_T_EKKO, TY_TH_EKKO S_EBELN for EKKO-EBELN P_GJAHR type EKKO-GJAHR CBX_LIST as checkbox RB_QTR1 radiobutton TC_PO_ITM TS_ITM_DET SUBSCR_0001 for schedule line details CUSCTRL_ALV_TREE IP_EBELN for PO Number

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

OP_ERNAM - User Name STX_POXT - PO Number text

NC-78 NC-79

Screen Icon Screen Box/Frame

Standard Standard

ICO_GO for Green light BX_HDR Frame for header details

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

Parameters Method Exceptions

<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

Standard Standard UPI_NOT_FOUND

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

SAP Standards: Naming Convention

Official Use Only

SAP Standards: Naming Convention


ID NC-85 Guidelines Type Group Standard/ Recommendation All fields defined within a Type Group must be prefixed with the Type Group name, but still the naming conventions for variables, constants, and types must be followed. Namespace>CX_<Functional area><Name> Class Standard Example

NC-86

Exception Class

Standard

ISG-QMS-COD003-3.0

SAP Standards: Naming Convention

Official Use Only

SAP Standards: Internal Table


ID IT-01 Guidelines Work Area Standard/ Recommendation Declare a separate work area for internal tables. Never use internal table with header line Always use 'READ' statement to read single record from an internal table When reading standard internal tables use BINARY SEARCH statement wherever applicable. Binary search is faster than linear search. When modifying internal table using index key word make sure index variable is a valid index number. Index variable with '0' will make program to dump Do not delete statement with index when deleting entries inside a loop Check internal table for valid entries before using it for all entries sql statements. Empty internal tables will fetch all records from the database tables Avoid using nested internal table loops. Use READ TABLE statement wherever applicable Use APPEND LINES OF statement to insert records from one internal table to another do not use loop and append statement Use INSERT LINES OF statement to insert records from one internal table to another do not use loop and append statement Free internal tables which are no longer used in the program Clear the work area inside the loop before reading new data into it. Use MOVE statement than loop and append technique Make sure to sort internal table before using DELETE ADJACENT DUPLICATES statement Internal tables field types and length should be considered before using collect statement Use modify with TRANSPORTING F1 variant wherever applicable. SAP recommends using the MOVE statement instead of MOVE-CORRESPONDING for performance reasons Class Standard Example

IT-02 IT-03

Reading internal table Binary Search

Standard Standard

IT-04

Modify Index

Standard

IT-05 IT-06

Deleting Entries For all entries

Standard Standard

IT-07 IT-08

Nested Loops Append Lines of

Standard Standard

IT-09

Insert Lines of

Standard

IT-10 IT-11 IT-12 IT-13

Free internal tables Work Area Copying Internal tables Delete adjacent duplicates Collect

Standard Standard Standard Standard ITAB1 = ITAB2

IT-14

Recommendation Recommendation Recommendation

IT-15 IT-16

Modifying ITAB Select Statement

ISG-QMS-COD003-3.0

SAP Standards: Internal Table

Official Use Only

SAP Standards: Data Dictionary


ID DD-01 DD-02 Guidelines Changing field Names Table Maintenance Generator Standard/ Recommendation Class Never change a field name in a production table Standard as it would cause loss of data Maintain a separate function group for table Standard maintenance. Do not use existing function groups (which are created for application development) to generate table maintenance modules The table name should be the transaction code to Standard maintain the table views. Basis team will provide access in PRD to the users as approved by the manager to maintain the table entries Always add a field/column to the end of a production table. Avoid using built in types unless, the table/column is independent. If the column is going to be used in more than one table always create data elements. It makes maintenance easy Recommendation Recommendation Example

DD-03

Transaction code Maintain table views

If table name is ZTEST, SM30 access for this table will be driven by the transaction code ZTEST

DD-04 DD-05

Adding new fields to tables Built in types

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

Adding fields to a standard table

10

ISG-QMS-COD003-3.0

SAP Standards: Data Dictionary

Official Use Only

SAP Standards: SQL


ID SQ-01 SQ-02 Guidelines Select single UP TO 1 ROWS Standard/ Recommendation Always use select single <field> to select a unique record from the database table If single select statement can not be used to check existence of a record in a database table use UP TO 1 ROWS variants . Select single should be used only when all keys are passed. Use aggregate functions wherever applicable Class Standard Standard Example

SQ-03 SQ-04 SQ-05

Aggregate functions Index support Logical Operator

Standard

Try to use index wherever applicable Standard Always use logical operators in where conditions Standard

SQ-06

Where condition Field sequence

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

Alias in Database Joins

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

Nested Select Select inside loop

SQ-11

Select Statement

Standard

SQ-12

Select Statement

Standard

SQ-13 SQ-14

Database joins For all entries

Recommendation Recommendation Recommendation

SQ-15

Select Statement

11

ISG-QMS-COD003-3.0

SAP Standards: SQL

Official Use Only

SAP Standards: SQL


ID SQ-16 Guidelines Select Statement Standard/ Recommendation Class If you are selecting a set of columns, make sure Recommenthat the work area and the database fields are of dation same type and length when using dynamic work areas. (620 Compiler throws a syntax error if the work area wide does not match the width of the selected database fields). Make use of corresponding fields statement only if it is required as it requires more runtime. When defining the work area for transaction Recommenrelated programs, make sure the work area is dation defined referring or including the structure rather than including the fields of the structure in the work area. This makes sure that work area always has the latest structure definition. Example

SQ-17

Select Statement

12

ISG-QMS-COD003-3.0

SAP Standards: SQL

Official Use Only

SAP Standards: Object Oriented


ID OO-01 Guidelines Boolean Methods Standard/ Recommendation Class These methods should not return any exceptions Standard (otherwise they should be defined as CHECK_ or generic methods). Methods in a class must be listed in the followed Standard order of their visibility (with exception of CLASSCONSTRUCTOR and CONSTRUCTOR methods, which are listed at the top): o Public o Protected o Private Example

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

OO-05 OO-06 OO-07 OO-08

Objects Exceptions Objects Initialization

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

Standard Standard Standard 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

SAP Standards: Object Oriented

Official Use Only

SAP Standards: Transport Request


ID TR-01 Guidelines Request Description Standard/ Recommendation Class Maintenance Log No (UCM/JIRA/Project Id) Standard should be mentioned in the beginning of the Short Description Example UCM11818 - SRM changes for Requisition role resolution. OR SP0019 - Trip Approval for LLF enhancements

TR-02

Request Consistency check Storing Objects in TR

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

Transport Request Description

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

SAP Standards: Transport Request

Official Use Only

SAP Standards: General


ID Guidelines Standard/ Recommendation Class Example Not intended for peer review of source code, but general standard for developers.

G-01

Development Class

G-02 G-03 G-04

SAP Program Modification SLIN Break-point

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

Standard Standard Standard BREAK WB240202.

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

Standard Standard Standard

Age Analysis Report

Ex: BASIS for system programs

G-08 G-09 G-10 G-11

Standard Standard Standard Standard

G-12

Standard

G-13

Message Text

Standard

G-14

Message Variable

Standard

G-15

Dynamic Messages

Standard

G-16

Character - Data type c

Standard

check ch_subrc eq '4'. NOT ch_subrc eq 4

15

ISG-QMS-COD003-3.0

SAP Standards: General

Official Use Only

SAP Standards: General


ID G-17 Guidelines Standard/ Recommendation Number type - Data type Use numbers instead of character strings I, P etc Mixed types Check for initial values Avoid mixing data types for calculations unless it is necessary Always use 'IS INITIAL' statement to check variables for initial values than using space, 0 etc. easy to understand the logic/code Class Standard Example sy-subrc eq 4 NOT sy-subrc eq '4'

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

Code Layout and Presentation

16

ISG-QMS-COD003-3.0

SAP Standards: General

Official Use Only

SAP Standards: General


ID G-30 G-31 Guidelines Code Layout and Presentation Code Layout and Presentation Code Layout and Presentation Filenames Standard/ Recommendation Begin each new statement in a new line. Avoid excessive nesting of IF statements. Consider the use of CASE statements to resolve such nesting, if possible. Avoid the replication of code by using FORMs, INCLUDEs, functions, etc. Filenames must be prefixed with the complete path name where the file is stored (or will be created). Avoid hard-coding of the paths in the program or defining it as constant in the variable declaration section of program. No new macros should be allowed. Handle exceptions when calling a function module Class Standard Standard Example

G-32 G-33

Standard Standard

G-34 G-35 G-36 G-37

Macros Exceptions Texts Import parameters

Standard Standard

G-38

Standard SAP Table modification Lock Objects usage

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

G-41 G-42 G-43 G-44

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

SAP Standards: General

Official Use Only

SAP Standards: General


ID G-46 Guidelines Table Types Standard/ Recommendation If the table type is based on SAP delivered (or custom created) structure or table, programmers are encouraged to use the same name as that of structure or table (excluding the namespace from the structure or table name). If it is a large scale enhancement, create a new include/subroutine pool etc to add new subroutines, programs etc Variables of same type should be declared in alphabetical order, however a group of variables that belong to same context should be declared at one place (separated from the rest by a blank line). Sort statement should not be inside loop. Class Recommendation Example

G-47

Modularization

Recommendation Recommendation

G-48

Code Layout and Presentation

G-49 G-50 G-51

Sort statement Sort statement Data Dictionary objects

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

G-52 G-53 G-54

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

SAP Standards: General

Official Use Only

Template Change History


Change Request ID Baselined Section Changed All New Version 3.0 Author / Date Approved By / Date Change Summary

J. Pauline SEPG Devaraj 04/20/2006 04/20/2006

Initial release of the new standards in spreadsheet format. This new standard will also replace the SAP Code Review Checklist (COD-004).

19

Ver. 3.0 04/20/2006

Software Coding Process SAP Coding Standards

Vous aimerez peut-être aussi