Show TOC Start of Content Area

Background documentation Naming Conventions in ABAP Objects   Locate the document in its SAP Library structure

The global classes and interfaces you create in the Class Builder are stored in the class library and administered by the Repository. They belong to the same namespace as all other repository objects (database tables, structures, data elements, and so on). It is therefore necessary to have naming conventions for object types and their components and to use them consistently during program development.

Note

The following naming convention should be used in the SAP namespace. If you do not observe the naming conventions for object types (classes and interfaces), conflicts may occur.

Namespace for Components

A single namespace is shared by:

      All components of the class itself (attributes, methods, events, constructors, interfaces, internal data types in the class, and aliases)

      All public and protected components of the superclasses of the class.

Note

Method implementations use a local namespace. The names of the local variables can obscure those of class components.

Naming Convention

General Remarks

When you choose names for development objects:

      Use English names

      Use glossary terms when possible

For example, CL_COMPANY_CODE instead of BUKRS.

      In compound names, use the underscore character (_) as a separator. Since names are not case-sensitive, this is the only character you can use to separate names.

For example, CL_COMPANY_CODE, CL_GENERAL_LEDGER_ACCOUNT.

      Names should describe the action, not the implementation of the action.

For example, PRINT_RECTANGLE, not RECTANGLE_TO_SPOOL.

Conventions for Object Types

Class and interface names in the class library belong to the same namespace as data elements, tables, structures, and types. They are maintained centrally in the table TADIR.

Class in the class library

CL_<class name>

The class name should consist of singular nouns.

CL_COMPANY_CODE, CL_GENERAL_LEDGER_ACCOUNT

Interfaces in the class library

IF_<interface name>

The same naming convention as for classes.

IF_STATUS_MANAGEMANT, IF_CHECKER

Local classes in programs (recommendation)

LCL_<class name>

The class name should consist of singular nouns.

LCL_TREE_MANAGEMENT

Local interfaces in programs (recommendation)

LIF_<interface name>

The same naming convention as for classes.

LIF_PRINTER

Note

These naming conventions are not compulsory. However, if you use prefixes for class and interface names, you should use those listed above.

Conventions for Components

Method name

<method name>

Method names should begin with a verb:

GET_STATUS, CREATE_ORDER, DETERMINE_PRICE

Events

<event name>

Event names should have the form <noun>_<participle>:

BUTTON_PUSHED, COMPANY_CODE_CHANGED, BUSINESS_PARTNER_PRINTED

Local type definitions within a class (recommendation)

TY_<type name>

TY_INTERNAL_TYPE, TY_TREE_LIST

Data definitions (variables)

<variable name>

When you name variables within a class (CLASS-DATA or DATA), avoid using verbs at the beginning of the name (to avoid conflicts with method names).

LINE_COUNT, MARK_PRINTED, MARK_CHANGED, STATUS

Data definitions (constants) (recommendation)

CO_<constant name>

CO_MAX_LINE, CO_DEFAULT_STATUS, CO_DEFAULT_WIDTH, CO_MAX_ROWS

Note

These naming conventions are not compulsory. However, if you use prefixes for class and interface names, you should use the ones listed above.

Concrete Method Descriptions

Attribute access

SET_<attribute name>, GET_<attribute name>

Methods that access attributes of any kind should have the prefix GET_ or SET_.

GET_STATUS, SET_USE_COUNT

Event handler methods

ON_<event name>

Methods that handle events should begin with ON, followed by the name of the event that they handle.

ON_BUTTON_PUSHED, ON_BUSINESS_PARTNER_PRINTED

Methods that perform type conversions

AS_<new type>

AS_STRING, AS_ISOCODE

Methods that return a Boolean value

 

IS_<adjective>

IS_OPEN, IS_EMPTY, IS_ACTIVE

These methods may not return any exceptions.

Note

Use SPACE and X to indicate false and true.

Check methods

CHECK_<objective>

CHECK_AUTHORIZATION, CHECK_PROCESS_DATE

Local Conventions Within Methods

For parameters

The parameters are regarded from the point of view of the method that implements them:

IMPORTING parameters

IM_<parameter name>

EXPORTING parameters

EX_<parameter name>

CHANGING parameters

CH_<parameter name>

RESULT

RE_<result>

Note

Using prefixes is not compulsory but if you decide to use prefixes, use only the ones listed above.

For exceptions

The following table contains a series of possible exception names which can also be used generically (for example, NOT_FOUND could also be used as DATE_NOT_FOUND)

EXCEPTION

Meaning

ACTION_NOT_SUPPORTED

The requested action or function code is not supported.

CANCELLED

You can set this exception if a method uses a dialog to find out what has to be done (for example, a list of choices), and the user chooses Cancel.

EXISTING

A new object that you want to create already exists in the database.

FAILED

The method could not be executed because of the current environment. This exception is intended for cases where the method cannot be executed because of variable system circumstances.

..._FAILED

Part of the method could not be completed because of the current environment. (OPEN_FAILED, CLOSE_FAILED, SELECTION_FAILED, AUTHORIZATION_FAILED)

FOREIGN_LOCK

The data is locked by another user.

INCONSISTENT

The object data in the database is inconsistent.

..._INCONSISTENT

The component data for … of an object in the database is inconsistent.

INVALID

The object data entered is incorrect (for example, company code does not exist). Compare NOT_QUALIFIED.

..._INVALID

The component data entered for an object is incorrect. Compare NOT_QUALIFIED.

INTERNAL_ERROR

Use this exception only when you cannot be more precise about the nature of the error.

NOT_AUTHORIZED

The user does not have the required authorization.

NOT_CUSTOMIZED

The object requested is not correctly customized.

..._NOT_CUSTOMIZED

The component … of the requested object is not correctly customized.

NOT_FOUND

Unable to find the requested object.

..._NOT_FOUND

Unable to find a component … of the requested object.

NOT_QUALIFIED

The combination of input parameters is insufficient to run the method. Compare INVALID.

..._NOT_QUALIFIED

One parameter of the method is not qualified.

NUMBER_ERROR

Error assigning a number

SYSTEM_ERROR

This exception is set if the system returns an unexpected error message.

 

 

End of Content Area