Sap Coding Standards Erpams

  • Uploaded by: Naresh Vepuri
  • 0
  • 0
  • March 2021
  • PDF

This document was uploaded by user and they confirmed that they have the permission to share it. If you are author or own the copyright of this book, please report to us by using this DMCA report form. Report DMCA


Overview

Download & View Sap Coding Standards Erpams as PDF for free.

More details

  • Words: 5,391
  • Pages: 19
Loading documents preview...
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.

Purpose

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.

Guideline

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.

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.

1

Ver. 3.0 04/20/2006

Software Coding Process SAP Coding Standards

Official Use Only SAP Standards: Style ID ST-01

ST-02 ST-03

ST-04

ST-05 ST-06

ST-07

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.

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 Processing blocks must precede with a label header.

Standard

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

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.

Recommendation

ST-10

Output display header

If standard report/screen headers are defined and in use for a team/project , then they must be used.

Recommendation

2

Data: GV_UPD. " Update Indicator

Pretty Printer

Modularization for Report programs Modularization for Report programs

ST-08

Example

ISG-QMS-COD003-3.0

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

SAP Standards: Style

Official Use Only

SAP Standards: Naming Convention ID

Guidelines

NC-01 NC-02

Data Elements Message Class

NC-03 NC-04 NC-05 NC-06 NC-07

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

NC-08 NC-09 NC-10 NC-11 NC-12

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

NC-21

3

Transparent Table Names View Names Structure Names Domains Table Types Search helps Adding fields to a standard table Enhancements Package

Naming Packages

ISG-QMS-COD003-3.0

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.

_ PBO modules should start with PBO PAI Modules should start with PAI POV should start with POV POH modules should start withPOH <2 to 3 character Functional_area>_name __ _RF__ _UPD__ _BAPI__ Type Groups should not be prefixed with namespace; and hence must follow the following guidelines: Z<XX> 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

ZFISCAL_YR ZMM_PO_CLS

Standard Standard Standard Standard Standard

PBO_INITIALIZE PAI_FCODE POV_PO_VALUES POH_F1_FOR_XYZ ZMM_STC

Standard

Z_CREATE_VENDOR

Standard

Z_RF_CREATE_VENDOR_PARA

Standard

Z_UPD_VENDOR_MASTER_DB

Standard

Z_BAPI_CREATE_VENDOR

Standard

A constant declaration within a Type Group ZIL01 should be like ZIL01_C_SUCCESS



Standard

ZSTC_HDR

V_ S_ _TT_ _SHLP Column/Field names should start with ZZ**

Standard Standard Standard Standard Standard

ZV_STC_HDR_ITM ZS_STC_SCR_ITM ZFISCAL_YR Z_TT_EKBE ZPONUM_SHLP

To hold components related to SAP enhancements, package should be named as: Z__SAP_ENHANCEMENTS

Standard

Standard

To hold Type Groups and other exceptional Standard dictionary objects, package should be named as: Z__DICT_OBJ

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)

NC-23

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: _Name

Standard

NC-24

BAPI

Standard

/ILAP/BAPI_DIS_GET_WDRWL_APPL

NC-25

BAPI Parameters

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

I_CONTRACT_NUM

NC-26

Function Group

_ Standard

NC-27

Function Group

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

NC-28

Tables

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:_INTL_ID

NC-29

SEARCH HELP

_ Standard

NC-30

SEARCH HELP EXIT LOCK OBJECT

<Search help name>SH_EXIT

Number range objects



NC-31

NC-32

4

ISG-QMS-COD003-3.0

Example

Standard

E_ 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). Standard

/ILAP/ITXN

SAP Standards: Naming Convention

Official Use Only

SAP Standards: Naming Convention ID NC-33

Guidelines Transactions

Standard/ Recommendation Z__ Z_TM_

Class Standard

NC-34

Transactions for Table Maintenance

NC-35

Executable Report Program names Executable Interface Program Name

R<2 to 3 character Functional_area>_name I<2 to 3 character Functional_area>_name

Standard

B<2 to 3 character Functional_area>_name <MAIN_PRG_NAME><3 Char Value²>

Standard

SAPFZ<2 to 3 character Functional_area>_name

Standard

SAPFZ_SMRTFORM_ROUTINS

NC-40

Executable BDC Program Name Include Program Names with Main program Include Program Names without Main program (Subroutine Pool) Subroutine Names

Should start with F_** to represent form

Standard

F_GET_PO_DETAILS

NC-41

Classes

__ 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.

LCL_FRONTEND_SERVICES

NC-42

Interfaces

__ Interface visibility->LIF Local interface (use of namespace and function area prefixes not required), IF Global interface

LIF_FRONTEND_SERVICES

NC-43

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)

_<noun>

Standard

CREATE_CONTRACT

GET_ or SET_ ON_<EVENT_NAME>

Standard

GET_UPDATE_MODE, SET_UPDATE_MODE ON_MGR_APPROVAL

