1.测试内表的行数。lines( i_tab )
DATA: name(10) TYPE c VALUE 'SOURCE',
source(10) TYPE c VALUE 'Antony',
target(10) TYPE c.
...
WRITE (name) TO target.
WRITE target.
() 是先取里面的值.
============================
计算:
两数相除:
取商
div
取余数:
mod
============================
DATA: BEGIN OF rate,
usa TYPE f VALUE '0.6667',
frg TYPE f VALUE '1.0',
aut TYPE f VALUE '7.0',
END OF rate.
DATA: BEGIN OF money,
usa TYPE i VALUE 100,
frg TYPE i VALUE 200,
aut TYPE i VALUE 300,
END OF money.
MULTIPLY-CORRESPONDING money BY rate."两数相乘
============================
DATA: BEGIN OF series,
n1 TYPE i VALUE 10,
n2 TYPE i VALUE 20,
n3 TYPE i VALUE 30,
n4 TYPE i VALUE 40,
n5 TYPE i VALUE 50,
n6 TYPE i VALUE 60,
END OF series.
DATA sum TYPE i.
ADD series-n1 THEN series-n2 UNTIL series-n5 GIVING sum.
WRITE sum.
ADD series-n2 THEN series-n3 UNTIL series-n6 to sum.
WRITE / sum.
*:第二次是赋值是在第一次的基础上相加的。如果第行的to改为了GIVING那么sum上一次的150会被清空,成为200
===========================
计算数据的函数
abs ---Absolute value of the argument arg
sign ---Plus/minus sign of the argument arg: -1, if the value of arg is negative; 0 if the value of arg is 0; 1 if the value of arg is positive.
ceil ---Smallest integer number that is not smaller than the value of the argument arg.
floor ---Largest integer number that is not larger than the value of the argument arg.
trunc ---Value of the integer part of the argument arg
frac ---Value of the decimal places of the argument arg
==========================
*
Funktion func Meaning Definition Area
acos --Arcuscosinus [-1,1]
asin --Arcussinus [-1,1]
atan --Arcustangens
cos --Cosinus
sin --Sinus
tan --Tangens
cosh --Hyperbelcosinus
sinh --Hyperbelsinus
tanh --Hyperbeltangens
exp --Exponential function for basis e [-709, 710]
log --Natural logarithm > 0
log10 --Logarithm for basis 10 > 0
sqrt --Square root >= 0
==========================
时间计算的例子
* date calculation
DATA: ultimo TYPE d.
ultimo = sy-datum.
ultimo+6(2) = '01'.
ultimo = ultimo - 1.
WRITE ultimo.
ULINE.
* time calculation
DATA: diff TYPE i,
seconds TYPE i,
hours TYPE i.
DATA: t1 TYPE t VALUE '200000',
t2 TYPE t VALUE '020000'.
diff = t2 - t1.
seconds = diff MOD 86400.
hours = seconds / 3600.
WRITE: / text-001, hours.
ULINE.
* convert date
DATA: odate TYPE d VALUE '19955011',
idate LIKE odate.
DATA field(8) TYPE c.
field = odate. WRITE / field.
CONVERT DATE odate INTO INVERTED-DATE idate.
field = idate. WRITE / field.
CONVERT INVERTED-DATE idate INTO DATE odate.
field = odate. WRITE / field.
================================================
数据类型:
Predefined ABAP Types
The table below shows the predefined ABAP types. Additional attributes can be found under value ranges and initial values.
Type | Length | Standard length | Description |
b | 1 Byte | 1 byte integer (internal) | |
c | 1 to 65,535 characters | 1 character | Text field |
cursor | as i | as i | Database cursor |
d | 8 characters | Date field | |
f | 8 bytes | Floating point number | |
i | 4 bytes | 4 byte integer | |
n | 1 to 65,535 characters | 1 character | Numeric text |
p | 1 to 16 bytes | 8 bytes | Packed number |
string | variable | Text string | |
s | 2 bytes | 2 byte integer (internal) | |
t | 6 characters | Time field | |
x | 1 to 65,535 bytes | 1 byte | Byte field |
xstring | variable | Byte string |