matinal:SAP ABAP 7.40及以上新语法LOOP GROUP

2023-10-26 14:33:22 浏览数 (1)

LOOP GROUP 类似 AT NEW

代码语言:javascript复制
DATA:p_menge TYPE ekko-wkurs.
DATA:p_menge1 TYPE ekko-wkurs.

SELECT  *
 FROM ekko
 INTO TABLE @DATA(lt_ekko)
 UP TO 5 ROWS.
  
SORT lt_ekko BY lifnr ernam.

"我一般用这个写法,比at new自由很多,不受内表字段的顺序限制  
LOOP AT lt_ekko INTO DATA(ls_ekko)
  GROUP BY ( lifnr = ls_ekko-lifnr ernam = ls_ekko-ernam )."按括号里的条件进行分组
  LOOP AT GROUP ls_ekko INTO DATA(member)."按分组后进行组员的访问
    p_menge = p_menge   member-wkurs."这里就是对同一组的进行某个字段的汇总
  ENDLOOP.
  WRITE:/  p_menge.
  CLEAR p_menge.
ENDLOOP.

LOOP AT lt_ekko INTO DATA(ls_ekko1)
  GROUP BY ( lifnr = ls_ekko1-lifnr ernam = ls_ekko1-ernam ) INTO DATA(key2).
*  LOOP AT GROUP LS_EKKO1 INTO DATA(MEMBER1). "后面的工作区会将分类的两个字段加入进去,前面的工作区是没有值的
*  ENDLOOP.
  LOOP AT GROUP key2 INTO DATA(member2)."这里要用后面的工作区进行组员的访问
    p_menge1 = p_menge1   member-wkurs."这里就是对同一组的进行某个字段的汇总
  ENDLOOP.
  WRITE:/ p_menge1.
  CLEAR p_menge1.
ENDLOOP.

结果如下

0 人点赞