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: 

Grouping in ALV

Former Member
0 Kudos

Hi,

I have a requirement where i am displaying four fields in an ALV grid. The fields are VKORG, KUNNR, VBELN and NETWR.

The sorting is being done on the fields VKORG KUNNR and VBELN. Therefore i have a display where there are three breaks.

My requirement is that the node for VKORG should be expanded mode while for the other two it should be in collapsed mode. This should be the default feature.

Can anyone let me know how this could be done in ALV (using OOPS would be fine too).

Thanks,

Writtick

3 REPLIES 3

Former Member
0 Kudos

Hi,

In SE38 give the program name as BCAL* and do a f4 on it you will get all the ALV related sample programs then check the best fit to ur requirment and use it.

Regards,

Lakshmikanth.T.V

0 Kudos

You can do this with the SORT parameters.

Regards,

Rich Heilman

RichHeilman
Developer Advocate
Developer Advocate
0 Kudos

Check this sample program.



report zrich_0004
       no standard page heading.

type-pools slis.

data: fieldcat type slis_t_fieldcat_alv.
data: sort     type slis_t_sortinfo_alv.

data: begin of ivbap occurs 0,
      vbeln type vbap-vbeln,
      kunnr type vbak-kunnr,
      vkorg type vbak-vkorg,
      netwr type vbap-netwr,
      end of ivbap.


* Selection Screen

start-of-selection.

  perform get_data.
  perform write_report.


************************************************************************
*  Get_Data
************************************************************************
form get_data.

  select vbak~vbeln vbak~kunnr vbak~vkorg vbap~netpr
              into table ivbap
                      from vbak
                         inner join vbap
                            on vbak~vbeln = vbap~vbeln
                                  up to 100 rows.

endform.

************************************************************************
*  WRITE_REPORT
************************************************************************
form write_report.

  data: layout type slis_layout_alv.

  layout-totals_only = 'X'.

  perform build_field_catalog.

  perform build_sort.

* CALL ABAP LIST VIEWER (ALV)
  call function 'REUSE_ALV_GRID_DISPLAY'
       exporting
            it_sort     = sort
            is_layout   = layout
            it_fieldcat = fieldcat
       tables
            t_outtab    = ivbap.

endform.

************************************************************************
* BUILD_FIELD_CATALOG
************************************************************************
form build_field_catalog.

  data: fc_tmp type slis_fieldcat_alv .
  clear fieldcat. refresh fieldcat.

  clear fc_tmp.
  fc_tmp-reptext_ddic    = 'Sales Org'.
  fc_tmp-fieldname  = 'VKORG'.
  fc_tmp-tabname   = 'IVBAP'.
  fc_tmp-outputlen  = '4'.
  append fc_tmp to fieldcat.

  clear fc_tmp.
  fc_tmp-reptext_ddic    = 'Customer'.
  fc_tmp-fieldname  = 'KUNNR'.
  fc_tmp-tabname   = 'IVBAP'.
  fc_tmp-outputlen  = '10'.
  append fc_tmp to fieldcat.

  clear fc_tmp.
  fc_tmp-reptext_ddic    = 'SD DOC'.
  fc_tmp-fieldname  = 'VBELN'.
  fc_tmp-tabname   = 'IVBAP'.
  fc_tmp-outputlen  = '10'.
  append fc_tmp to fieldcat.

  clear fc_tmp.
  fc_tmp-reptext_ddic    = 'Net'.
  fc_tmp-fieldname  = 'NETWR'.
  fc_tmp-tabname   = 'IVBAP'.
  fc_tmp-outputlen  = '15'.
  fc_tmp-do_sum  = 'X'.
  fc_tmp-datatype = 'QUAN'.
  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.

  clear tmp_sort.
  tmp_sort-fieldname = 'VKORG'.
  tmp_sort-tabname   = 'IALV'.
  tmp_sort-up        = 'X'.
  tmp_sort-subtot    = 'X'.
  tmp_sort-group     = 'X'.
*  tmp_sort-expa      = 'X'.
  append tmp_sort to sort.

  clear tmp_sort.
  tmp_sort-fieldname = 'KUNNR'.
  tmp_sort-tabname   = 'IALV'.
  tmp_sort-up        = 'X'.
  tmp_sort-subtot    = 'X'.
  tmp_sort-group     = 'X'.
  tmp_sort-expa      = 'X'.
  append tmp_sort to sort.

  clear tmp_sort.
  tmp_sort-fieldname = 'VBELN'.
  tmp_sort-tabname   = 'IALV'.
  tmp_sort-up        = 'X'.
  tmp_sort-subtot    = 'X'.
  tmp_sort-group     = 'X'.
  tmp_sort-expa      = 'X'.
  append tmp_sort to sort.

endform.

Regards,

Rich Heilman