1、关于内表的一些操作
TYPES: BEGIN OF t_marc,
matnr type marc-MATNR,
BSTRF type marc-BSTRF,
END OF t_marc.
DATA:LT_MARC TYPE TABLE OF t_marc,
LT_MARC02 TYPE TABLE OF t_marc,
ls_marc type t_marc.
"eg:查询数据作为操作内表
select matnr BSTRF
into table lt_marc
from marc
UP TO 500 ROWS.
"对内表进行排序
SORT LT_MARC BY MATNR DESCENDING.
"对内表根据物料号去重
delete ADJACENT DUPLICATES FROM LT_marc COMPARING matnr.
""获取内表的行数
data:line type i .
line = lines( lt_marc ).
"读取内表的数据到工作区内
READ TABLE LT_MARC INTO LS_MARC WITH KEY MATNR = ''."根据条件获取对应数据
READ TABLE LT_MARC INTO LS_MARC INDEX 1."根据索引获取对应的数据
"查询内表内是否包含某个数据而不存到内表内
READ TABLE LT_MARC TRANSPORTING NO FIELDS WITH KEY MATNR = ''.
"声明结构和内表
TYPES: BEGIN OF t_marc02,
matnr type marc-matnr,
BSTRF type marc-BSTRF,
END OF t_marc02.
data:lt_collect type TABLE OF t_marc02,
ls_collect type t_marc02.
"把表1的几列放到表2中去
lt_collect = CORRESPONDING #( lt_marc ).
"把表内相同物料号的BSTRF 数值相加
loop at lt_marc into data(ls_marc03).
ls_collect = CORRESPONDING #( ls_marc03 ).
COLLECT ls_collect into lt_collect.
endloop.
"把内表的数据赋值给一个新的内表
data(lt_newmarc) = lt_marc[].
"把内表A的值添加到内表B中,不影响原本内表B的数据
APPEND LINES OF lt_marc TO LT_MARC02.
"删除内表的数据
delete lt_marc INDEX 1."根据索引删除内表的第一行数据
delete lt_marc where MATNR = ''."删除对应的物料号数据
delete lt_marc from 1 to 2 where MATNR = ''."删除符合条件的前两条数据
delete lt_marc from lt_marc02."根据内表删除
"内表的MODIFY操作,修改内表的值
READ TABLE lt_marc INTO LS_MARC INDEX 1.
LS_MARC-BSTRF = '536.36'.
MODIFY LT_MARC FROM LS_MARC."根据工作区进行修改
MODIFY LT_MARC FROM LS_MARC TRANSPORTING BSTRF WHERE MATNR = ''."根据内表修改对应的字段
"使用二分法查询时,需要事先进行排序
SORT lt_marc by matnr DESCENDING.
READ TABLE lt_marc into LS_MARC with key MATNR = '' BINARY SEARCH.
2、字符串的一些处理
DATA:s1(10) type c VALUE 'HELLO',
s2(10) type c VALUE 'WORLD',
s3(50) type c,
s4(5) type c VALUE 'L',
s5(10) type c,
s6(10) type c,
long TYPE i.
s3 = s1 && s2. "通过&&进行拼接
CONCATENATE s1 s2 into s3."通过 CONCATENATE 进行拼接
CONCATENATE s1 s2 into s3 SEPARATED BY '||'."通过 CONCATENATE进行拼接,并设置对应的分隔符
SEARCH s1 for 'H'.""查询字符串中是否含H
CONDENSE s1 NO-GAPS."去除空格。
SPLIT s1 at s4 into s5 s6."分割字符串
long = strlen( s1 ). "获取字符串长度
TRANSLATE s1 TO UPPER CASE. "转换成大写
TRANSLATE s2 TO LOWER CASE. "转换成小写
CONV:类型强制转换
CONV 类型( 数据 )
eg:DATA(L_MK_GD) = CONV QSOLLWERTC( 0 ).