0

Say I have a table with customers, which is shown in an alv-grid like so:

**BEFORE THIS: Set up parameters, SQL Select, Table etc.
CREATE OBJECT gr_alv_grid
    EXPORTING
        i_parent = cl_gui_custom_container=>default_screen
    EXCEPTIONS
        error_cntl_create = 1
        error_cntl_init = 2
        error_cntl_link = 3
        error_dp_create = 4
        others = 5.
   IF sy-subrc <> 0.
    MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno.
   ENDIF.

gr_alv_grid->set_table_for_first_display(
    EXPORTING
        i_structure_name = 'ZDebcdstest'
    CHANGING
        it_outtab = lt_debis
    EXCEPTIONS
        invalid_parameter_combination = 1
        program_error = 2
        too_many_lines = 3
        others = 4
).
IF sy-subrc <> 0.
    MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
        WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ENDIF.

What I would like to have is the option to double-click on any given row and get a more detailed overview of the object contained therein, like for instance done in SE16. I have already set up an Event Handler to listen for a double click, which works, but I haven't figured out how to get all the relevant data in a row and display the chosen object in full detail.

Any help is greatly appreciated.

Suncatcher
  • 10,355
  • 10
  • 52
  • 90
Just some Guy
  • 123
  • 1
  • 6
  • 3
    It is simple in the event data you get the row number which you then have to use when reading from your internal table that is displayed in ALV. In this case `lt_debis`. There is also a lot of materials on ALV on the internet, so please do your research first. – Jagger Nov 11 '20 at 09:12
  • You mean by importing it like this? CLASS lh_event_handler DEFINITION. PUBLIC SECTION. METHODS: handle_double_click FOR EVENT double_click OF cl_gui_alv_grid IMPORTING e_row. ENDCLASS. And then using that data in the Implementation? – Just some Guy Nov 11 '20 at 09:19
  • 2
    This event has three parameters which are available in the event handler: `E_ROW E_COLUMN ES_ROW_NO`. The data in the row can be then accesed like that `lt_debis[ e_row-index ]` – Jagger Nov 11 '20 at 09:42
  • Ah, I see. Probably a stupid question, but what would it look like in the Implementation then? – Just some Guy Nov 11 '20 at 09:44
  • 2
    The implementation is up to you. Just try my hint, update your example with a concrete problem and then the community will be able to help you. – Jagger Nov 11 '20 at 09:45
  • Got it now, thanks for the help and sorry for being a bit thick about it. :) – Just some Guy Nov 11 '20 at 13:55
  • Stack Overflow requests that your question is focused on one question (and only one). The first one you have is about how to read the details of the double-clicked line in the double-click event handler, so I suggest that you just ask this one here. Displaying the "chosen object in full detail" would lead to too many opinionated answers. Please read the Stack Overflow help center for more information about how to ask questions. – Sandra Rossi Nov 11 '20 at 17:38

1 Answers1

2

Here is the primitive sample how to make it work "like for instance done in SE16'

  METHOD handle_double_click.
    DATA: ls_sflight LIKE LINE OF gt_sflight,
          ls_layout  TYPE lvc_s_layo.

    DATA: lt_fieldcatalog TYPE lvc_t_fcat,
          ls_fieldcatalog TYPE lvc_s_fcat.

    DATA: details_outtab TYPE lvc_t_detm,
          ls_detail      TYPE lvc_s_detm,
          lt_detail_tab  TYPE lvc_t_deta,
          ls_detail_tab  TYPE lvc_s_deta.

    READ TABLE gt_sflight INDEX e_row-index INTO ls_sflight.

    ls_fieldcatalog-fieldname = 'COLUMNTEXT'.
    ls_fieldcatalog-ref_table = 'LVC_S_DETA'.
    ls_fieldcatalog-key       = 'X'.
    ls_fieldcatalog-seltext   = 'Field'.
    ls_fieldcatalog-outputlen = 30.
    APPEND ls_fieldcatalog TO lt_fieldcatalog.

    CLEAR ls_fieldcatalog.
    ls_fieldcatalog-fieldname = 'VALUE'.
    ls_fieldcatalog-ref_table = 'LVC_S_DETA'.
    ls_fieldcatalog-seltext   = 'Field value'.
    ls_fieldcatalog-outputlen = 20.
    APPEND ls_fieldcatalog TO lt_fieldcatalog.

    ls_layout-no_toolbar = 'X'.

    LOOP AT gt_fieldcat ASSIGNING FIELD-SYMBOL(<field>).
      ls_detail_tab-columntext = <field>-scrtext_l.
      ASSIGN COMPONENT sy-tabix OF STRUCTURE ls_sflight TO FIELD-SYMBOL(<col>).
      ls_detail_tab-value = <col>.
      APPEND ls_detail_tab TO lt_detail_tab.
    ENDLOOP.
    ls_detail-detailtab = lt_detail_tab.
    APPEND ls_detail TO details_outtab.

    CALL FUNCTION 'LVC_ITEM_DETAIL'
      EXPORTING
        i_title               = 'Row details'
        it_fieldcatalog       = lt_fieldcatalog
        is_layout             = ls_layout
      TABLES
        t_outtab              = details_outtab.

  ENDMETHOD.                           "handle_double_click

in the above snippet

gt_sflight - main table you wanna capture row details from

gt_fieldcat - field catalog of this table which must be populated before firing the event

if you don't know how apply this method to your ALV, search for some tutorial about event implementation.

Suncatcher
  • 10,355
  • 10
  • 52
  • 90