Application Development and Automation Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

report

Former Member
0 Likes
782

hi,

Internal table : key fields are week , werks , group.

WEEK WERKS GROUP USAGE

200709|P10 |AW | 10.000 |

200709|P10 |AW | 10.000 |

200709|P10 |FL | 100.000 |

200709|P10 |TR | 10.000 |

200709|P10 |TR | 10.000 |

200709|P20 |TR | 10.000 |

-


Required

WEEK WERKS GROUP USAGE

200709|P10 |AW | 20.000 |

200709|P10 |FL | 100.000 |

200709|P10 |TR | 20.000 |

200709|P20 |TR | 10.000 |

Thanks,

vind

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
757

use collect statement

loop at itab.

collect itab to itab_new.

endloop.

8 REPLIES 8
Read only

Former Member
0 Likes
757

Hi..

Sort table by week , werks , group.

then use collect stmt..

delete adjacent duplicate by comparing week , werks , group.

this will fetch u desired result...

Hi..

do like this..

data: gtab like itab. ( where ur itab is of your 4 fields).

loop at itab into wa.

collect wa into gtab.

endloop.

Message was edited by:

Rammohan Nagam

Message was edited by:

Rammohan Nagam

Read only

Former Member
0 Likes
758

use collect statement

loop at itab.

collect itab to itab_new.

endloop.

Read only

Former Member
0 Likes
757

use COLLECT statement.

reward the helpful replies.

Regards,

Raman

Read only

Former Member
0 Likes
757

vind,

u can use <b>collect stmt </b>as well as the control event <b>at new</b> or <b>on change of</b> for ur requirement.

Regards...

Arun.

Reward points if useful.

Read only

Former Member
0 Likes
757

Hi,

You need to use the COLLECT statment

COLLECT <wa> INTO <itab>.

<itab> must have a flat line type, and all of the fields that are not part of the table key must have a numeric type (F, I, or P). You specify the line that you want to add in a work area that is compatible with the line type.

When the line is inserted, the system checks whether there is already a table entry that matches the key. If there is no corresponding entry already in the table, the COLLECT statement has the same effect as inserting the new line. If an entry with the same key already exists, the COLLECT statement does not append a new line, but adds the contents of the numeric fields in the work area to the contents of the numeric fields in the existing entry.

You should only use the COLLECT statement if you want to create summarized tables. If you use other statements to insert table entries, you may end up with duplicate entries.

<b>Example Program</b>

DATA: BEGIN OF LINE,
        COL1(3) TYPE C,
        COL2(2) TYPE N,
        COL3    TYPE I,
      END OF LINE.

DATA ITAB LIKE SORTED TABLE OF LINE 
          WITH NON-UNIQUE KEY COL1 COL2.

LINE-COL1 = 'abc'. LINE-COL2 = '12'. LINE-COL3 = 3.
COLLECT LINE INTO ITAB.
WRITE / SY-TABIX.

LINE-COL1 = 'def'. LINE-COL2 = '34'. LINE-COL3 = 5.
COLLECT LINE INTO ITAB.
WRITE / SY-TABIX.

LINE-COL1 = 'abc'. LINE-COL2 = '12'. LINE-COL3 = 7.
COLLECT LINE INTO ITAB.
WRITE / SY-TABIX.

LOOP AT ITAB INTO LINE.
  WRITE: / LINE-COL1, LINE-COL2, LINE-COL3.
ENDLOOP.

Regards

Sudheer

Read only

former_member194669
Active Contributor
0 Likes
757

Hi,


sort itab by week werks group.

loop at itab.
  at end of group.
    move 'Y' to v_flg.
  endat.
  at end of werks.
    move 'Y' to v_flg.
  endat.
  at end of week.
    move 'Y' to v_flg.
  endat. 
  v_usage = v_usage + itab-usage.
  if v_flg eq 'Y'.
    move-corresponding itab to itab1.
    move v_usage to itab1-usage.
    append itab1.
    clear: v_usage, v_flg.
  endif. 
endloop.

After this loop itab1 contains the results.

aRs

Read only

Former Member
0 Likes
757

Hi..

do like this..

data: gtab like itab. ( where ur itab is of your 4 fields).

loop at itab into wa.

collect wa into gtab.

endloop.

Read only

Former Member
0 Likes
757

Hi,

Please try this.


REPORT ZTEST.

DATA: BEGIN OF ITAB1 OCCURS 0,
        WEEK(6)  TYPE C,
        WERKS(4) TYPE C,
        GROUP(2) TYPE C,
        USAGE    TYPE P DECIMALS 3,
      END OF ITAB1.

DATA: BEGIN OF ITAB2 OCCURS 0,
        KEY(10)  TYPE C,
        WEEK(6)  TYPE C,
        WERKS(4) TYPE C,
        GROUP(2) TYPE C,
        USAGE    TYPE P DECIMALS 3,
      END OF ITAB2.

ITAB1-WEEK = '200709'.
ITAB1-WERKS = 'P10'.
ITAB1-GROUP = 'AW'.
ITAB1-USAGE = '10.000'.
APPEND ITAB1.

ITAB1-WEEK = '200709'.
ITAB1-WERKS = 'P10'.
ITAB1-GROUP = 'AW'.
ITAB1-USAGE = '10.000'.
APPEND ITAB1.

ITAB1-WEEK = '200709'.
ITAB1-WERKS = 'P10'.
ITAB1-GROUP = 'FL'.
ITAB1-USAGE = '100.000'.
APPEND ITAB1.

ITAB1-WEEK = '200709'.
ITAB1-WERKS = 'P10'.
ITAB1-GROUP = 'TR'.
ITAB1-USAGE = '10.000'.
APPEND ITAB1.

ITAB1-WEEK = '200709'.
ITAB1-WERKS = 'P10'.
ITAB1-GROUP = 'TR'.
ITAB1-USAGE = '10.000'.
APPEND ITAB1.

ITAB1-WEEK = '200709'.
ITAB1-WERKS = 'P20'.
ITAB1-GROUP = 'TR'.
ITAB1-USAGE = '10.000'.
APPEND ITAB1.


LOOP AT ITAB1.
  ITAB2-KEY(6)   = ITAB1-WEEK.
  ITAB2-KEY+6(4) = ITAB1-WERKS.
  MOVE-CORRESPONDING ITAB1 TO ITAB2.
  COLLECT ITAB2.
ENDLOOP.

SORT ITAB2.
LOOP AT ITAB2.
   WRITE: / ITAB2-WEEK, ITAB2-WERKS, ITAB2-GROUP, ITAB2-USAGE.
ENDLOOP.

Regards,

Ferry Lianto