Application Development and Automation 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: 
Read only

Editable ALV - OOPs scrolling problem

ankit_munshi2
Participant
0 Likes
6,217

Hi,

I have an output ALV screen which is editable . The screen could have more than 1000 records . the problem is that if we scroll down, modify a record and then click on our custom functionality buttons - scroll automatically moves up . This becomes annoying since my ALV grid is supposed to have more than 1000 records and if we are processing 900th record , scroll would move up and we have to manually search for that record again .

Is there any workaround for this ?

I am using method set table for first display for this functionality ( so please don't bother about REUSE_ALV_GRID_DISPLAY replies).

Regards,

Ankit Munshi

1 ACCEPTED SOLUTION
Read only

ankit_munshi2
Participant
4,177

Thanks all for your help !

The issue was resolved by calling  CALL METHOD grid1->set_scroll_info_via_id AFTER calling  set_table_for_first_display method.


6 REPLIES 6
Read only

former_member201275
Active Contributor
0 Likes
4,177

There is a sap standard demo program BCALV_EDIT_09 which does this, also using OO. There they have an alv, you can click on the 'change' button and change entries in the alv, and also click on other buttons and the alv doesn't scroll. I am not exactly sure how they do it but maybe you can go through the code and find your answer.

Hope this helps.

Read only

0 Likes
4,177

Hi Glen,

Thanks for your response. I checked the said program , I do not see anything special that they might have done in this program for scrolling issue.

They are using the same classes as me , with the same parameters:(

Read only

0 Likes
4,177

Hi.

Every time you execute a function you make a refresh.

In order to keep the position you have to read positions before refreshing.

Do the following:

DATA: li_rows    TYPE lvc_s_roid,

         li_col     TYPE lvc_s_col,

         lws_row_id TYPE lvc_s_roid,

         lws_col_id TYPE lvc_s_col,

         ls_col     TYPE lvc_s_col,

         ls_num     TYPE lvc_s_roid.

   CALL METHOD c_grid->get_current_cell

     IMPORTING

       es_col_id = li_col

       es_row_no = li_rows.

   CALL METHOD c_grid->get_scroll_info_via_id

     IMPORTING

       es_col_info = ls_col

       es_row_no   = ls_num.

   CALL METHOD c_grid->refresh_table_display.

   CALL METHOD c_grid->set_scroll_info_via_id

     EXPORTING

       is_col_info = ls_col

       is_row_no   = ls_num.

   lws_row_id-row_id    = li_rows-row_id.

   lws_col_id-fieldname = li_col-fieldname.

   CALL METHOD c_grid->set_current_cell_via_id

     EXPORTING

       is_column_id = lws_col_id

       is_row_no    = lws_row_id.



Hope to help.-


Bye

Read only

0 Likes
4,177

Thanks for your help Roberto. Unfortunately it didn't work for me . Thing is I have not used CALL METHOD c_grid->refresh_table_display. anywhere in my current logic.


What I am doing is simply reading the scroll position in PAI and setting the same position in RBO just before the call METHOD set_table_for_first_display.


here is the code -

**************************************************************

**************************************************************

MODULE pbo OUTPUT.

   SET PF-STATUS 'CUSTOM_STATUS'.
   SET TITLEBAR  'CUSTOM_TITLE'.

   IF g_custom_container IS INITIAL.

     CREATE OBJECT g_custom_container
       EXPORTING
         container_name = g_container.

     CREATE OBJECT grid1
       EXPORTING
         i_parent = g_custom_container.
   ENDIF.

   PERFORM f_modify_init_style.

   gt_outtab2[] = gt_outtab[].

   PERFORM f_display_alv.

**************************************************************

**************************************************************

MODULE pai INPUT.

   CASE ok_code.
     WHEN 'EXIT'.
       LEAVE TO SCREEN 0.

     WHEN 'BACK'.
       LEAVE TO SCREEN 0.

     WHEN 'VAL'.
* get values changed on screen
       PERFORM f_get_changed_values .

* Validate and save changed reads
       PERFORM f_validate_reads .

     WHEN 'ZENTER'.

* get values changed on screen
       PERFORM f_get_changed_values .

* Validate changed reads
       PERFORM f_validate_reads .

     WHEN 'REL'.
       PERFORM f_rel_save_reads.

     WHEN 'ESTM'. " estimate reads
* get changed data and then selected rows
       CALL METHOD grid1->check_changed_data .

       CLEAR : gt_selected_rows.
       CALL METHOD grid1->get_selected_rows
         IMPORTING
           et_index_rows = gt_selected_rows.

       PERFORM f_get_selected_records.

* estimate reads
       PERFORM f_estimate_reads.

   ENDCASE.

   CALL METHOD grid1->get_current_cell
     IMPORTING
       es_col_id = li_col
       es_row_no = li_rows.

   CALL METHOD grid1->get_scroll_info_via_id
     IMPORTING
       es_col_info = ls_col
       es_row_no   = ls_num.

   CALL METHOD grid1->refresh_table_display.



ENDMODULE.                 " PAI  INPUT


**************************************************************

**************************************************************

  ls_exclude = grid1->mc_fc_check.
   APPEND ls_exclude TO lt_exclude.
   CLEAR ls_exclude.

* If enter is pressed event data changed will be triggered
   CALL METHOD grid1->register_edit_event
     EXPORTING
       i_event_id = cl_gui_alv_grid=>mc_evt_enter.

   SET HANDLER: lcl_eventhandler=>handle_data_changed FOR grid1.

   CALL METHOD grid1->set_scroll_info_via_id
     EXPORTING
       is_col_info = ls_col
       is_row_no   = ls_num.

   lws_row_id-row_id    = li_rows-row_id.
   lws_col_id-fieldname = li_col-fieldname.

   CALL METHOD grid1->set_current_cell_via_id
     EXPORTING
       is_column_id = lws_col_id
       is_row_no    = lws_row_id.

   CALL METHOD grid1->set_table_for_first_display
     EXPORTING
       is_layout            = gs_layout
       it_toolbar_excluding = lt_exclude
     CHANGING
       it_outtab            = gt_outtab[]
       it_fieldcatalog      = gt_fieldcat.

* set edit enabled cells ready for input
   CALL METHOD grid1->set_ready_for_input
     EXPORTING
       i_ready_for_input = 1.


**************************************************************

**************************************************************


FORM f_get_changed_values .

   DATA : lv_index TYPE sy-tabix.

   CLEAR : lv_index.
   CALL METHOD grid1->check_changed_data .

   CLEAR gt_changed[].

   LOOP AT gt_outtab.

     lv_index = sy-tabix.

     CLEAR gt_outtab2.
     READ TABLE gt_outtab2 WITH KEY anlage    = gt_outtab-anlage
                                    sernr     = gt_outtab-sernr
                                    zwnummer  = gt_outtab-zwnummer
                                    adatsoll  = gt_outtab-adatsoll
                                    kwh_read  = gt_outtab-kwh_read
                                    istablart = gt_outtab-istablart
                                    adat      = gt_outtab-adat
                                    mrnote    = gt_outtab-mrnote.
     IF sy-subrc NE 0. " means record was changed on screen
       APPEND gt_outtab TO gt_changed[].
       IF gt_outtab2-flag EQ abap_true.
         CLEAR gt_outtab2-flag .
         MODIFY gt_outtab FROM  gt_outtab2 INDEX lv_index TRANSPORTING flag" if reads/readtype/date etc has changed - reset release flag - treat it as new unevaluated record
       ENDIF.

     ELSEIF    gt_outtab2-text    IS NOT INITIAL
       AND     gt_outtab2-flag    IS INITIAL" this flag would indicate whether read was released or not
       " we do not want a read which was released to show up again in table gt_changed
       APPEND gt_outtab TO gt_changed[].
     ENDIF.
     CLEAR gt_outtab.
   ENDLOOP.

ENDFORM.                    " F_GET_CHANGED_VALUES

Read only

0 Likes
4,177

HI.

You are using grid1 instead of c_grid, it's natural. In the last step of PAI you're using grid1->refresh_table_display.

In the PBO you should call che alv display only once, and  in others times you should only refresh if the container is already filled. In the PAI you don't have to use refresh_table_display but only commands but it depends on your needs.

When you use REFRESH_TABLE_DISPLAY use option SOFT_REFRESH. Try this .

Hope to help

Bye

Read only

ankit_munshi2
Participant
4,178

Thanks all for your help !

The issue was resolved by calling  CALL METHOD grid1->set_scroll_info_via_id AFTER calling  set_table_for_first_display method.