Application Development 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: 

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

1 ACCEPTED SOLUTION

Sandra_Rossi
Active Contributor

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.

29 REPLIES 29

SaschaW
Participant
0 Kudos

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

0 Kudos

Hi Sascha,

I could find a answer in the below link.. but it is not clear. Could you please check the below link and let me know your suggestion.

http://www.tricktresor.de/blog/zellen-verbinden/

Regards,

Yes this seems to be interesting, but it also says that there is no possibillity in standard ALV Grid to do that. But in this example they manipulate the ALV Grid class and enhance the ALV Grid by a subclass and implement the functionality in the subclass itself so that you can use it in your program.

Maybe you can try it with the example coding. But it also says that there are limitations in your ALV if you implement this functionality.

0 Kudos

It also seems to me that there is a lot of code missing from this as well.

Rich

I just tried it, there is no missing code. You have to double click every method to get the whole code, + the demo program (there's just one syntax error "ZCL_GUI_ALV_GRID_MERGE not found", replace it with ZCL_GUI_ALV_GRID)

0 Kudos

Ok, thanks Sandra

Sandra_Rossi
Active Contributor
0 Kudos

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/ ?

0 Kudos

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?

Thanks in Advance!

Regards,

0 Kudos

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.

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,

0 Kudos

Hi Abirami,

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

Thanks

0 Kudos

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,

0 Kudos

Hi Abhi..

Can you explain me how do we achieve merging of alv cells dynamically same as column P in the above pic..

0 Kudos

What is your issue with the solution provided by Enno Wulff at http://www.tricktresor.de/blog/zellen-verbinden/ ?

Sandra_Rossi
Active Contributor

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.

0 Kudos

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,

0 Kudos

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,

0 Kudos

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).

Sandra_Rossi
Active Contributor
0 Kudos

Mahfud din This is the simplest code to merge the cells, but don't forget that's not a supported feature, and it's not used by SAP (although it's indirectly used by the texts of subtotals).

The original idea it taken from enno.wulff at https://tricktresor.de/blog/zellen-verbinden/

With the code below, here's the result obtained:

Code:

INCLUDE <cl_alv_control>.

CLASS lcl_alv_cell_merging DEFINITION.
   PUBLIC SECTION.
   INTERFACES IF_ALV_RM_GRID_FRIEND.
   METHODS constructor
        IMPORTING
          alv_grid TYPE REF TO cl_gui_alv_grid.
   METHODS add_command
        IMPORTING
          column   TYPE i
          row      TYPE i
          colspan  TYPE i DEFAULT 1
          rowspan  TYPE i DEFAULT 1
          align    TYPE lvc_style default ALV_STYLE_ALIGN_CENTER_CENTER
          color    TYPE lvc_style OPTIONAL
          bold     TYPE lvc_style OPTIONAL.
   METHODS execute_commands.
   DATA alv_grid TYPE REF TO cl_gui_alv_grid.
   DATA commands TYPE SORTED TABLE OF lvc_s_data WITH non-unique key col_pos row_pos.
ENDCLASS.

CLASS lcl_alv_cell_merging IMPLEMENTATION.
  METHOD CONSTRUCTOR.
    me->alv_grid = alv_grid.
  ENDMETHOD.
  METHOD add_command.
    data style type LVC_style.
    data command type lvc_s_data.
    command-col_pos = column.
    command-row_pos = row.
    command-mergehoriz = colspan - 1.
    command-mergevert  = rowspan - 1.
    style = color BIT-OR align BIT-OR bold.
    command-style = style.
    INSERT command INTO TABLE commands.
  ENDMETHOD.
  METHOD execute_commands.
    FIELD-SYMBOLS <ls_data> TYPE lvc_s_data.
    FIELD-SYMBOLS <command> TYPE lvc_s_data.
    LOOP AT alv_grid->mt_data ASSIGNING <ls_data>.
      READ TABLE commands WITH TABLE KEY col_pos = <ls_data>-col_pos row_pos = <ls_data>-row_pos ASSIGNING <command>.
      IF sy-subrc = 0.
        <ls_data>-mergehoriz = <command>-mergehoriz.
        <ls_data>-mergevert = <command>-mergevert.
        <ls_data>-style = <ls_data>-style + <command>-style.
      ENDIF.
    ENDLOOP.
  CALL METHOD alv_grid->set_data_table
     CHANGING
       data_table = alv_grid->mt_data[].
  ENDMETHOD.
ENDCLASS.

DATA go_alv TYPE REF TO cl_gui_alv_grid.
DATA go_alv_cell_merging TYPE REF TO lcl_alv_cell_merging.
DATA gt_sflight TYPE TABLE OF sflight.
PARAMETERS dummy.

AT SELECTION-SCREEN OUTPUT.
  IF go_alv IS INITIAL.
    CREATE OBJECT go_alv
        EXPORTING
          i_parent = cl_gui_container=>screen0.
    SELECT * FROM sflight INTO TABLE gt_sflight.
    go_alv->set_table_for_first_display(
        EXPORTING i_structure_name = 'SFLIGHT'
        CHANGING it_outtab = gt_sflight ).
    CREATE OBJECT go_alv_cell_merging EXPORTING alv_grid = go_alv.
    go_alv_cell_merging->add_command( 
        column = 1 row = 1 
        colspan = 4 rowspan = 4 
        COLOR = ALV_STYLE_COLOR_int_total ).
    go_alv_cell_merging->add_command( 
        column = 3 row = 7 
        colspan = 4 rowspan = 4 
        COLOR = ALV_STYLE_COLOR_total ).
    go_alv_cell_merging->execute_commands( ).
  ENDIF.
AT SELECTION-SCREEN ON EXIT-COMMAND.
  go_alv->free( ).
  free go_alv.

Hi Sandra,

Thanks for all the support..

regards,

Hi Sandra,

I tried code, it works but there is an issue.

alv_grid->mt_data table is limited 819 rows. So if our internal data table is big, ALV dont show other rows.

i tried to append to alv_grid->mt_data remaining rows manually. Then program gives short dump.

Maybe this is the reason why SAP keeps it private.

adem.bayraktar3 Thanks for the feedback. You're right. It's always dangerous to use unsupported features, that's a beautiful example 🙂

0 Kudos

Hi all,

I've been messing around with enno.wulff at https://tricktresor.de/blog/zellen-verbinden/ solution and I am getting some interesting results.

However I am using CL_SALV_TABLE... the challenge that I am facing is that MT_TAB (CL_GUi_ALV_GRID internal table) is not filled with all of my data and my SALV is not completely rendered:

The black boxes are some of my merged merged cells. The red box is what made investigate what might be happening. And when I debug, I've realized that the number of rows in MT_TAB were always the same and were not all that I needed..

Does anyone have a clue?

former_member472308
Discoverer
0 Kudos

Hi all,

I've been implemented this feature,But other problems arise,Please how to solve it ?

0 Kudos

Do you fix?

former_member850183
Discoverer
0 Kudos

I come across the same problem also,the mt_data limit with 819 lines,my data can not show fully,do you fix the problem,Mr ma?

or anyone have solution?

Thank you~~~

0 Kudos

Ploblem fixed,add follow code:

CALL METHOD PO_ALV_GRID->SET_READY_FOR_INPUT

EXPORTING

I_READY_FOR_INPUT = 1.

0 Kudos

This is my code, the mt_data problem is indeed solved,but there is a problem with the cell merge layout,I find that the screen is refreshed,do you fix the problem.

Regards

0 Kudos

I fix the problem.

Thank you very much!