LOOP AT GROUP BY语法练习

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.

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.

 

 

你可能感兴趣的:(SAP,ABAP)