matinal:SAP ABAP 7.40及以上新语法-内表分类汇总

2023-10-14 14:58:54 浏览数 (1)

1个内表里有3个字段,字段1、2是主键,汇总放到字段3:

代码语言:javascript复制
REPORT zmatinal.
 
TYPES:
  BEGIN OF struct,
    key1 TYPE string,
    key2 TYPE string,
    col      TYPE i,
  END OF struct,
  itab TYPE STANDARD TABLE OF struct WITH EMPTY KEY.
 
DATA(itab) = VALUE itab(
                         ( key1 = `a` key2 = `a` col = 1 )
                         ( key1 = `a` key2 = `b` col = 2 )
                         ( key1 = `a` key2 = `a` col = 3 )
                         ( key1 = `a` key2 = `a` col = 4 )
                         ( key1 = `a` key2 = `b` col = 5 )
                         ( key1 = `b` key2 = `a` col = 6 )
                         ( key1 = `b` key2 = `a` col = 7 )  ).
 
DATA gt_co TYPE TABLE OF struct.
DATA gs_co TYPE  struct.
 
LOOP AT itab INTO DATA(wa_itab) GROUP BY ( key1 = wa_itab-KEY1 key2 = wa_itab-KEY2 ).  "这里去重
 
         gs_co-key1 = wa_itab-key1.
         gs_co-key2 = wa_itab-key2.
 
        LOOP AT GROUP wa_itab INTO DATA(tmp).
            gs_co-col = gs_co-col   tmp-col.
        ENDLOOP.
      
        APPEND gs_co TO gt_co.
 
ENDLOOP.
 
cl_demo_output=>write( gt_co ).
cl_demo_output=>display( ).

0 人点赞