按内表某些字段汇总处理

来源:互联网 发布:ubuntu ssh key 登录 编辑:程序博客网 时间:2024/05/01 23:20
report.

databegin of itab occurs 0,
        field1 type c,
        field2 type c,
        value type i,
      end of itab.

itab-field1 1.
itab-field2 1.
itab-value 2.
append itab.

itab-field1 1.
itab-field2 1.
itab-value 2.
append itab.

itab-field1 1.
itab-field2 2.
itab-value 2.
append itab.

datal_sum(2type c.

datal_curr type string"当前行内容
      l_pre  type string"上一行内容

loop at itab.

  concatenate itab-field1 itab-field2 into l_curr.

  if l_curr <> l_pre and sy-tabix <> 1.
    write:'总和:'l_sum,'处理内容:',l_pre.
    clear l_sum.
    l_pre l_curr.
  elseif sy-tabix 1.
    l_pre l_curr.
  endif.

  l_sum l_sum + itab-value.

  at last.
    write:'总和:'l_sum,'处理内容:',l_pre.
    clear l_sum.
  endat.
endloop.

原创粉丝点击