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: 

Can we scroll to the last page of an alv grid?

Former Member
0 Kudos

I am dispalying a report in ALV grid format - REUSE_ALV_GRID_DISPLAY.

As soon as the execute button is clicked it should show the last page with the totals.

User will then scroll upwards to see the details.

How to scroll to the end of the ALV grid?

(It is like goign to the last page of course)

Thanks,

Ven

1 ACCEPTED SOLUTION

Former Member
0 Kudos

Hi,

Yes..You can do it using the OO ALV...You can use the method set_current_cell_via_id ..to show the last record.

Check this example.

* Declarations.
DATA: l_lines TYPE int4,
      l_row_no TYPE lvc_s_roid.
DATA: ok_code LIKE sy-ucomm,
      g_container TYPE scrfname VALUE 'CONTAINER1',
      g_grid  TYPE REF TO cl_gui_alv_grid,
      g_custom_container TYPE REF TO cl_gui_custom_container,
      gs_layout TYPE lvc_s_layo.

DATA: gt_outtab TYPE TABLE OF t001w.
DATA: v_count TYPE i.

*---------------------------------------------------------------------*
*       MAIN                                                          *
*---------------------------------------------------------------------*
CALL SCREEN 100.

*---------------------------------------------------------------------*
*       MODULE PBO OUTPUT                                             *
*---------------------------------------------------------------------*
MODULE pbo OUTPUT.

  SET PF-STATUS 'TEST'.
  SET TITLEBAR 'MAIN100'.

* Create the grid.
  IF g_custom_container IS INITIAL.
    CREATE OBJECT g_custom_container
      EXPORTING
        container_name = g_container.
    CREATE OBJECT g_grid
      EXPORTING
        i_parent = g_custom_container.

* Get the data.
    SELECT * FROM t001w INTO TABLE gt_outtab.

    CALL METHOD g_grid->set_table_for_first_display
      EXPORTING
        i_structure_name = 'T001W'
        is_layout        = gs_layout
      CHANGING
        it_outtab        = gt_outtab.

    DESCRIBE TABLE gt_outtab LINES l_lines.

* Go to the last row.
    l_row_no-row_id =  l_lines.
    CALL METHOD g_grid->set_current_cell_via_id
      EXPORTING
        is_row_no = l_row_no.

  ENDIF.
ENDMODULE.                    "pbo OUTPUT
*---------------------------------------------------------------------*
*       MODULE PAI INPUT                                              *
*---------------------------------------------------------------------*
MODULE pai INPUT.
  CASE sy-ucomm.
    WHEN 'EXIT' OR 'BACK'.
      PERFORM exit_program.
  ENDCASE.
ENDMODULE.                    "pai INPUT
*---------------------------------------------------------------------*
*       FORM EXIT_PROGRAM                                             *
*---------------------------------------------------------------------*
FORM exit_program.
  LEAVE PROGRAM.
ENDFORM.                    "exit_program

Thanks

Naren

10 REPLIES 10

former_member188685
Active Contributor
0 Kudos

it is not possible to show the last page. if you have subtotals then can do this..

in the sort you have expa if you set this expa to 'X' all the subnodes will be collapsed.

so you can see all the totals etc. then you can expand and see the details if you want.

sort-fieldname = 'FIELDNAME'.
sort-subtot = 'X'.
sort-up = 'X'.
sort-expa = 'X'.
append sort to it_sort.

0 Kudos

Is it possible to scroll by using methods?

When I use a container and object oriented code, it brings in a default pf-status. On this when I click on the create button it is scrolling to the bottm and adding lines.

(BCALV_EDIT_02, 04 etc).

However I am not able to use the buttons here as I am not able to get a control over them. (These are not going into debug mode).

Thanks,

Ven,

Former Member
0 Kudos

Hi,

Yes..You can do it using the OO ALV...You can use the method set_current_cell_via_id ..to show the last record.

Check this example.

* Declarations.
DATA: l_lines TYPE int4,
      l_row_no TYPE lvc_s_roid.
DATA: ok_code LIKE sy-ucomm,
      g_container TYPE scrfname VALUE 'CONTAINER1',
      g_grid  TYPE REF TO cl_gui_alv_grid,
      g_custom_container TYPE REF TO cl_gui_custom_container,
      gs_layout TYPE lvc_s_layo.

DATA: gt_outtab TYPE TABLE OF t001w.
DATA: v_count TYPE i.

*---------------------------------------------------------------------*
*       MAIN                                                          *
*---------------------------------------------------------------------*
CALL SCREEN 100.

*---------------------------------------------------------------------*
*       MODULE PBO OUTPUT                                             *
*---------------------------------------------------------------------*
MODULE pbo OUTPUT.

  SET PF-STATUS 'TEST'.
  SET TITLEBAR 'MAIN100'.

* Create the grid.
  IF g_custom_container IS INITIAL.
    CREATE OBJECT g_custom_container
      EXPORTING
        container_name = g_container.
    CREATE OBJECT g_grid
      EXPORTING
        i_parent = g_custom_container.

* Get the data.
    SELECT * FROM t001w INTO TABLE gt_outtab.

    CALL METHOD g_grid->set_table_for_first_display
      EXPORTING
        i_structure_name = 'T001W'
        is_layout        = gs_layout
      CHANGING
        it_outtab        = gt_outtab.

    DESCRIBE TABLE gt_outtab LINES l_lines.

