0

I'm able to display data using two standard tables but in that I have duplicate entries.

EX:

A     16.03.2017    168
B     16.03.2017    150
A     16.03.2017    208

Here, I want to display output like below:

A     16.03.2017     200[here I want to give my value]
B     16.03.2017     150

Could anyone please help me on this??

Suncatcher
  • 10,355
  • 10
  • 52
  • 90
Pavitra M
  • 1
  • 1
  • 1
  • 3
    What does "here I want to give my value" mean? Which value from A should be deleted? How do you get 200 from 208 and 168? –  Mar 21 '17 at 06:26
  • Don't get the idea too. If you wanna own values, just create your own itab and that's it. – Suncatcher Mar 21 '17 at 10:31

2 Answers2

0

The question is unclear on what you want to achieve. Anyway the below piece should work. Here you need to define two variable row and last_row.

SORT tab.
LOOP AT tab INTO row.
  IF sy-tabix = 1.
    last_row = row.
  ELSE.
    IF  last_row-col1 = row-col1 AND last_row-col2 = row-col2. "duplicate
      last_row-value = 'My Value'.
    ELSE. "New values
      WRITE:/ last_row-col1, last_row-col2, last_row-value.
      last_row = row.
    ENDIF.
  ENDIF.
ENDLOOP.
IF sy-subrc EQ 0.
  WRITE:/ last_row-col1, last_row-col2, last_row-value.
ENDIF.
jhamu
  • 232
  • 3
  • 14
  • 2
    Could you please explain what your code is intended to do? –  Mar 22 '17 at 10:42
  • @lausek, the code sorts the table. and whenever the column values changes it prints the last row saved. In case it find duplicate, it updates the value with your own value... If you take the input provided and output requested in the question, this code will work.. Anyway I am sure if question provide more details, better solutions are possible. – jhamu Mar 26 '17 at 09:06
0

I don't quite get your question. But I guess you might need the following code for reference.

Let's give some names for the columns, and give a name to this internal table: lt_tab

C1    C2            C3
A     16.03.2017    168
B     16.03.2017    150
A     16.03.2017    208

Try the following causes:

SORT lt_tab BY C1 C2.
DELETE ADJACENT DUPLICATES FROM lt_tab COMPARING C1 C2.
LOOP AT lt_tab ASSIGNING FIELD-SYMBOL(<fs_tab>).
  IF <fs_tab>-C1 EQ 'A'.
    <fs_tab>-C3 = 200.
  ENDIF.
ENDLOOP.