Skip to Content
avatar image
Former Member

Merge Column Cells alv - using cl_gui_alv_grid

Hi

I want to merge below highlighted column and need to include a text in the merged column. Kindly suggest.

Thanks in advance.

Regards,

Abirami

merge-column.png (10.7 kB)
Add comment
10|10000 characters needed characters exceeded

  • Get RSS Feed

7 Answers

  • Best Answer
    May 09, 2017 at 06:38 AM

    To span one cell over 2 rows and 2 columns, do as follows with the code of @enno.wulff (http://www.tricktresor.de/blog/zellen-verbinden/) :

    " span over 2 rows (outputlen must be the number of rows)
    wa_col_merge-col_id = 1.
    wa_col_merge-outputlen = 2.
    APPEND wa_col_merge TO it_col_merge.
    CALL METHOD g_alv_grid->z_set_merge_vert EXPORTING row = 1
    CHANGING tab_col_merge = it_col_merge.
    
    " span over 2 columns (outputlen must be the number of the last column to merge)
    wa_col_merge-col_id = 1.
    wa_col_merge-outputlen = 2.
    APPEND wa_col_merge TO it_col_merge.
    CALL METHOD g_alv_grid->z_set_merge_vert EXPORTING row = 1
    CHANGING tab_col_merge = it_col_merge.

    Add comment
    10|10000 characters needed characters exceeded

  • avatar image
    Former Member
    May 08, 2017 at 11:35 AM
    -1

    Hi Sandra,

    I copied the same class and also the demonstrated prog:

    demonstrated prog: http://www.tricktresor.de/wp-content/downloads/ALV/zz_alv_merge_cells.abap.txt

    But I am getting below output. I am unable to find the column merged.

    Could you please suggest on this, as the logic will work perfectly for the column merge or not?

    Thanks in Advance!

    Regards,

    Add comment
    10|10000 characters needed characters exceeded

    • Former Member

      Hi Abirami,

      Can you please share class methods-> attributes. I tried to create class but unable to find the attributes of its methods.

      Thanks

  • May 08, 2017 at 06:17 AM

    Hi Abirami,

    as far as I know it is not possible to merge column cells in ALV Grid. If you sort the table for example, then same cells are automatically merged if merging is allowed, But you can't control the mergering on your own.

    Regards

    Add comment
    10|10000 characters needed characters exceeded

  • May 08, 2017 at 07:50 AM

    Well done, Abirami. It's the first time I see that it's possible to do it (although not supported by SAP i.e. no guarantee to be maintained). Could you tell us where is your issue with the solution provided by Enno Wulff at http://www.tricktresor.de/blog/zellen-verbinden/ ?

    Add comment
    10|10000 characters needed characters exceeded

    • I guess you changed the demo, because what I tried was beautiful. In your example, I see 3 merged cells (TRICKTRESOR, HC in column "P", and HC in column "K").

      Isn't it what you're trying to achieve? Please explain carefully as I don't understand what your issue is.

  • avatar image
    Former Member
    May 09, 2017 at 05:16 AM

    Hi Sandra,

    Currently the 3 merged cells are merged by only rows.. I want the column also to be merged.

    ex: as highlighted below : along with TRICKTRESOR the corresponding column has to be merged.

    In your demo is the column getting merged? it will be good if you share me your output snap shot.. for my better understanding.

    I do no where im getting failed in archiving the column merge.. Kindly share me..

    Regards,

    Add comment
    10|10000 characters needed characters exceeded

  • avatar image
    Former Member
    May 09, 2017 at 08:20 AM

    Hi

    Thanks for in details..

    I just made a mistake while creating a class.. I am getting now the perfect output..

    Thanks for all the support.

    Regards,

    Add comment
    10|10000 characters needed characters exceeded

  • avatar image
    Former Member
    May 10, 2017 at 06:46 AM

    Hi Sandra,

    I am trying to merge the highlighted rows

    code used:

    But the 2nd colunm is getting affected.

    Kindly suggest on this to archeive, thanks

    Regards,

    Add comment
    10|10000 characters needed characters exceeded

    • I don't think it's related to only the code you show. Maybe you didn't clear the internal table it_col_merge, or you have an extra code you didn't show, or things like that.

      Your code should have no effect as you merge a cell to itself (with Y/Z_SET_MERGE_VERT, outputlen is the total number of rows to merge from a given cell, including this cell). You should use outputlen = 3 (and correct some other code for cell R3C2).