IS_ _<Past_tense_verb> CHECK_

Standard Standard Standard

NC-36

NC-37 NC-38

NC-39

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

5

ISG-QMS-COD003-3.0

Example

Standard

Standard

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

IS_APPROVED, IS_CANCELLED CONTRACT_APPROVED CHECK_CONTRACT_STAT CHECK_AUTHORIZATION CHECK_APPRV_CONDNS

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

XV for Variable, XS for Structures, XT for Internal table (based on the internal table type follow rules)

NC-52

Function Module / Form Table parameters Function Module Import Parameter / Form Using Parameter

T for standard table, TH for hashed table, TI Standard for Indexed table, TS for sorted table

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

Standard

IV_EBELN, IS_EKKO, IT_EKKO, ITH_EKBE for hashed table, ITI_EKBE for indexed table, ITS_EKBE for sorted table.

NC-54

Function Module Export Parameter

EV for Variable, ES for Structures, ET for Internal table (based on the internal table type follow rules)

Standard

NC-55

Method Import Parameter

IV for Variable, IS for Structure, IT for Internal table (based on the internal table type follow rules)

Standard

NC-56

Method Export Parameter

EV for Variable, ES for Structures, ET for Internal table (based on the internal table type follow rules)

Standard

NC-57

Method Changing parameter

NC-58

Method Returning parameter

NC-59

Method table parameters

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

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

NC-60

Subroutine Formal Parameters

FPV for Variable, FPS for Structure, FPT for Standard Internal table (based on the internal table type follow rules)

FPV_EBELN, FPS_EKKO, FPT_EKKO, FPTH_EKBE for hashed table, FPTI_EKBE, PTS_EKBE.

NC-53

6

ISG-QMS-COD003-3.0

Standard

SAP Standards: Naming Convention

Official Use Only

SAP Standards: Naming Convention Standard/ Recommendation GR_** for Selection Range

Class Standard

Example GR_DATUM for SY-DATUM

LR_** for Selection Range

Standard

LR_DATUM for SY-DATUM

<FS_> for field symbols

Standard Standard



NC-65 NC-66

Guidelines Global selection Range Local selection Range Field Symbols Global Field Symbols Data References Data Types

DR_ TY__Name

Standard Standard

NC-67 NC-68 NC-69 NC-70 NC-71 NC-72 NC-73

Select-options Parameters Checkbox Radiobutton Table Control Tab Strip Subscreen

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

Standard Standard Standard Standard Standard Standard Standard

LDR_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

NC-74 NC-75

Custom Control CUSCTRL_** for Custom Control Screen input/output IP_** For Screen Input Variable Variable

Standard Standard

CUSCTRL_ALV_TREE IP_EBELN for PO Number

NC-76

OP_** For screen Output Variable

Standard

OP_ERNAM - User Name

NC-77

Screen output Variable Screen text

Standard

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

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. _

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

Parameters

Standard

NC-82

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

NC-83

Authorization Z Objects Transport Requests Transport requests must be named based on following standards:

ID NC-61 NC-62 NC-63 NC-64

NC-84

Standard

UPI_NOT_FOUND

Standard Standard

: -

7

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.

Class Standard

NC-86

Exception Class

Namespace>CX_

Standard

8

ISG-QMS-COD003-3.0

Example

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

Class Standard

IT-02

Reading internal table

Standard

IT-03

Binary Search

IT-04

Modify Index

IT-05

Deleting Entries

IT-06

For all entries

IT-07

Nested Loops

IT-08

Append Lines of

IT-09

Insert Lines of

IT-10

Free internal tables

IT-11

Work Area

IT-12

Copying Internal tables

IT-13

Delete adjacent duplicates

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

IT-14

Collect

Internal tables field types and length should be considered before using collect statement

Recommendation

IT-15

Modifying ITAB

IT-16

Select Statement

Use modify with TRANSPORTING F1 variant wherever applicable. SAP recommends using the MOVE statement instead of MOVE-CORRESPONDING for performance reasons

Recommendation Recommendation

9

ISG-QMS-COD003-3.0

Example

Standard

Standard

Standard Standard

Standard Standard

Standard

Standard Standard Standard

ITAB1 = ITAB2

Standard

SAP Standards: Internal Table

Official Use Only

SAP Standards: Data Dictionary ID DD-01

Guidelines Changing field Names

DD-02

Table Maintenance Generator

DD-03

Transaction code Maintain table views

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

DD-04 DD-05

Adding new fields to tables Built in types

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

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.

DD-07

Adding fields to a standard table

Use append structure to add new fields to standard tables.

10

ISG-QMS-COD003-3.0

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

Example

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

Recommendation Recommendation

Recommendation

SAP Standards: Data Dictionary

Official Use Only

SAP Standards: SQL ID SQ-01

Guidelines Select single

Class Standard

UP TO 1 ROWS

