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: 

Count lines in alvgrid.

Former Member
0 Kudos

What I want to do is to write the number om lines that the ALV grid displays.

How do i solv this? Is there a standarsfunction for this?

Best Regards Claes

1 ACCEPTED SOLUTION

RichHeilman
Developer Advocate
Developer Advocate
0 Kudos

Where do you want to put it. In the TOP? All you need to do is find the number of records in the internal table.

Data: NO_OF_LINES type i.

DESCRIBE TABLE ITAB LINES NO_OF_LINES.

Then you can use this sample program to learn how to use the ALV TOP.



report zrich_0001
       no standard page heading.

* Global ALV Data Declarations
type-pools slis.

data: begin of i_alv occurs 0,
      matnr type mara-matnr,
      end of i_alv.

* Miscellanous Data Declarations
data: fieldcat type slis_t_fieldcat_alv,
      events   type slis_t_event,
      list_top_of_page type slis_t_listheader,
      top_of_page  type slis_formname value 'TOP_OF_PAGE'.


start-of-selection.

  perform initialization.
  perform get_data.
  perform call_alv.

end-of-selection.

************************************************************************
*  Form  Initialization
************************************************************************
form initialization.

  clear i_alv.       refresh i_alv.

  perform eventtab_build using events[].

endform.

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

  select matnr into table i_alv
              from mara up to 100 rows.

endform.

************************************************************************
*  CALL_ALV
************************************************************************
form call_alv.

  data: variant type  disvariant.
  data: repid type sy-repid.
  data: layout type  SLIS_LAYOUT_ALV.

  repid = sy-repid.
  variant-report = sy-repid.
  variant-username = sy-uname.

  perform build_field_catalog.

  perform comment_build using list_top_of_page[].


* Call ABAP List Viewer (ALV)

  call function 'REUSE_ALV_GRID_DISPLAY'
       exporting
            it_fieldcat        = fieldcat
            i_callback_program = repid
            is_variant         = variant
            it_events          = events[]
            IS_LAYOUT          = layout
            i_save             = 'U'
       tables
            t_outtab           = i_alv.

endform.

************************************************************************
* EVENTTAB_BUILD
************************************************************************
form eventtab_build using events type slis_t_event.

* Registration of events to happen during list display
  data: tmp_event type slis_alv_event.

  call function 'REUSE_ALV_EVENTS_GET'
       exporting
            i_list_type = 0
       importing
            et_events   = events.
  read table events with key name = slis_ev_top_of_page
                           into tmp_event.
  if sy-subrc = 0.
    move top_of_page to tmp_event-form.
    append tmp_event to events.
  endif.

endform.

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

  clear: fieldcat. refresh: fieldcat.

  data: tmp_fc type slis_fieldcat_alv.

  tmp_fc-reptext_ddic = 'Material'.
  tmp_fc-fieldname    = 'MATNR'.
  tmp_fc-tabname      = 'I_ALV'.
  tmp_fc-outputlen    = 18.
  append tmp_fc to fieldcat.

endform.

************************************************************************
* COMMENT_BUILD
************************************************************************
form comment_build using list_top_of_page type
                                        slis_t_listheader.
  data: tmp_line type slis_listheader.

  clear tmp_line.
  tmp_line-typ  = 'H'.
  tmp_line-info = 'Here is a line of text'.
  append tmp_line to list_top_of_page.

  clear tmp_line.
  tmp_line-typ  = 'S'.
  tmp_line-key  = 'Key1'.
  tmp_line-info = 'Here is a value'.
  append tmp_line to list_top_of_page.

  clear tmp_line.
  tmp_line-typ  = 'S'.
  tmp_line-key  = 'Key2'.
  tmp_line-info = 'Here is another value'.
  append tmp_line to list_top_of_page.

endform.


************************************************************************
* TOP_OF_PAGE
************************************************************************
form top_of_page.

  call function 'REUSE_ALV_COMMENTARY_WRITE'
       exporting
            i_logo             = 'ENJOYSAP_LOGO'
            it_list_commentary = list_top_of_page.

endform.

Regards,

Rich Heilman

5 REPLIES 5

Former Member
0 Kudos

HI,

Do a describe table..

LIKE..

DESCRIBE TABLE ITAB LINES V_LINES.

V_lines is the no: of lines displayed in the report from the internal table.

Former Member
0 Kudos

WHat exactly u want, no of records diaplyed in each page ? or total no of records.

If its the later one ...do a Descible table on ur final internal table.

