Skip to Content

ALV grid how to merge duplicate rows when i hide a column

Hi experts, I'm looking for an answer to this question for three days, i haven't found any post that can help me... Then i created my post. Thank you for your help.

First : I have this display using an ALV grid:


First picture :

Article | Prod.bio | TyAr | Fr.geh. | Allergene | Hier.pdt. | L/B
100     |          | ZPFD |         |           |  86       |
600     |          | ZPFD |         |           |  86       |
1000    |          | ZPFD |         |           |  86       |
1300    |          | ZPFD |         |           |  86       |
3000    |          | ZROH |         |           |  8790     |
3005    |          | ZROH |         |           |  8790     | 004
3010    |          | ZROH |         |           |  8790     | 005
3013    |          | ZROH |         |           |  8790     |    

We can see that the values are not duplicated by the primary key "article ".

When I hide the primary key using 'right click > hide' or the specific ALV button, I have this display:

Second picture :

Prod.bio | TyAr | Fr.geh | Allergene | Hier.pdt. | L/B
         | ZPFD |        |           |  86       |
         | ZPFD |        |           |  86       |
         | ZPFD |        |           |  86       |
         | ZPFD |        |           |  86       |
         | ZROH |        |           |  8790     |
         | ZROH |        |           |  8790     | 004
         | ZROH |        |           |  8790     | 005
         | ZROH |        |           |  8790     | 

There is no need to keep all these values after have hide "article " So how do I write my code to dynamically merge the lines. I don't want to make two check boxes for my different screens.

I post the attended result :


Third picture :

Prod.bio | TyAr | Fr.geh | Allergene | Hier.pdt. | L/B
         | ZPFD |        |           |  86       | 
         | ZROH |        |           |  8790     |
         | ZROH |        |           |  8790     | 004
         | ZROH |        |           |  8790     | 005

And my code, an alv grid display:

REPORT ZTESTALEX01 NO STANDARD PAGE HEADING.
**********************************************************************
*TEST ALV DYNAMIQUE
**********************************************************************

TABLES: MARA.TYPE-pools: slis.

"ALV Declarations

DATA: 
 it_fieldcat TYPE slis_t_fieldcat_alv WITHHEADERLINE,
 wa_fieldcat TYPE slis_t_fieldcat_alv,
 l_layout TYPE slis_layout_alv,
 it_sort TYPE slis_t_sortinfo_alv WITHHEADERLINE,
 wa_sort TYPE slis_t_sortinfo_alv.

DATA: BEGIN OF TB_MARA OCCURS 0,
 MATNR LIKE MARA-MATNR,"Article
 ZZBIOJFA LIKE MARA-ZZBIOJFA,"Article bio
 MTART LIKE MARA-MTART,"
 ZZFRUIT LIKE MARA-ZZFRUIT,"
 ZZALLERGENE LIKE MARA-ZZALLERGENE,"
 PRDHA LIKE MARA-PRDHA,"
 LABOR LIKE MARA-LABOR,"lab./bureau d'étude
END OF TB_MARA.

DATA: BEGIN OF TB_COPY OCCURS 0,
 MATNR LIKE MARA-MATNR,"Article
 ZZBIOJFA LIKE MARA-ZZBIOJFA,"Article bio
 MTART LIKE MARA-MTART,"
 ZZFRUIT LIKE MARA-ZZFRUIT,"
 ZZALLERGENE LIKE MARA-ZZALLERGENE,"
 PRDHA LIKE MARA-PRDHA,"
 LABOR LIKE MARA-LABOR,"lab./bureau d'étude
END OF TB_COPY.