Standard/ Recommendation Always use select single 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.

SQ-02

SQ-03

Aggregate functions

Use aggregate functions wherever applicable

Standard

SQ-04 SQ-05

Index support Logical Operator

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

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

SQ-09 SQ-10

Nested Select Select inside loop

SQ-11

Select Statement

SQ-12

Select Statement

SQ-13

Database joins

SQ-14

For all entries

SQ-15

Select Statement

11

ISG-QMS-COD003-3.0

Example

Standard

Standard

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.

Standard Standard

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 SELECT…ENDSELECT statement than using an internal table.

Recommendation Recommendation

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

Standard

Standard

Recommendation

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.

SQ-17

Select Statement

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.

12

ISG-QMS-COD003-3.0

Example

SAP Standards: SQL

Official Use Only

SAP Standards: Object Oriented ID OO-01

Guidelines Boolean Methods

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

Standard

OO-05 OO-06

Objects Exceptions

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

OO-07 OO-08

Objects Initialization

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

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

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

Standard Standard

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

TR-02

Request Consistency check

TR-03

Storing Objects in TR

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.

TR-04

Transport Copies

Use transport copies to move program copies/application to another system during development phase.

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

Recommendation

Example UCM11818 - SRM changes for Requisition role resolution. OR SP0019 - Trip Approval for LLF enhancements

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

SAP Standards: Transport Request

Official Use Only

SAP Standards: General ID

Guidelines

G-01

Development Class

G-02 G-03

SAP Program Modification SLIN

G-04

Break-point

Standard/ Recommendation

Class

Example Not intended for peer review of source code, but general standard for developers.

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.

Standard

Standard

BREAK WB240202.

Program Title

Concise, Meaningful and easily identifiable title

Standard

Age Analysis Report

Production Program Status Application Component Assignment

Should have Customer Production Program status before transporting to Production Should be assigned to appropriate Application component

Standard

Fixed point arithmetic indicator Editor Lock Unicode Subroutine Formal Parameters types

Should be on. If unchecked, should justify

Standard

Should not enable editor lock Should be enabled Always specify types for routines formal parameters. Helps in code optimization and performance

Standard Standard Standard

G-12

Single Messages

Standard

G-13

Message Text

G-14

Message Variable

G-15

Dynamic Messages

G-16

Character - Data type c

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

G-05 G-06 G-07

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

15

ISG-QMS-COD003-3.0

Standard Standard

Standard

Ex: BASIS for system programs

Standard

Standard

Standard

Standard

check ch_subrc eq '4'. NOT ch_subrc eq 4

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

Class Standard

G-18

Mixed types

Standard

G-19

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

G-20

IF vs Case

Standard

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

G-22

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

G-23

G-24

Standard

Structure Names

G-26

Global Variables

G-27

BAPI Exceptions

G-28

Coding

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.

G-29

Code Layout and Presentation

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

ISG-QMS-COD003-3.0

If an integer has to be checked for initial value use is initial statement than checking for '0'.

Standard

G-25

16

Example sy-subrc eq 4 NOT sy-subrc eq '4'

UPI_NOT_FOU ND

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

SAP Standards: General

Official Use Only

SAP Standards: General ID G-30 G-31

G-32

Guidelines Code Layout and Presentation Code Layout and Presentation

G-33

Code Layout and Presentation Filenames

G-34 G-35

Macros Exceptions

G-36 G-37

Texts Import parameters

G-38

Standard SAP Table modification

G-39

Lock Objects usage

G-40

Code Layout and Presentation

G-41

Code Inspector

G-42

Boolean Variable

G-43

Numeric : Data type N

G-44

Negative statements

G-45

While vs Do

17

ISG-QMS-COD003-3.0

Standard/ Recommendation Begin each new statement in a new line.

Class Standard

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

Standard

Example

Standard Standard

Standard Standard

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

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

Use while statement than do statement wherever possible. While statement is faster and easier to understand

WRITE: gv_UPI, gv_name.

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.

Recommendation

SAP Standards: General

Official Use Only

SAP Standards: General ID G-46

Guidelines Table Types

G-47

Modularization

G-48

Code Layout and Presentation

G-49

Sort statement

G-50

Sort statement

G-51

Data Dictionary objects

G-52

Message Numbers

G-53 G-54

18

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).

Example

Recommendation Recommendation

Sort statement should not be inside loop.

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.

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&

ISG-QMS-COD003-3.0

Class Recommendation

Recommendation Performance hint Policy

SAP Standards: General

Official Use Only

Template Change History Change Request ID Baselined

19

Section Changed All

New Version 3.0

Author / Date

Approved By / Date

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

Change Summary

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

Ver. 3.0 04/20/2006

Software Coding Process SAP Coding Standards

Related Documents

Coding Standards
January 2021 1
Coding Python
January 2021 1
Belajar Android - Coding
January 2021 1

More Documents from "Rafa"