* Go to the last row.
    l_row_no-row_id =  l_lines.
    CALL METHOD g_grid->set_current_cell_via_id
      EXPORTING
        is_row_no = l_row_no.

  ENDIF.
ENDMODULE.                    "pbo OUTPUT
*---------------------------------------------------------------------*
*       MODULE PAI INPUT                                              *
*---------------------------------------------------------------------*
MODULE pai INPUT.
  CASE sy-ucomm.
    WHEN 'EXIT' OR 'BACK'.
      PERFORM exit_program.
  ENDCASE.
ENDMODULE.                    "pai INPUT
*---------------------------------------------------------------------*
*       FORM EXIT_PROGRAM                                             *
*---------------------------------------------------------------------*
FORM exit_program.
  LEAVE PROGRAM.
ENDFORM.                    "exit_program

Thanks

Naren

naimesh_patel
Active Contributor
0 Kudos

I don't know if is it possible to scroll to last page of ALV, but you can bring the total on the very first line.

In the LAYOUT we have a option to bring the Total on the first line. Like:


data: LS_LAYOUT TYPE  SLIS_LAYOUT_ALV .
ls_layout-totals_before_items = 'X'.

Regards,

Naimesh Patel

naimesh_patel
Active Contributor
0 Kudos

If you don't want to move the totals to first line you can scroll the list in the Classcial ALV also.

1. You need to get the Grid object from the ALV using the FM GET_GLOBALS_FROM_SLVC_FULLSCR

2. Call method to set_current_cell_via_id to last line.

You need to call this grid object before it generates the output. So, good palce would be the TOP_OF_PAGE routine.


* get the global reference
  CALL FUNCTION 'GET_GLOBALS_FROM_SLVC_FULLSCR'
   IMPORTING
      e_grid                           = lo_grid.

* Go to the last row.
    DATA: la_row_no TYPE lvc_s_roid.
    describe table it_bkpf lines sy-index.
    la_row_no-row_id =  sy-index.
    CALL METHOD lo_grid->set_current_cell_via_id
      EXPORTING
        is_row_no = la_row_no.

You can check the the entired code which has the same kind of concept on my professional blog: [Classical ALV: Change Subtotal |http://help-abap.blogspot.com/2008/09/classical-alv-change-subtotal.html]

Thanks to Narendran to point out me towards the SET_CURRENT_CELL_VIA_ID method.

Regards,

Naimesh Patel

0 Kudos

Here is the code I used with the Last Page option using the above inputs.

Now you can scroll in alv grid display also.

In the user_command routine:

WHEN 'P++'.

DATA: l_lines TYPE int4,

lo_GRID TYPE REF TO CL_GUI_ALV_GRID,

l_row_no TYPE lvc_s_roid.

DESCRIBE TABLE t_mara LINES l_lines.

l_row_no-row_id = l_lines.

CALL UNCTION 'GET_GLOBALS_FROM_SLVC_FULLSCR'

IMPORTING

e_grid = lo_grid.

CALL METHOD lo_grid->set_current_cell_via_id

EXPORTING

is_row_no = l_row_no.

I think by getting the grid name, the reuse_alv_grid_display and methods can be combined.

because in most of the methods, it looks for the grid name.

Thanks to every body.

Ven.

PS: This however becomes a bit clumsy if youa re using top_of_page event.

The event gets triggered twice - for the first page as well as the last page and shows twice.

Not sure how to control it - trying of course....

0 Kudos

I guess, TOP OF PAGE event will fire only once, since you are in the ALV grid (not the List).

If it is calling more than once than you can set some flag and check to avoid multiple access of the object.

Like:


DATA: W_FLAG type FLAG.   "Declare in Global data

FORM top_of_page.

IF W_FLAG IS INITIAL.
  W_FLAG = 'X'.

* PROCESS TO SCROLL DOWN

ENDIF.  

ENDFORM.

Regards,

Naimesh Patel

0 Kudos

The method I described earlier for Page Down P++, did not work for me when I added a blank line to the end of the grid display. I am able to add the line but it is not scrolling.

So I did a bit of research and added the following code in the pf-status event.

IF NOT v_index IS INITIAL. "[v_index(10) - global decalration of data]

ls_scroll_grid-s_row_info-index = v_index.

  • gs_grid_opt-rowcol_info-row_index.

ls_scroll_grid-s_col_info-fieldname = 'MATNR'.

  • gs_grid_opt-rowcol_info-col_fieldname.

CALL FUNCTION 'REUSE_ALV_GRID_LAYOUT_INFO_SET'

EXPORTING

is_grid_scroll = ls_scroll_grid.

ENDIF.

In the user_command event, describe the grid dispaly internal table and pass the no_of_lines value to v_index.

Once this code is in place, when you click on the add line button, it scrolls to the end of the list and adds a new line.

Thanks,

Ven

0 Kudos

Hi Ven,

using the

CALL FUNCTION 'REUSE_ALV_GRID_LAYOUT_INFO_SET'

EXPORTING

is_grid_scroll = ls_scroll_grid.

i become a

"Laufzeitfehler GETWA_NOT_ASSIGNED

Kurztext Feldsymbol ist noch nicht zugewiesen

Programm SAPLSLVC

Include LSLVCU07

Modulname LVC_TRANSFER_FROM_KKBL0"

Do you know, what is the Problem?

Thanks

Former Member
0 Kudos

Resolved as per the details mentioned above