TYPES: BEGIN OF tp_t,
matnr TYPE matnr,
tipo type char1,
cont TYPE i,
END OF tp_t.
matnr TYPE matnr,
tipo type char1,
cont TYPE i,
END OF tp_t.
types gkey type TABLE OF tp_t WITH DEFAULT KEY.
DATA t_teste TYPE TABLE OF tp_t.
APPEND VALUE #( matnr = 'A' cont = 1 ) TO t_teste.
APPEND VALUE #( matnr = 'A' cont = 1 ) TO t_teste.
APPEND VALUE #( matnr = 'B' tipo = 'X' cont = 1 ) TO t_teste.
APPEND VALUE #( matnr = 'B' cont = 2 ) TO t_teste.
APPEND VALUE #( matnr = 'B' cont = 3 ) TO t_teste.
APPEND VALUE #( matnr = 'D' cont = 2 ) TO t_teste.
APPEND VALUE #( matnr = 'C' cont = 1 ) TO t_teste.
APPEND VALUE #( matnr = 'C' cont = 1 ) TO t_teste.
APPEND VALUE #( matnr = 'C' tipo = 'W' cont = 1 ) TO t_teste.
APPEND VALUE #( matnr = 'C' tipo = 'W' cont = 1 ) TO t_teste.
APPEND VALUE #( matnr = 'A' cont = 1 ) TO t_teste.
APPEND VALUE #( matnr = 'B' tipo = 'X' cont = 1 ) TO t_teste.
APPEND VALUE #( matnr = 'B' cont = 2 ) TO t_teste.
APPEND VALUE #( matnr = 'B' cont = 3 ) TO t_teste.
APPEND VALUE #( matnr = 'D' cont = 2 ) TO t_teste.
APPEND VALUE #( matnr = 'C' cont = 1 ) TO t_teste.
APPEND VALUE #( matnr = 'C' cont = 1 ) TO t_teste.
APPEND VALUE #( matnr = 'C' tipo = 'W' cont = 1 ) TO t_teste.
APPEND VALUE #( matnr = 'C' tipo = 'W' cont = 1 ) TO t_teste.
data(lt_mat) =
VALUE gkey(
FOR GROUPS material OF wa IN t_teste
GROUP BY ( matnr = wa-matnr
tipo = wa-tipo )
DESCENDING
LET cont_1 = REDUCE tp_t( init line type tp_t
for ls_c in group material
NEXT line-matnr = ls_c-matnr
LINE-TIPO = ls_c-tipo
line-cont = line-cont + ls_c-cont ) in ( cont_1 ) ).
BREAK-POINT.
VALUE gkey(
FOR GROUPS material OF wa IN t_teste
GROUP BY ( matnr = wa-matnr
tipo = wa-tipo )
DESCENDING
LET cont_1 = REDUCE tp_t( init line type tp_t
for ls_c in group material
NEXT line-matnr = ls_c-matnr
LINE-TIPO = ls_c-tipo
line-cont = line-cont + ls_c-cont ) in ( cont_1 ) ).
BREAK-POINT.
LOOP AT lt_mat INTO data(lsx).
WRITE: / lsx-matnr, lsx-tipo, lsx-cont.
ENDLOOP.
Nenhum comentário:
Postar um comentário