Presentation is loading. Please wait.

Presentation is loading. Please wait.

ABAP Basic Concept (2) 運算子 控制式與迴圈 Subroutines Event Block

Similar presentations


Presentation on theme: "ABAP Basic Concept (2) 運算子 控制式與迴圈 Subroutines Event Block"— Presentation transcript:

1 ABAP Basic Concept (2) 運算子 控制式與迴圈 Subroutines Event Block
IF, CASE, DO… ENDDO Subroutines Call by value, value and result, reference Event Block Initialization, Start-of-Selection, At Line-Selection

2 1. 運算子 比較運算子 = , <> , < , <= , > , >=
比較運算子 = , <> , < , <= , > , >= 算數運算子 + , - , * , /, mod (餘數) 邏輯運算子 AND , OR

3 2. 控制式與迴圈 IF子句 IF <Logical Expression> <Statements>. ELSEIF <Logical Expression> . <Statements>. ELSE . <Statements>. ENDIF . CASE子句 CASE < variable > . WHEN 'value1' <Statements>. WHEN 'value2' OR 'value3' <Statements>. WHEN OTHERS . <Statements>. ENDCASE .

4 控制式與迴圈 (Cont.) DO…ENDDO子句 DO 整數變數 TIMES. ENDDO. 範例: DATA X TYPE I.
DATA N TYPE I. X = 1. N = 5. DO N TIMES. WRITE: / X. X = X + 1.

5 3. Subroutines 第一行以FORM開始,最後一行以ENDFORM結束

6 參數傳遞方式 相同記憶體位址 CHANGING fv3 USING VALUE (fv1) 不同位址,但回傳後更改其值
呼叫副程式 USING VALUE (fv1) 不同位址,但回傳後更改其值 CHANGING VALUE (fv2) 相同記憶體位址 CHANGING fv3 CHANGING

7 練習F 計算總和副程式 (程式名稱zyy**_ex_f) 定義整數變數n,並設定n為6,請分別呼叫以下兩支副程式,再印出n值。
副程式1:利用call by value 根據傳來的n值,印出n平方 副程式2:利用call by reference

8 練習F參考解答 REPORT zyyTC_EX_F . DATA N TYPE I. N = 6.
PERFORM SQUARE1 USING N. WRITE: / 'N=', N. ULINE. PERFORM SQUARE2 CHANGING N. FORM SQUARE1 USING VALUE(X). X = X * X. WRITE: / 'Square1: N^2=', X. ENDFORM. FORM SQUARE2 CHANGING X.

9 4. Event Block 類似視窗系統之事件,無一定之執行順序,而由 runtime system 所決定 用法:
第一行以keyword為起始,無結束keyword 直到遇到下一個event block或FORM keyword才結束

10 Event Blocks for Reports

11 Event Blocks for Reports (Cont.)
The runtime environment creates the INITIALIZATION event and calls the event block. If there is a selection screen defined in the program, control returns to the selection screen processor. Control then passes to the reporting processor. It creates the START-OF-SELECTION event. The logical database, if you are using one, calls further event blocks at this point. The reporting processor creates the END-OF-SELECTION event. If the program contains a list description, it displays the list defined in the AT LINE-SELECTION event.

12 Major Event Blocks 設定初值 Basic list要用到的 event,用來產生report 範例
PARAMETERS INPUTN TYPE I. START-OF-SELECTION. IF INPUTN = 1 . WRITE : 'HI!'. ENDIF.


Download ppt "ABAP Basic Concept (2) 運算子 控制式與迴圈 Subroutines Event Block"

Similar presentations


Ads by Google