Question

How do i suppress duplicate entries in both classical (write) and ALV report? I was given a task to write a simple report with this criteria. I tried to google but could not succeed with any of their solutions and need help. Below is the expected result.

original report:

--------------------------------------
|Sales Org | Dist.Channel | Division | 
--------------------------------------
|1000      |10            |00        |
|1000      |10            |00        |
|1000      |10            |00        |
|1020      |22            |00        |
|1020      |22            |00        |
--------------------------------------

expected output:

--------------------------------------
|Sales Org | Dist.Channel | Division |
--------------------------------------
|1000      |10            |00        |
|          |              |          |
|          |              |          |
|1020      |22            |00        |
|          |              |          |
--------------------------------------

need help.Thank you.

Was it helpful?

Solution

Assuming you are using an internal table to store data that is going to be displayed, you can use DELETE ADJACENT DUPLICATE ENTRIES FROM itab.

For ALV grid you have to use an internal table. For WRITE statement, even if you read directly from a database table you can buffer the entries in an internal table, use the above statement to delete duplicates and then display results from internal table.

Regards, Sergiu

OTHER TIPS

Well, if the internal table with the data is really sorted the way you put in your example. Then you can remember the last line that was output and compare the next one to the previous one an write an empty row based on this condition. If the previous line is not equal then you print the new row with new data and store the new one in the previous row variable. To me it does not seem like a lot of the development effort.

This is however based on the assumption that the table is somehow sorted.

ALV does provide an option for this, it's enabled per default - but you have to sort by the columns in question. You can turn it off though.

If you're really into WRITEing your own lists (why anyone would do that today is beyond my understanding), you'll have to do this for yourself.

This would depend where the data that you are displaying is coming from.

If it is in an internal table, then sorting and DELETE ADJACENT DUPLICATESis the way to go (s+as sepo mentioned).

However, if you are reading the data from the database with a SQL Select, it would be better to let the database do the work and SELECT DISTINCT or adjust your statement accordingly. This will offset some work to the database server (who may also have an index to make this quicker) and minimizes network traffic.

Even though all other answers suggest a decent/better approach, I thought I'd just add the code which answers your question exactly. It does what @Jagger is suggesting.

DATA wa_tvta_prev TYPE tvta.
FIELD-SYMBOLS <fs_tvta> TYPE tvta.
LOOP AT ta_tvta ASSIGNING <fs_tvta>.
  IF <fs_tvta> <> wa_tvta_prev.
    PERFORM write_line USING <fs_tvta>.
  ELSE.
    PERFORM write_empty_line.
  ENDIF.
  wa_tvta_prev = <fs_tvta>.
ENDLOOP.

This is assuming you have a sorted internal table ta_tvta containing the data from your example. The subroutines write_line and write_empty_line contain the required WRITE syntax; I'm assuming you already got that part figured out.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top