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

LOOP GROUP 类似 AT NEW

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.

matinal:SAP ABAP 7.40及以上新语法LOOP GROUP_第1张图片

结果如下

matinal:SAP ABAP 7.40及以上新语法LOOP GROUP_第2张图片

你可能感兴趣的:(ABAP技术,1024程序员节,服务器,大数据,前端,运维,linux,python)