START-OF-SELECTION.
SELECT*FROM MARA into CORRESPONDING FIELDS OF TABLE TB_MARA.
it_fieldcat-fieldname ='MATNR'.
it_fieldcat-tabname ='TB_MARA'.
it_fieldcat-ref_tabname ='MARA'.APPEND it_fieldcat TO wa_fieldcat.clear it_fieldcat.
it_fieldcat-fieldname ='ZZBIOJFA'.
it_fieldcat-tabname ='TB_MARA'.
it_fieldcat-ref_tabname ='MARA'.APPEND it_fieldcat TO wa_fieldcat.clear it_fieldcat.
it_fieldcat-fieldname ='MTART'.
it_fieldcat-tabname ='TB_MARA'.
it_fieldcat-ref_tabname ='MARA'.APPEND it_fieldcat TO wa_fieldcat.clear it_fieldcat.
it_fieldcat-fieldname ='ZZFRUIT'.
it_fieldcat-tabname ='TB_MARA'.
it_fieldcat-ref_tabname ='MARA'.APPEND it_fieldcat TO wa_fieldcat.clear it_fieldcat.
it_fieldcat-fieldname ='ZZALLERGENE'.
it_fieldcat-tabname ='TB_MARA'.
it_fieldcat-ref_tabname ='MARA'.APPEND it_fieldcat TO wa_fieldcat.clear it_fieldcat.
it_fieldcat-fieldname ='PRDHA'.
it_fieldcat-tabname ='TB_MARA'.
it_fieldcat-ref_tabname ='MARA'.APPEND it_fieldcat TO wa_fieldcat.clear it_fieldcat.
it_fieldcat-fieldname ='LABOR'.
it_fieldcat-tabname ='TB_MARA'.
it_fieldcat-ref_tabname ='MARA'.APPEND it_fieldcat TO wa_fieldcat.clear it_fieldcat.
l_layout-window_titlebar ='Table MARA'.CLEAR it_sort.
 it_sort-FIELDNAME ='MATNR'.
 it_sort-UP ='X'.APPEND it_sort TO wa_sort.CLEAR it_sort.

DELETEADJACENT DUPLICATES FROM TB_MARA COMPARING ALL FIELDS.
CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
EXPORTING
 i_callback_program =sy-repid
 is_layout = l_layout
 it_fieldcat = wa_fieldcat[]
 it_sort = wa_sort[]
 i_callback_top_of_page ='TOP'
 I_HTML_HEIGHT_TOP =1
TABLES
 t_outtab = TB_MARA
EXCEPTIONS
 program_error =1
 others=2.
IF sy-subrc <> 0.
ENDIF.
***------------------------------------------------------------------*
*** Top-of-page ***
***------------------------------------------------------------------*
FORM TOP.
CALL FUNCTION'Z_EGF_TOP_OF_PAGE'
EXPORTING
 P_BOTTOM_LINE =''."Pour enlever la ligne vide de l'en-tete dans l'apercu avant impression
ENDFORM.

Thanks for yours answers.

Add comment
10|10000 characters needed characters exceeded

  • Get RSS Feed

3 Answers

  • Best Answer
    Jan 02 at 12:39 PM

    You could handle event after_refresh (convert first your old fashioned FM report to OO) in the handling method, read the current field catalog (get_frontend_fieldcatalog) and if and only if required, update the displayed internal table (from a saved internal table with data read from database or reload from database, don't forget that user can display again a previously hidden field) and execute refresh_table_display.

    Add comment
    10|10000 characters needed characters exceeded

  • Jan 02 at 09:42 AM

    ALV does not have the feature to merge identical lines, nor lines with the same visible content.

    So, condense the lines of the internal table before displaying the ALV (SORT ... BY ... + DELETE ADJACENT DUPLICATES ... COMPARING ... both followed by the list of fields you want i.e. all fields except "article").

    Add comment
    10|10000 characters needed characters exceeded

    • Jelena Perfiljeva Alexandre HOLZHAMMER

      I'm curious - how do you expect ALV to figure out what is a duplicate and what isn't? In this particular case you happened to have empty values. But what if they were not empty? Let's say we have this data:

      ZPFD 5
      ZPFD 5
      ZROH 10

      If "5" here is some kind of identifier then a human would look at this and say: hm, I don't really need to see 3 rows here as the first two are clearly duplicates. But what is "5" is quantity or net value and the first two lines belong to two different documents (with the document # hidden)? Then it's not a duplicate at all! How do you expect ALV to know the difference?

  • avatar image
    Former Member
    Jan 02 at 10:44 PM

    It is not 100%, what you want (you get a subtotals line for free), but best what you can do with the sum function in ALV.


    Add comment
    10|10000 characters needed characters exceeded