Skip to Content
-3

How can i sum up or collect the data on the same field?

Jun 22, 2017 at 12:22 AM

136

avatar image
Former Member

Hi ABAP users i would like to ask if what process i can make to COLLECT the data on the same field? all i want to do is to sum up or collect the data in dmbtr that belongs to same date, (date field monat) (werks to plant codes)

it_zfi_vbrp_bseg_1-num3 = it_zfi_vbrp_bseg_1-werks.
it_zfi_vbrp_bseg_1-num2 = it_zfi_vbrp_bseg_1-dmbtr.
COLLECT it_zfi_vbrp_bseg_1.

DELETE ADJACENT DUPLICATES FROM it_zfi_vbrp_bseg_1 COMPARING ALL FIELDS.
Sort it_zfi_vbrp_bseg_1 by werks.

LOOP AT it_zfi_vbrp_bseg_1 into wa_zfi_vbrp_bseg_1 WHERE monat = '01'.
IF wa_zfi_vbrp_bseg_1-werks EQ '4030'.
WRITE:/, AT pos wa_zfi_vbrp_bseg_1-dmbtr.

ENDIF. 
ENDLOOP.

Any configuration in my codes guys?

10 |10000 characters needed characters left characters exceeded
* Please Login or Register to Answer, Follow or Comment.

1 Answer

Mangesh Parihar Jun 22, 2017 at 05:27 AM
-1

Hi,

For Collect to work properly, you have to make sure if following things are fine.

  1. Collect works on only numeric fields.
  2. When you use collect, the position of column in the table matters. Collect will sum up the column based on previous all columns of the same table.
  3. Table should be sorted on the basis of the previous columns in the table.
Example :
TYPES: BEGIN OF  st_vbbe ,
                  matnr TYPE vbbe-matnr,
                  werks TYPE vbbe-werks,
                  omeng TYPE vbbe-omeng,
            END OF st_vbbe.
DATA : it_vbbe TYPE TABLE OF st_vbbe WITH HEADER LINE,
          wa_vbbe TYPE st_vbbe,
          it_vbbe_f TYPE TABLE OF st_vbbe,
          wa_vbbe_f TYPE st_vbbe.

START-OF-SELECTION.
  SELECT matnr werks omeng
               FROM vbbe INTO TABLE it_vbbe UP TO 500 ROWS.
  BREAK-POINT.
  LOOP AT it_vbbe INTO wa_vbbe.
    COLLECT wa_vbbe INTO it_vbbe_f.
  ENDLOOP.
  BREAK-POINT.
Show 1 Share
10 |10000 characters needed characters left characters exceeded
  1. You shouldn't be internal tables with header line anymore
  2. COLLECT shouldn't be used for STANDARD TABLEs (cf. https://help.sap.com/doc/abapdocu_751_index_htm/7.51/en-US/index.htm?file=abencollect_guidl.htm)
1