Popular Posts
Enable SSL connection for Jsoup import org.jsoup.Connection; import org.jsoup.Jsoup; import javax.net.ssl.*; import java.io.IOException; import java.security.KeyManagement... Word break tag : <wbr/> (HTML5) The  HTML  <wbr>  tag  is  used  defines  a  potential  line  break  point  if  needed.  This  stands  for  Word  BReak. This  is  u... Build an OpenVPN server on android device Preparation An android device, in this case, Sony xperia Z is used Root permission required Linux Deploy for deploy i...
Stats
Text Symbols
*&---------------------------------------------------------------------*
*& Report  ZA000020                                                    *
*&                                                                     *
*&---------------------------------------------------------------------*
*&                                                                     *
*&                                                                     *
*&---------------------------------------------------------------------*

report  ZA000020                                .

write / TEXT-A01.                    " 文字元件, 類似Resource, 需先建立定義
write / 'Default text value'(A02).   " 同上, 可不先建立定義, 若未建立文字內容, 以引號內的內容為預設值

*
建立文字內容的方式有
  1. 在source code中, 雙擊文字元件變數, 會跳出對話窗
    按yes即可建立
  2. 在ABAP Editor(SE38)中, 選擇Text elements建立
text elements 編輯畫面
Introductory Statements for Programs
Program Type Introductory Statement
Executable Program REPORT
Module Pool PROGRAM
Function Group FUNCTION-POOL
Class Pool CLASS-POOL
Interface Pool INTERFACE-POOL
Subroutine Pool PROGRAM
Type Group TYPE-POOL
Include Program -
Internal Table: header line
types: begin of POW,
         NUM type I,
         NUM2 type I,
       end of POW.
data: ITAB type POW occurs 0,
      ROW type POW.

do 5 times.
  ROW-NUM = SY-INDEX.
  ROW-NUM2 = SY-INDEX ** 2.
  append ROW to ITAB.
enddo.

* ======================================================================
* "ITAB" is a table without a header line and therefore has no component
* ======================================================================
*do 5 times.
*  ITAB-NUM = SY-INDEX + 5.
*  ITAB-NUM2 = ITAB-NUM ** 2.
*  append ITAB.
*enddo.

loop at ITAB into ROW.
  write: / 'num:', ROW-NUM left-justified, ', num2:', ROW-NUM2.
endloop.
types: begin of POW,
         NUM type I,
         NUM2 type I,
       end of POW.
data: ITAB type POW occurs 0 with header line,
      ROW type POW.

do 5 times.
  ROW-NUM = SY-INDEX.
  ROW-NUM2 = SY-INDEX ** 2.
  append ROW to ITAB.
enddo.

do 5 times.
  ITAB-NUM = SY-INDEX + 5.
  ITAB-NUM2 = ITAB-NUM ** 2.
  append ITAB.
enddo.

loop at ITAB into ROW.
  write: / 'num:', ROW-NUM left-justified, ', num2:', ROW-NUM2.
endloop.
Internal Table: declare
types ARR type I occurs 10.                   " 定義長度為10的數值table/array

types: begin of CONTACT,                      " 定義CONTACT為work area, 並以CONTACT定義內表
         FIRST_NAME(15),
         LAST_NAME(15),
         EMAIL(30),
         TEL type N length 12,
       end of CONTACT,
       CTAB type CONTACT occurs 0.


data S1 type I occurs 10 with header line.    " 宣告包含header line(work area)的表變數
data S2 type I occurs 10.                     " 宣告無header line的表變數
data S3 type standard table of I.             " 取代舊occurs語法的宣告方式

data: begin of EMPLOYEE occurs 10,            " 宣告EMPLOYEE的表變數, 並定義其欄位
        FIRST_NAME(15),
        LAST_NAME(15),
        TEL type N length 12,
      end of EMPLOYEE.
Flow control: loop (while)
data: NUM type I,
      STR(1).

while SY-INDEX < 10.
  STR = SY-INDEX.
  NUM = NUM + SY-INDEX.
  if SY-INDEX > 1.
    write '+'.
  endif.
  write STR.
endwhile.

write: '=', NUM.
1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 =          45
Flow control : loop (do)
data: N1(1),
      N2(1),
      N3(2).

do 9 times.
  N1 = SY-INDEX.
  do 9 times.
    N2 = SY-INDEX.
    N3 = N1 * N2.
    write: N1, 'x', N2, '=', N3, '|'.
  enddo.
  write SY-ULINE.
enddo.
data: begin of TEXT,
        WORD1(4) value 'This',
        WORD2(4) value 'is',
        WORD3(4) value 'a',
        WORD4(4) value 'loop',
      end of TEXT.

data: STRING1(4), STRING2(4).

do 4 times varying STRING1 from TEXT-WORD1 next TEXT-WORD2.
  write STRING1.
  if STRING1 = 'is'.
    STRING1 = 'was'.       " TEXT-WORD2的值也會變更
  endif.
enddo.
    skip.

skip.

do 2 times varying STRING1 from TEXT-WORD1 next TEXT-WORD3
           varying STRING2 from TEXT-WORD2 next TEXT-WORD4.
  write: STRING1, STRING2.