If its the former then u have to explictily code it .

In the report header u wud have given LINE-COUNT .

Say LINE-COUNT 65. That means in each page there can be a max of 65 lines,

what u can do is 65-reportheader size-columnheadings

is a rough estimate no of records in ur page

Message was edited by: Nandha Kumar Raju

RichHeilman
Developer Advocate
Developer Advocate
0 Kudos

Where do you want to put it. In the TOP? All you need to do is find the number of records in the internal table.

Data: NO_OF_LINES type i.

DESCRIBE TABLE ITAB LINES NO_OF_LINES.

Then you can use this sample program to learn how to use the ALV TOP.



report zrich_0001
       no standard page heading.

* Global ALV Data Declarations
type-pools slis.

data: begin of i_alv occurs 0,
      matnr type mara-matnr,
      end of i_alv.

* Miscellanous Data Declarations
data: fieldcat type slis_t_fieldcat_alv,
      events   type slis_t_event,
      list_top_of_page type slis_t_listheader,
      top_of_page  type slis_formname value 'TOP_OF_PAGE'.


start-of-selection.

  perform initialization.
  perform get_data.
  perform call_alv.

end-of-selection.

************************************************************************
*  Form  Initialization
************************************************************************
form initialization.

  clear i_alv.       refresh i_alv.

  perform eventtab_build using events[].

endform.

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

  select matnr into table i_alv
              from mara up to 100 rows.

endform.

************************************************************************
*  CALL_ALV
************************************************************************
form call_alv.

  data: variant type  disvariant.
  data: repid type sy-repid.
  data: layout type  SLIS_LAYOUT_ALV.

  repid = sy-repid.
  variant-report = sy-repid.
  variant-username = sy-uname.

  perform build_field_catalog.

  perform comment_build using list_top_of_page[].


* Call ABAP List Viewer (ALV)

  call function 'REUSE_ALV_GRID_DISPLAY'
       exporting
            it_fieldcat        = fieldcat
            i_callback_program = repid
            is_variant         = variant
            it_events          = events[]
            IS_LAYOUT          = layout
            i_save             = 'U'
       tables
            t_outtab           = i_alv.

endform.

************************************************************************
* EVENTTAB_BUILD
************************************************************************
form eventtab_build using events type slis_t_event.

* Registration of events to happen during list display
  data: tmp_event type slis_alv_event.

  call function 'REUSE_ALV_EVENTS_GET'
       exporting
            i_list_type = 0
       importing
            et_events   = events.
  read table events with key name = slis_ev_top_of_page
                           into tmp_event.
  if sy-subrc = 0.
    move top_of_page to tmp_event-form.
    append tmp_event to events.
  endif.

endform.

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

  clear: fieldcat. refresh: fieldcat.

  data: tmp_fc type slis_fieldcat_alv.

  tmp_fc-reptext_ddic = 'Material'.
  tmp_fc-fieldname    = 'MATNR'.
  tmp_fc-tabname      = 'I_ALV'.
  tmp_fc-outputlen    = 18.
  append tmp_fc to fieldcat.

endform.

************************************************************************
* COMMENT_BUILD
************************************************************************
form comment_build using list_top_of_page type
                                        slis_t_listheader.
  data: tmp_line type slis_listheader.

  clear tmp_line.
  tmp_line-typ  = 'H'.
  tmp_line-info = 'Here is a line of text'.
  append tmp_line to list_top_of_page.

  clear tmp_line.
  tmp_line-typ  = 'S'.
  tmp_line-key  = 'Key1'.
  tmp_line-info = 'Here is a value'.
  append tmp_line to list_top_of_page.

  clear tmp_line.
  tmp_line-typ  = 'S'.
  tmp_line-key  = 'Key2'.
  tmp_line-info = 'Here is another value'.
  append tmp_line to list_top_of_page.

endform.


************************************************************************
* TOP_OF_PAGE
************************************************************************
form top_of_page.

  call function 'REUSE_ALV_COMMENTARY_WRITE'
       exporting
            i_logo             = 'ENJOYSAP_LOGO'
            it_list_commentary = list_top_of_page.

endform.

Regards,

Rich Heilman

0 Kudos

Problem is solved.

Thanks for all the help.

/claes

Message was edited by: Claes Widestadh

0 Kudos

I don't think that the problem is solved ... keep in mind that if you want to display the number of rows displayed by the alv, you have to check whether a filter is set or not... describe table lines lv_count doesn't work for that!