Function Module 内表内容比较

在开发中,经常用到同个内表内容比较的情况。

可以使用标准的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内容没有改变,如果为空则说明这两个内表内容不一致。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值