enddo.
This is   a    loop

This was  a    loop
data: begin of WORD,
        W1(1) value 'a',
        W2(1) value 'b',
        W3(2) value 'c',
        W4(3) value 'd',
        W5(4) value 'e',
      end of WORD.

data LEN type I.
describe field WORD length LEN in character mode.       " 以文字模式計算物件長度

data STR2(1).
do len times varying STR2 from WORD-W1 next WORD-W2.    " STR2, WORD-W1, WORD-W2的類型及長度需相同
  write: '(' no-gap,  STR2 no-gap, ')'.
enddo.
(a) (b) (c) ( ) (d) ( ) ( ) (e) ( ) ( ) ( )
Flow control : if / case
if ... elseif ... else ... endif
data AGE type I value '12'.

if AGE < 0.
  write 'Illegal value'.
elseif AGE >= 0 and AGE < 18.
  write 'Sorry, this is adult only.'.
else.
  write 'Hi, wellcome.'.
endif.
case ... when .... when others ... endcase
data S(2) value 'F'.

case S.                      " case sensitive
  when 'F'.
    write / 'Hi, girl.'.
  when 'M'.
    write / 'Hi, boy.'.
  when others.
    write / 'Who it is?'.
endcase.
Call by value
data: NAME(20) value 'source',
      SOURCE(10) value 'Bruce',
      TARGET(10).

write (NAME) to TARGET.   " write ('source') to TARGET.
write / TARGET.           " 'Bruce' will be printed
assign value
data: S1(10) value '0123456789',
      S2(10).

S2 = S1.            " move S1 to S2.
write / S2.
clear S2.

S2 = S1+5(5).       " move S1+5(5) to S2.
write / S2.

S2+5(5) = S1(5).    " move S1(5) to S2+5.
write / S2.
clear S2.
0123456789
56789
5678901234
data: begin of ADDRESS,
        FIRST_NAME(10) value 'Bruce',
        LAST_NAME(10) value 'Tsai',
        TEL(12) value '28883912',
      end of ADDRESS.

data: begin of ACCOUNT,
        FIRST_NAME(10),
        LAST_NAME(10),
        EMAIL(50),
      end of ACCOUNT.

move-corresponding ADDRESS to ACCOUNT.
write / ACCOUNT-FIRST_NAME.
write / ACCOUNT-LAST_NAME.
Bruce
Tsai
Math function
函數 說明
ABS(N) 絕對值
SIGN(N) N>0 : 1, N=0 : 0, N<0 : -1
CEIL(N) 大於N的最小整數值
FLOOR(N) 小於N的最大整數值
TRUNC(N) 整數部份
FRAC(N) 小數部份
COS(N) 餘弦
SIN(N) 正弦
TAN(N) 正切
EXP(N) eN
LOG(N) logeN
LOG10(N) logN
SQRT(N) N的平方根
symbol & icon
include .
include .

write: / 'Phone Symbole:', SYM_PHONE as symbol.
write: / 'Alarm Icon:', ICON_ALARM as icon.
write
語法:
write at [/][<pos>][(<len>)] output
用法:
write 'Bruce'.                    " 輸出常數
Bruce
data CNAME(10) value 'James'.
write: / CNAME, 'is busy.'.       " 輸出變數, 多個值
James      is busy.
data NUM(10) value '0123456789'.
write / NUM.                      " 輸出變數
write /5 NUM.                     " 在位置5的地方輸出變數
write /(5) NUM.                   " 輸出5字元變數
write /5(5) NUM.                  " 在位置5的地方輸出5字元變數
0123456789  
     0123456789  
01234
     01234
declare
定義資料類型(EMPLOYEE):
TYPES dtype [TYPE type|LIKE dobj] ...
types: begin of EMPLOYEE,          " type definition
         WID(10) type C,
         FIRST_NAME(15) type C,
         LAST_NAME(15) type C,
         AGE type I,
       end of EMPLOYEE.
data EMP1 type EMPLOYEE.           " declare variant
types EMP like EMP1.               " type definition using exist variant
data EMP2 like EMP1.               " declare variant using exist variant
宣告變數(EMPLOYEE):
DATA var [{TYPE type}|{LIKE dobj}] ...
data: begin of EMPLOYEE,           " declare variant with structs
        WID(10) type C,
        FIRST_NAME(15) type C,
        LAST_NAME(15) type C,
        AGE type I,
      end of EMPLOYEE.
data EMP3 like EMPLOYEE.           " declare variant using exist variant
宣告常數:
constants: CNAME(10) value 'Bruce',
           BIRTHDAY type D value '19650201'.

constants: begin of MYADDRESS,
             NAME     type C length 20 value 'Fred Flintstone',
             STREET   type C length 20 value 'Cave Avenue',
             NUMBER   type P           value  11,
             POSTCODE type N length 5  value  98765,
             CITY     type C length 20 value  'Bedrock',
           end of MYADDRESS.
宣告表格:
tables: SPFL.                " load from ABAP/4 Dictionary
select * from SPFL.          " iterator data
  write: SPFL-MANDT,
         SPFL-CARRID,
         SPFL-CONNECTION.
endselect.