在开发中,经常用到同个内表内容比较的情况。
可以使用标准的Function Module来解决。更方便。
report zhk_test2.
types: begin of ty_s_table,
field1 type char2,
field2 type char2,
end of ty_s_table.
data: gt_table_old type standard table of ty_s_table,
gt_table_new type standard table of ty_s_table,
gwa_table type ty_s_table,
gt_table_del type standard table of ty_s_table,
gt_table_add type standard table of ty_s_table,
gt_table_mod type standard table of ty_s_table.
data: key_length type i,
flag type char1.
key_length = 2.
gwa_table-field1 = 'A1'.
gwa_table-field2 = 'B1'.
append gwa_table to gt_table_old.
gwa_table-field1 = 'A1'.
gwa_table-field2 = 'C1'.
append gwa_table to gt_table_new.
*gwa_table-field1 = 'A2'.
*gwa_table-field2 = 'B2'.
*append gwa_table to gt_table_new.
call function 'CTVB_COMPARE_TABLES'
exporting
table_old = gt_table_old
table_new = gt_table_new
key_length = key_length
importing
table_del = gt_table_del
table_add = gt_table_add
table_mod = gt_table_mod
no_changes = flag. "if flag is 'X' means no change, else if empty means changed.
write:1.
这个Function Module的功能。
输入参数:
TABLE_OLD:旧表
TABLE_NEW:新表
KEY_LENGTH:键长度,指定内表中的前若干个字节为主键,做为内表行是否为增加的判断条件。
IF_SORTED:排序标记,如果已排序,在比较时可以提高效率。
输出参数:
TABLE_DEL:被删除的行
TABLE_ADD:被增加的行
TABLE_MOD:被修改的行
NO_CHANGES:表没有被修改的标记,如果这个标记为 “X”,表示TABLE_OLD和TABLE_NEW内容没有改变,如果为空则说明这两个内表内容不一致。
本文介绍了一种在ABAP开发中高效的内表内容对比方法,利用FunctionModule 'CTVB_COMPARE_TABLES'来快速识别表格间的变化,包括新增、删除及修改的记录。
1508

被折叠的 条评论
为什么被折叠?



