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

G Global Attribute Constants, Static attributes
M Instance Attribute Object 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

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

 

發佈了68 篇原創文章 · 獲贊 52 · 訪問量 4萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章