ABAP编程命名规范

0. 通用前缀

通用前缀是标识代码用途的重要手段,通常在项目中会以项目名作为一种通用的前缀;在SAP系统中也是类似的,例如使用FI,MM等模块作为通用前缀。

  • SAP前缀举例:FI_xxx
  • 项目前缀举例:ABC_xxx

通用前缀在下文将使用<general prefix>或<prefix>表示。

注:对于客户定制的代码,对象的命名空间为Y或Z。

1. 类的命名(Class)

1.1 全局类 (Global Class)

Name

Class

CL_<prefix>_Standard Class
CF_<prefix>Factory Class
CX_<prefix>_Exception Class
IF_<prefix>_Interface
TC_<prefix>_Global Test Class
TD_<prefix>_Global Test Double 
TH_<prefix>_ Global Test Helper Class

1.2 局部类(Local Class)

Name

Class

LCL_General local class
LTC_ABAPUnit: Test class
LTD_ABAPUnit: Test Double
LTH_ABAPUnit: Helper Class

1.3 方法名 (Methods)

Type

Pattern

Examples

变量访问 Attribute Accesses

SET_<attribute_name>

GET_<attribute_name>

 
Check方法 (with exceptions) CHECK_<objective> 
事件 Events<noun>_<participle>BUTTON_PUSHED, DOCUMENT_POSTED
通用方法 General Methods<verb>_<noun>GET_STATUS, DETERMINE_DUE_DATE

返回方法 Return a boolean value
(without exceptions)

IS_<adjective>

HAS_<adjective>

EXISTS_<adjective>

 

事件响应方法

Methods that handle an event

ON_<event_name>

 

2. 属性命名和变量命名

通用的命名规则即:<Attribute Type><Data Type>_

2.1 属性类型的命名

<Attribute Type>

Description

Remarks

GGlobal AttributeConstants, Static attributes
MInstance AttributeObject member
Local Attribute Declared in method, form, function module, etc.
Importing Parameter Interface of method, form, function module
Exporting Parameter Interface of method, form, function module 
Changing Parameter Interface of method, form, function module
Returning Parameter Interface of method 

2.2 数据类型的标识

<Data Type>

Description

Remarks

CConstant 
DDataOnly relevant for parameters or field symbols with a generic type
OObject ReferenceRef to class, interface, BAdI
RData Reference 
SStructure 
TInternal TableTable, Range (internal tables with special structure)
VFieldAny atomic value type (string, char, numc, int, dec, float, ...)
XObject Reference to Exception Class 

2.3 命名举例

iv_value_datedate for value date field as an importing parameter
es_resulta strucute as a exporting parameter 
ct_namean internal table as changing parameter with names
mo_instancean object as a class's attribute
<ls_invoice>invoice structure as a locally used field-symbol
gc_costc_mainmain cost center defined as a global constant

3. 数据类型的定义命名

Prefix

Type

TY_Field
TS_Structure

TT_

Standard Table, Index Table

TTS_Sorted Table 
TTH_Hashed Table
TTA_Any Table
TM_Mesh

4. DDIC数据字典对象

Object

Prefix

Remarks

Database Table<general_prefix>_ Short version of general prefixed used because table name length is rather short.
ViewsV_<table name> Name of the leading table 
View ClusterVC_<name> 
Data Elements, Domains<general_prefix>_If Domain only used for one data element then domain name should be same as data element.
Structures<general_prefix>_S_ 
Range Structures<general_prefix>_S_RANGE_ 
Table Types<general_prefix>_T_ 
Enqueue ObjectsE<general_prefix>_ 

5. 屏幕的parameter和select-options

Prefix

Description

P_Parameters
S_Select-Options

6. 其它数据对象

Object

Prefix

Remarks

Message Classes, Reports, Transactions<general prefix>_ 
IncludesI<general prefix>_  
Includes for unit testsUT_<general prefix>_Same name as for class to be tested. Instead of CL_ use UT_
PFCG Roles<general_prefix>_ 
Authorization ObjectsF_<general prefix>_ 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

十年铸器

给作者赏杯咖啡

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值