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: 

How to group values in a column in ALV Grid

Former Member
0 Kudos

Hi ,

i have got a report layout like below.

1 4

1 5

1 6

2 7

2 8

2 8

now i want to group the 1st column like below

1 4

5

6

2 7

8

8

How can i get this in ALV grid display.....pls help me out if any of u have got a sample code.

5 REPLIES 5

Former Member
0 Kudos

Hi,

Pass the Value for

IT_SORT: Sort criteria for first list display

mention the first field name. in the sort criteria

0 Kudos

Thanks a lot for quick replt but what value shld i need to pass to IT_SORT ? can you pls elaborate it or can u pls provide me the sample code

0 Kudos

Hi,

in the Exporting Parametr of REUSE_ALV_GRID_DISPLAY.

Do this




also declare type-pool in ur program


TYPE-POOLS: slis.



Field the details for Sort

  line_sortinfo TYPE slis_sortinfo_alv.

  CLEAR line_sortinfo.
  line_sortinfo-fieldname = 'QMART'.
  line_sortinfo-tabname = 'I_DATA'.
  line_sortinfo-spos = 1.            " First sort by this field.
  line_sortinfo-down = 'X'.          " Descending
  APPEND line_sortinfo TO i_sortcat.

  line_sortinfo-fieldname = 'WS_ROW'.
  line_sortinfo-tabname = 'I_DATA'.
  line_sortinfo-spos = 2.            " Second sort by this field.
  line_sortinfo-up = 'X'.            " Ascending
  APPEND line_sortinfo TO i_sortcat.


I_DATA : is the internal Table which holds the data

'QMART','WS_ROW' : are the fields of the internal table


Expoting
   it_fieldcat                       = i_fieldcat
*   IT_EXCLUDING                      =
*   IT_SPECIAL_GROUPS                 =
   IT_SORT                           = i_sortcat

  
  

Message was edited by: Manoj Gupta

Former Member
0 Kudos

Hi,

You may find your solution in below thread:

<b>Reward if helpful</b>

Rgds,

Shakuntala

Former Member
0 Kudos

Hi,

Here is a sample program which shows how to do sorting.

report zsudheer
       no standard page heading.
 
type-pools slis.
 
data: fieldcat type slis_t_fieldcat_alv.
<b>data: sort     type slis_t_sortinfo_alv.</b>
 
data: begin of imara occurs 0,
      matnr type mara-matnr,
      matkl type mara-matkl,
      labor type mara-labor,
      brgew type mara-brgew,
      maktx type makt-maktx,
      end of imara.
 
* Selection Screen
selection-screen begin of block b1 with frame title text-001 .
select-options: s_matnr for imara-matnr .
selection-screen end of block b1.
 
start-of-selection.
 
  perform get_data.
  perform write_report.
 
 
************************************************************************
*  Get_Data
************************************************************************
form get_data.
 
  select  mara~matnr mara~matkl mara~labor mara~brgew makt~maktx
            into corresponding fields of table imara
              from mara
               inner join makt
                 on mara~matnr = makt~matnr
                    where mara~matnr in s_matnr
                      and makt~spras = sy-langu.
 
endform.
 
************************************************************************
*  WRITE_REPORT
************************************************************************
form write_report.
 
  perform build_field_catalog.
 
  <b>perform build_sort.</b>
 
* CALL ABAP LIST VIEWER (ALV)
  call function 'REUSE_ALV_GRID_DISPLAY'
       exporting
            it_sort     = sort
            it_fieldcat = fieldcat
       tables
            t_outtab    = imara.
 
endform.
 
************************************************************************
* BUILD_FIELD_CATALOG
************************************************************************
form build_field_catalog.
 
  data: fc_tmp type slis_t_fieldcat_alv with header line.
  clear: fieldcat. refresh: fieldcat.
 
  clear: fc_tmp.
  fc_tmp-reptext_ddic    = 'Material Number'.
  fc_tmp-fieldname  = 'MATNR'.
  fc_tmp-tabname   = 'IMARA'.
  fc_tmp-outputlen  = '18'.
  fc_tmp-col_pos    = 2.
  append fc_tmp to fieldcat.
 
  clear: fc_tmp.
  fc_tmp-reptext_ddic    = 'Material Group'.
  fc_tmp-fieldname  = 'MATKL'.
  fc_tmp-tabname   = 'IMARA'.
  fc_tmp-outputlen  = '12'.
  fc_tmp-col_pos    = 3.
  append fc_tmp to fieldcat.
 
  clear: fc_tmp.
  fc_tmp-reptext_ddic    = 'Sort Group'.
  fc_tmp-fieldname  = 'LABOR'.
  fc_tmp-tabname   = 'IMARA'.
  fc_tmp-outputlen  = '12'.
  fc_tmp-col_pos    = 3.
  append fc_tmp to fieldcat.
 
  clear: fc_tmp.
  fc_tmp-reptext_ddic    = 'Gross Weight'.
  fc_tmp-fieldname  = 'BRGEW'.
  fc_tmp-tabname   = 'IMARA'.
  fc_tmp-outputlen  = '12'.
  fc_tmp-do_sum     = 'X'.
  fc_tmp-col_pos    = 4.
  append fc_tmp to fieldcat.
 
  clear: fc_tmp.
  fc_tmp-reptext_ddic    = 'Material Description'.
  fc_tmp-fieldname  = 'MAKTX'.
  fc_tmp-tabname   = 'IMARA'.
  fc_tmp-outputlen  = '40'.
  fc_tmp-col_pos    = 5.
  append fc_tmp to fieldcat.
 
endform.
 
************************************************************************
*       FORM build_sort                                                *
************************************************************************
form build_sort.
 
  data: tmp_sort type line of slis_t_sortinfo_alv.
 
  clear sort. refresh sort.
 
<b>  clear tmp_sort.
  tmp_sort-fieldname = 'MATKL'.
  tmp_sort-tabname   = 'IALV'.
  tmp_sort-up        = 'X'.
  append tmp_sort to sort.
 
  clear tmp_sort.
  tmp_sort-fieldname = 'LABOR'.
  tmp_sort-tabname   = 'IALV'.
  tmp_sort-up        = 'X'.
  tmp_sort-subtot    = 'X'.
  append tmp_sort to sort.</b>
 
endform.

Regards,

Sudheer