Object-Oriented Class Development

Global Classes

Naming Conventions for custom classes.

 

Suggested Naming Standard

Class Name <Prefix><Class Prefix><Separator><Class Name>

 

 

Glossary

Prefix Z, Y or namespaceNormal customer developed objects should be prefixed with Z. Y should only be used when an object is local and will not be transported. When a namespace is involved that would be used as a prefix. i.e. "/Prefix/FIDEV"
Class Prefix FI, PP.MM etc.

Functional Application Area, Note it is typical to use SAP's Application Areas but others work as well.

Seperator  "_" use an underscore
Class Name

Class name, use proper nouns such as COMPANY_CODE GENERAL LEDGER_ACCOUNT etc.

 

 

 

 

 

 

 

 Examples:

A class should be named after the object it represents, for example, a master data class to maintain a vendor using the naming convention above would be ZCL_Vendor a class to define a customer could be ZCL_CUSTOMER obviously there can any type of variation but this is an example.

Persistent Classes


Persistent classes are classes that utilize the persistent services and provide an abstraction layer of the database tables.
Because they differ from the standard classes a leading practice is to identify them differently so we recommend a separate naming guideline :

Examples: As above a class that manages the persistence to a table called ZTAB would be named ZCL_PERS_ZTAB.

 


Attributes


A class attribute similar to a variable in a regular program is a reference to a memory location where you can store data. An attribute of a class when instantiated is a block of memory reserved for an instance.

Attributes, since they are isolated to the instance, provide a little more flexibility as to naming and the naming should be descriptive of the attribute.
An attribute should use the following naming convention.

Suggested Naming Standard

Attribute Name <Descriptive name>

 

 

Glossary

<Descriptive Name>

Descriptive attribute name that identifies the value being captured, note Pascal case, When using multiple works first letter is capital.

 

 

 


Examples:
- an Attribute for a country code could be CountryCode.
- an attribute for a bool type identifying whether a document has been printed could be HasPrinted
- an attribute for a generalLedgerAccount, note that we do not use the acronym though we could GLaccount but the latter is less descriptive and the full name is very clear.
Remember that the length of the name has no impact on performance it is only important for code clarity so use it.

Note about Self reference when referencing attributes within a method of a class the use of me-> to reference the attributes is not required by ABAP itself but is, as a rule, a best practice to emphasize the distinction between local variables and class attributes that may be already available.

 

Methods


Naming Conventions for class Methods.

Suggested Naming Standard

Method Name  

 

Glossary

Method Name

Method name, use clear verbs to describe what the method does I.e. PRINT

 

 

 

Method Parameters


Naming Conventions for Method Parameters

Suggested Naming Standard

Method parameter <Type>_<Parameter description>

 

 

Glossary

Method Name

Type of parameter, E = Exporting , I = Importing etc.

<Parameter Description>

Descriptive name for the parameter being passed

 

 

 

 

 

Examples
a general ledger account class has server parameters identified for the constructor method, they would be

I_generalLedgerAccount
I_companyCode

Error Classes

Error classes are classes specifically designed to trap errors from a class

Naming standard is
Prefix ZCX_object name

Preferably the object name is the same as the Class Object name that it is linked to, so furthering out examples, the ZCL_generalLedgerAccount class has an Error Class called ZCX_generalLedgerAccount.

= Variable Naming =

Global vs. Local objects.
In ABAP objects its possible to isolate variables within the class instance, in standard procedural code it is up to the developer to ensure they limit the variables available to only the modules that need access to it. Thus all variables should be local to a module unless the variable will be used across modules.

Naming conventions for ABAP variables.

     
Go To Top