# 113-2 SAP ABAP 總複習 ## ABAP ### ABAP **A**dvanced **B**usiness **A**pplication **P**rogramming 高級商務應用程式語言 - SAP 上開發工具的程式語言 - 處理 Application Program 的開發(報表 Reporting、對話程式 Dialog …) - 結合 SQL 語法特性的**第四代程式語言** - 事件導向 Event-Orient ### T-code - ABAP Dictionary (SE11) 創建資料表、結構表等等的開發工具 - Object Navigator (SE80) 集合所有 ABAP 開發相關的工作集 (包括SE38及SE11) - ABAP Editor(SE38) 新增/修改/查詢 ABAP 程式的開發工具 (Z開頭) - SU3 用於管理 SAP 系統使用者資料的T-code,使用者可以通過這個T-code來修改個人參數和設置。  ### Structure of Repository  ### Structure of Repository in SAP  ## Work Area / Internal Table ### Variables、Internal Table ABAP提供三種不同變數: - **Element Data Object**:單值變數 (e.g. 年齡) - **Work Area**:一個變數存放多個欄位,每個欄位型態不限。  - **Internal Table**:一個變數存放一整張table的資料。  ### Work Area 1. 先定義 structure type  2. 宣告一個 WORK AREA 變數,參照剛建立好的 structure type  3. 利用建立好的 WORK AREA 來指定要給值的欄位並給值   ### Internal Table 與 Transparent table 的差別 **Transparent table** ABAP Dictionary 中的表,儲存交易型資料,定義結構,資料庫 **Internal table** 建立在ABAP 程式內的變數,不在資料庫層級  ### Internal Table 1. 先建立 structure  2. 使用Structure分別建立 Work Area 與 Interal table  3. Work Area 填值  4. Internal table Append!  5. Work Area 填值  6. Internal table Append!  ### 建立Internal Table的Type  ## 增刪改查、語法補充 ### Return Code: sy-subrc **常見系統變數 SY** - ==SY-SUBRC==: (subroutine return code) - 系統執行某指令的Return Code - 前一個動作正確回傳0 - 錯誤則是其他數字 - SY-UNAME:當前使用者username - SY-DATUM:系統日期與時間 - ==SY-INDEX==:loop當前循環次數 - SY-MANDT:登入的client number - SY-VLINE:畫垂直線 - SY-ULINE:畫水平線 ### 增  ### 刪  ### 改  ### 查  ## ABAP Dictionary ### What is ABAP Dictionary ? SAP定義和管理資料的主要工具 負責操控、維護 ABAP 程式與資料庫 (Database) 之間的聯繫 可以用來定義系統中的各類資料對象,包括資料類型、資料表等 ### ABAP 基本物件關係  ## ABAP 程式語言 ### ABAP Program #### 基礎 - 定義變數 (TYPE & DATA) - 輸入 (PARAMETER) - 輸出 (WRITE) - 判斷式 (IF ELSE/CASE WHEN) - 迴圈 (DO/WHILE/LOOP AT) - 自訂函式 (PERFORM) #### 特殊 WORK AREA INTERNAL TABLE ### 以結構化程式設計歸納 - 循序(Sequential) : WRITE, PARAMETER - 選擇(Selection) : IF…ELSE, CASE…WHEN - 重複(Repeat) : DO...TIMES, WHILE  ## Modulation ### Modulation Overview All ABAP programs are modular in structure and made up of processing. There are 2 types of processing blocks 1. Called from **outside a program** by the ABAP runtime system 2. Called by ABAP statements in **ABAP programs**. 建立副程式(subroutine)需考慮: - **高內聚力(cohesion)**: 一個模組內只專注完成一件工作。 - **低耦合力(coupling)**: 模組與之間的互不影響,僅靠參數傳遞。 ### Called from ABAP Program - **Subroutine** - 內部 (local) It is a reusable section of code. - **Function Module** - 外部 (global) 可在SAP系統之間共享。 - **Method** – OOP 物件導向 It refers to a specific function or procedure within a class. It is a way of organizing and encapsulating code related to a specific task or behavior. - 封裝 (Encapsulation) - 繼承 (Inheritance) - 多型 (Polymorphism)  ### Subroutine - 主程式:透過 PERFORM 來呼叫子程式。 - 子程式:由 FORM 開頭,ENDFORM 結尾。 (可從當前程式及外部程式呼叫,也可以在Subroutuine內呼叫另一個Subroutuine)  #### Call by Value  #### Call by Reference  #### Call by Value and Result  ## Screens ### Selection Screen - 使用者輸入欲查詢的條件範圍,系統從資料庫中讀取資料並顯示報表 - 可讓使用者根據以下方式,選擇輸入方式: - 單一欄位搜尋 PARAMETERS  - 進階搜尋 SELECT-OPTIONS  ### 什麼是 Screen? 1. 即為一般所指的 Graphical User Interface (GUI) 2. 可與使用者互動 (對話程式;Dialog program),使畫面變化更多,可跨多個 screens 執行程式。  ### Screen Layout  ### SAP 的 Flow Logic Control 一個Dialog Program通常會包含PBO與PAI模組,透過Screen的Flow Logic來呼叫。 **程式執行的呼叫順序:** - **PBO (Process Before Output) module** 設定 Screen 在顯示前預先處理的動作,一般用來設定預設值,例如: 清空欄位。 - **PAI (Process After Input) module** 設定 Screen 在使用者輸入後須處理的動作,例如: 呼叫下一個 Screen  ## BAPI ### BAPI **B**usiness **A**pplication **P**rogramming **I**nterface **API**(Application Programming Interface)是廠商提供的連線接口 有預先寫好的 functions 可以提供給第三方開發者使用 給予 functions 指定的參數,可回傳想要的結果 BAPI 是基於 ABAP 語言 ### Tcode: BAPI  ### Standard Operating Procedures (SOP)  #### Step1: 建立 Structure  #### Step2: 建立 Function Group  #### Step3: 建立 Function Module  #### Step4: 建立 Business Object Type  #### 測試已建置的 BAPI  #### BAPI 測試結果  ### Business Object 架構  ## SAP JCo (Java Connector) ### Java Connector (JCo) 特色 - JCo 是 Java 跟 SAP 的中介層 - 可讓更多 Java 工程師簡單上手 SAP 開發 - 透過 Remote function call (RFC) 連結,可雙向溝通 - Java 可攜帶性高,可跨平台開發 
×
Sign in
Email
Password
Forgot password
or
By clicking below, you agree to our
terms of service
.
Sign in via Facebook
Sign in via Twitter
Sign in via GitHub
Sign in via Dropbox
Sign in with Wallet
Wallet (
)
Connect another wallet
New to HackMD?
Sign up