ABAP Dictionary
description
Transcript of ABAP Dictionary
E-1企業資源規劃 楊子青
ABAP Dictionary What is ABAP Dictionary ? Domain
– Value Range Data Element Table
– Table Fields– Technical Settings
• Data Class, Size Category, Buffering, Logging
– Foreign Keys
E-2企業資源規劃 楊子青
1. What is ABAP Dictionary ?
集中管理 R/3 系統中被使用到的所有資料定義– 建立使用者定義型態、定義 Database objects– Defining an input help
• Search Help (F4 help :輸入部分資料時,按此鍵會顯示所有可能值供選擇 )
• Attaching a field help (F1 help :欄位說明 )
E-3企業資源規劃 楊子青
ABAP Dictionary: Initial Screen Transaction Code: SE11
– 或 Tools→ ABAP Workbench→ Development→ ABAP Dictionary
按 F1 看看輸入部分值 * ,按 F4 看看( 例如 sbo* ,按 f4)
Domain
Data element
Table
E-4企業資源規劃 楊子青
ABAP Dictionary Basic Objects
Table
Domainuses
usesData element
Table field
定義資料型態及長度,以描述一 field之 value range
描述在一特定企業背景下,一 domain 所代表的意義。包含基本的 field help (F1 documentation)及 field labels 。
E-5企業資源規劃 楊子青
Two-Level Domain Concept
Domain reuse :可套用系統預先定義的 domains– 不同的 data elements 可能指定給同一 domain– 同理,不同的 fields 可能指定給同一 data element 。
Table SBOOK
. . . . . . FORCURAM . . . . . . .
Table SFLIGHT
. . . . . . . . . . PRICE . . . . . .
Data elementS_F_CUR_PR
Data element S_PRICE
Domain S_PRICE 長度 15 ,小數 2
票價 運費
E-6企業資源規劃 楊子青
SBook
E-7企業資源規劃 楊子青
2. Domain
Table 欄位的技術定義– 獨立存在於 ABAP Dictionary– 設定資料型態及長度,以描述一 field之
value range– 控制 fields 外觀: output length、 uppercase/
lowercase letters
E-8企業資源規劃 楊子青
Create a Domain
SE11 勾選 Domain ,輸入欲定義之 Domain 名稱 ( 例如 zyy**_domain1。 yy 為民國年, ** 為自己編號 )
按 create 按鈕,即可進入編輯畫面 ( 見下頁 )– Short text :簡短敘述 (如 zyy**_domain1 domain)– Data type :選擇資料型態 (如 char)– No. characters :長度– Decimal Place :小數點位置– 按 Save ,選 local object( 暫時留在本台機器,測試 )– 記得 save 後,一定要按 Activate ,才會存至底層 DB
E-9企業資源規劃 楊子青
Domain 編輯畫面
Enter a description (short text).
Enter data type and length.
控制 fields外觀 .
Save
Activate
E-10企業資源規劃 楊子青
2.1 Value Range
Fixed Value– 將 fields 的值限定在一有限集合內
• 個別設定 (Single vals.) :以列舉方式設定,例如定義性別之 domain ,其值可設為 M及 F
• 區間設定 (Intervals) :設定 Lower limit及 Upper limit ,例如年資為 (0,40)
Value Table– 搭配 foreign key 的定義, value table 可變成
check table ,而具有 check 之作用 (見 p.31-33)
E-11企業資源規劃 楊子青
Value Range 標籤畫面
E-12企業資源規劃 楊子青
練習:請先建立下表之 Domain
Table Field Data Element Domain Type
zyy**_DEP DEPID zyy**D_ID zyy**D _ID CHAR 5
DEPNAME zyy**D_NAME Build-in type CHAR 20
zyy**_WAG CLASS zyy**W_CLS zyy**_CLASS CHAR 2
POST zyy**W_POS zyy**_POST CHAR 16
WAGE zyy**W_WAG zyy**_WAGE DEC 9 2
CURRENCY zyy**W_CUR WAERS CUKY 5
PS: Domain WAERS 為 SAP 內建之 Domain 直接套用之即可。
E-13企業資源規劃 楊子青
練習 (Cont.)
Table Field Data Element Domain Type
zyy**_EMP EMPID zyy**E_ID zyy**E_ID NUMC 5
DEPID zyy**D_ID zyy**D_ID CHAR 5
NAME zyy**E_NAME Build-in type CHAR 20
CLASS zyy**E_CLS zyy**_CLASS CHAR 2
SEX zyy**E_SEX zyy**_SEX CHAR 2
BIRTH Direct type DATS 8
ADDRESS Direct type CHAR 50
PS:每完成一 object的設定,務必存檔並 Activate之,方為正確完成設定。
E-14企業資源規劃 楊子青
練習:建立 Domain之 Fixed Value
在 Domain zyy**E_SEX 下建 Fixed value,如下:
E-15企業資源規劃 楊子青
3. Data Element Table fields 的語義定義
– 描述在一特定企業背景下,一 domain 所代表的意義 Create a Data Element
– SE11
– 勾選 Data type ,輸入欲定義之 Data Element 名稱 (如 zyy**_id1)
– 按 create 按鈕,即可進入編輯畫面 ( 見下頁 )• Short text :簡短敘述 (如 zyy**_id1 data element)
• Data type選 Elementary type( 基本型態 )– 若要參考先前定義之 Domain ,選 Domain 再輸入 Domain 名
稱– 若要自行定義,則勾選 Built-in type
• 按 Save ,再 Activate
E-16企業資源規劃 楊子青
Data Element 編輯畫面
Enter a description (short text).
Enter domain name.
E-17企業資源規劃 楊子青
練習 請建立 p.11-12之 Data Element 。
E-18企業資源規劃 楊子青
4. Table
Field 1 Field 2 Field 3 Field 4
TableTableFieldsFields
ForeignForeignKeysKeys
TechnicalTechnicalSettingsSettings
IndexesIndexes
E-19企業資源規劃 楊子青
Create a Table
SE11 勾選 Database table ,輸入欲定義之 Table 名稱 ( 例如 zyy**_table1)
按 create 按鈕,即可進入編輯畫面 ( 見下頁 )– Short description :簡短敘述 (如 zyy**_table1
table)– 在 Delivery Class按 F4 ,選 Application table (master
and transaction data)– 將 Table maintenance allowed 打勾,表示允許使用者直接輸入資料 ( 通常不勾,而由程式維護 )
– Save 後,再按 Activate
E-20企業資源規劃 楊子青
Table 編輯畫面
Enter a description (short text).
Maintain delivery class
Table maintenance allowed
E-21企業資源規劃 楊子青
4.1 Table Fields
Domain ( 建議使用此方式 )– 在 domain 設定 data type ,指定 domain給 data
element ,再指定 data element給 field 。 Build-in type
– 在 data element 設定 data type ( 即未定義 Domain) ,再指定 data element給 field 。
Direct type ( 儘量避免此方式 )– 直接在 field 設定 data type ,不指定 data element 。
E-22企業資源規劃 楊子青
Table Fields 編輯畫面
Maintain field attributes
輸入欄位名稱
主鍵 非空值
見上頁,可輸入data element
Data element 與直接輸入之切換
見 4.2
E-23企業資源規劃 楊子青
4.2 Technical Settings
Data Class– logically defines the physical area of the database in
which your table should be stored ( 存放內容 ) 。 Size Category
– describes the expected storage requirements for the table on the database ( 預期貯存空間 ) 。
Buffering– define whether and how the table should be buffered 。
Logging– define whether changes to the table entries should be
logged (DB 異動是否都記錄下來 ) 。
E-24企業資源規劃 楊子青
Technical Settings 編輯畫面
Maintain Data class
Maintain Size category
E-25企業資源規劃 楊子青
(1) Data Class
APPL0 (Master data): Data is seldom changed.– Ex: the data contained in an address file, such as name,
address, and telephone number. APPL1 (Transaction data): Data is frequently changed.
– Ex: the goods in a warehouse, which change after each purchase order.
APPL2 (Organizational data): Customizing data that is defined when the system is installed and seldom changed.– Ex: the table with country codes.
E-26企業資源規劃 楊子青
(2) Size CategoryInitialExtent
FirstExtent
SecondExtent
TABATABA
TABBTABB
TABCTABC
Database
Technical Settings
Size category
TABA
TABB
TABC
1
3
4
E-27企業資源規劃 楊子青
(3) Buffering 直接自 application server 的 local buffer 讀取 table
records ,排除費時的資料庫存取 先勾選 buffering switched on ,再選以下一種方式 :– Full buffering
• all the table records are loaded into the buffer when one record of the table is accessed 。
– Generic buffering• all the records whose left-justified part of the key is the same are
loaded into the buffer when a table record is accessed 。– Single-record buffering
• only the record that was accessed is loaded into the buffer 。 (buffer 最小,但是存取費時 )
E-28企業資源規劃 楊子青
Buffering 實例說明 以右下圖 Table 為例,執行以下 SQL 指令:
SELECT * FROM SCOUNTER WHERE MANDT = ‘001’ AND CARRID = ‘LH’ AND COUNTNUM =‘000004’– 選 full_buffering:整個 table的資料都放進 buffer contents– 選 generic buffering :先判斷 generic key為何者,假設為 MANDT與 CARRID ,則放進 buffer contents 的是001 LH 000001 BER001 LH 000002 FRA001 LH 000004 LCY
– 選 single-record buffering :僅放 一筆入 buffer contents 001 LH 000004 LCY
E-29企業資源規劃 楊子青
(4) Logging 記錄並儲存 table 內容的修改。
Logging
Applicationtransaction
Change a record
System profiles
rec /client =ALL
...
...
TAB
Field 2 Field 3 Field 5
TAB Log table
Field 1 Field 2 Field 3
Database
ABAP Dictionary
Log TABLog TAB
E-30企業資源規劃 楊子青
練習 請建立 p.11-12之 Table 及其 Fields 。
E-31企業資源規劃 楊子青
4.3 Foreign Keys
A foreign key 連結兩個 tables– 在 Foreign key table 輸入資料,必先
與另一 Check table 中已存在的資料核對,以確保資料的一致性。
Foreign
Foreign
E-32企業資源規劃 楊子青
Foreign Keys 的必要條件 The foreign key field and the primary key of the
check table must share the same domain. A value table must exist for that domain.
E-33企業資源規劃 楊子青
Foreign Key 設定畫面 Enter a description (short text).
Enter check table.
Maintain Cardinality
(A)
(B)
E-34企業資源規劃 楊子青
練習 Domain之 Value table
– 在 Domain zyy**D_ID 下,建 Value table zyy**_DEP
Table之 Foreign Keys– 在 Table zyy**_EMP 下,設定 Foreign Key :
• Field DEPID 指到 Table zyy**_DEP的 DEPID 。• Field CLASS 指到 Table zyy**_WAG的 CALSS。
E-35企業資源規劃 楊子青
Using a Table in Program Code
TABLES: SPFLI.
SELECT * FROM SPFLI.
WRITE: / SPFLI-CONNID, SPFLI-CARRID, SPFLI-CITYFROM,
SPFLI-CITYTO.
ENDSELECT.
E-36企業資源規劃 楊子青
練習:輸入欄位值 手動輸入方法
– 進入 Table 後,選功能表 Utilities → Table Contents → Create Entries 。輸入後 save、 activate 。
A1
E-37企業資源規劃 楊子青
實例練習:實驗室 table
E-38企業資源規劃 楊子青
實例練習:老師 table