数据输出
- 使用write语句进行数据对象的输出
- 可在输出时控制对象的长度、输出位置及格式等属性的控制
- 可同时输出多个数据对象
- 不同队形通过“/”换行输出
语法:
write [/] [<pos>] [(len)] 资料项
/:换行
pos:屏幕x轴坐标
len:显示输出的长度
例如:
write: / 'lv_partner:',(3)lv_partner. "表示只输出3位
产生空白行:
skip [n]
例如:
write '例1'.
skip.
write '例2'.
include [symbol]或[icon]:引入
查看系统符号/图标
例子
include <symbol>
include <icon>
write: / 'phone symbol' sym_phone as symbol.
write: / 'alarm icon',icon_alarm as icon.
显示复选框数据
显示控件:
write <资料项> as checkbox.
例子:
data: flag1 value '',
flag2 value 'x'.
write: / 'check flag1:',
flag1 as checkbox.
write: / 'check flag2:',
flag2 as checkbox.
颜色输出
例子:
*----------预定义类型:变量----------*
data: lv_c(6) type c value 'ABCD123456', "运行只显示前六位
lv_d type d value '20210318',
lv_f type f value '544.35',
lv_i type i value 45678,
lv_n type(6) n value 12456,
lv_p type p value '555.22' decimals 2, "定义小数位
lv_t type t value '202020'.
write: / 'lv_c:',lv_c.
write: / 'lv_d:',lv_d.
write: / 'lv_f:',lv_f.
write: / 'lv_i:',lv_i.
write: / 'lv_n:',lv_n.
write: / 'lv_t:',lv_t.
*把lv_d设置为系统日期,lv_t设为系统时间
lv_d = sy-datum.
lv_t = sy-uzeit.
write:sy-uline. "系统变量:画横线
*----------自定义数据类型----------*
*数据元素
TYPES ty_bu_partner(10) type c,
ty_bu_partner1 type bu_partner, "参考字典内的类型
ty_bu_partner2 type ty_bu_partner, "定义参考自定义的类型
*结构体:可以使用types和data定义
types:begin of ty_partnerif, "业务伙伴信息
name(10) type c,
age(2) type i,
tel(11) type n,
end of ty_partnerif.
*----------变量----------* 参照自定义数据类型
data:lv_partner type ty_bu_partner,
lv_partner1 type ty_bu_partner1,
lv_partner2 type ty_bu_partner2,
lv_partnerif type ty_bu_partnerif, "结构体变量
*普通变量赋值
lv_partner = '张三'.
lv_partner1 = '李四'.
lv_partner2 = lv_partner.
write: / 'lv_partner:',lv_partner.
write: / 'lv_partner1:',lv_partner1.
write: / 'lv_partner2:',lv_partner2.
*结构赋值
lv_partnerif-name = lv_partner1.
lv_partnerif-age = 30.
lv_partnerif-tel = '123456'.
write: / 'lv_partnerif'.
write: / 'lv_partnerif-name',lv_partnerif-name.
write: / 'lv_partnerif-age',lv_partnerif-age.
write: / 'lv_partnerif-tel',lv_partnerif-tel.
*结构体继承
data:begin of ls_cus. "此时后面跟句号,因为INCLUDE STRUCTURE是单独使用
INCLUDE STRUCTURE ty_partnerif. "继承ty_partnerif
data:address(40) type c, "此时为逗号
end of ls_cus.
move-corresponding ty_partnerif to ls_cus. "相同字段赋值
ls_cus-address = '自定义字段赋值'.
write: / 'ls_cus:',ls_cus.
write: / 'ls_cus-name:',ls_cus-name.
write: / 'ls_cus-age:',ls_cus-age.
write: / 'ls_cus-tel:',ls_cus-tel.
write: / 'ls_cus-address:',ls_cus-address.