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 | 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 |
---|---|---|
G | Global Attribute | Constants, Static attributes |
M | Instance Attribute | Object member |
L | Local Attribute | Declared in method, form, function module, etc. |
I | Importing Parameter | Interface of method, form, function module |
E | Exporting Parameter | Interface of method, form, function module |
C | Changing Parameter | Interface of method, form, function module |
R | Returning Parameter | Interface of method |
2.2 数据类型的标识
<Data Type> | Description | Remarks |
---|---|---|
C | Constant | |
D | Data | Only relevant for parameters or field symbols with a generic type |
O | Object Reference | Ref to class, interface, BAdI |
R | Data Reference | |
S | Structure | |
T | Internal Table | Table, Range (internal tables with special structure) |
V | Field | Any atomic value type (string, char, numc, int, dec, float, ...) |
X | Object Reference to Exception Class |
2.3 命名举例
iv_value_date | date for value date field as an importing parameter |
es_result | a strucute as a exporting parameter |
ct_name | an internal table as changing parameter with names |
mo_instance | an object as a class's attribute |
<ls_invoice> | invoice structure as a locally used field-symbol |
gc_costc_main | main 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. |
Views | V_<table name> | Name of the leading table |
View Cluster | VC_<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 Objects | E<general_prefix>_ |
5. 屏幕的parameter和select-options
Prefix | Description |
---|---|
P_ | Parameters |
S_ | Select-Options |
6. 其它数据对象
Object | Prefix | Remarks |
---|---|---|
Message Classes, Reports, Transactions | <general prefix>_ | |
Includes | I<general prefix>_ | |
Includes for unit tests | UT_<general prefix>_ | Same name as for class to be tested. Instead of CL_ use UT_ |
PFCG Roles | <general_prefix>_ | |
Authorization Objects | F_<general prefix>_ |
post SAP-Garson
原文链接:https://blog.csdn.net/nkGavinGuo/article/details/103141473文章来自于网络,如果侵犯了您的权益,请联系站长删除!