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: 

ALV Cursor position

hamzaefe44
Explorer
0 Kudos
220

Hi,

I have a requirement about alv cursor position but I faced a problem. I was able to Highlighted to cell using this code:

    DATAls_row    TYPE i,
          ls_value  TYPE c,
          ls_col    TYPE i,
          ls_row_id TYPE lvc_s_row,
          ls_col_id TYPE  lvc_s_col,
          es_row_no TYPE lvc_s_roid.

    CALL METHOD lo_alv->get_current_cell
      IMPORTING
        e_row     ls_row
        e_value   ls_value
        e_col     ls_col
        es_row_id ls_row_id
        es_col_id ls_col_id
        es_row_no es_row_no.
    IF ls_col 1."next line
      ls_col_id 'LGORT'.  "cursor will go this field.
      CALL METHOD lo_alv->refresh_table_display.
      CALL METHOD lo_alv->set_current_cell_via_id
        EXPORTING
          is_column_id ls_col_id
          is_row_no    es_row_no.
      CALL METHOD lo_alv->refresh_table_display
        EXPORTING
*          is_stable      =
          i_soft_refresh abap_true
*        EXCEPTIONS
*          finished       = 1
*          others         = 2
        .
      IF sy-subrc <> 0.
*       MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
*                  WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
      ENDIF.
    ELSE.
      ls_col_id 'WERKS'.  "cursor will go this field.
      es_row_no-row_id conv ies_row_no-row_id .
      CALL METHOD lo_alv->refresh_table_display.
      CALL METHOD lo_alv->set_current_cell_via_id
        EXPORTING
          is_column_id ls_col_id
          is_row_no    es_row_no.
    ENDIF.


but cursor itself located top of screen where we enter tcode here is cursor position where its located:

hamzaefe44_0-1725520131625.png

How can I solve this problem.



2 REPLIES 2

Sandra_Rossi
Active Contributor
186

The focus was lost. Did you try cl_gui_control=>set_focus( lo_alv ). (+ handle classic exceptions)

183

https://community.sap.com/t5/application-development-discussions/set-focus-on-alv-oo/td-p/5166329
in the link above I saw that the set_focus solution should be used in pbo. Now the problem solved thank you  for your reply.