abapalv

Callback subroutine of REUSE_ALV_GRID_DISPLAY is not triggered?


I watched a video on YouTube that showed how to call a transaction by clicking on a specific field in the ALV view, but when replicating it in my code I was unable to implement this function. When I click on a document in the "EBELN" field nothing happens.

The issue is that the program does not produce any errors, but when I attempt to debug it by placing a breakpoint in the call transaction section, it simply skips over that part. This section is only executed when there is a double-click on the `ebeln` field, but when I double-click nothing happens.

Why is the double click not executing the ''user_command'' form?

what's wrong in my code?

PERFORM chama_alv.

*---------------------------------------------------------------------*
*       FORM CHAMA_ALV                                                *
*---------------------------------------------------------------------*
FORM chama_alv.
  CLEAR: fieldcat.
  REFRESH: fieldcat.

  PERFORM monta_fieldcat USING 'EBELN' 'LS_TABELA1' 'LS_TABELA1' 'DOCUMENTO' ' ' 'X'.
  PERFORM monta_fieldcat USING 'LIFNR' 'LS_TABELA1' 'LS_TABELA1' 'FORNECEDOR' ' ' ' '.
  PERFORM monta_fieldcat USING 'NAME1' 'LS_TABELA1' 'LS_TABELA1' 'NOME FORNECEDOR' ' ' ' '.
  PERFORM monta_fieldcat USING 'AEDAT' 'LS_TABELA1' 'LS_TABELA1' 'DATA CRIAÇÃO DO PEDIDO' ' ' ' '.
  PERFORM monta_fieldcat USING 'UDATE' 'LS_TABELA1' 'LS_TABELA1' 'DATA MODIFICAÇÃO' ' ' ' '.
  PERFORM monta_fieldcat USING 'COUNT' 'LS_TABELA1' 'LS_TABELA1' 'REAPROVAÇÕES' ' ' ' '.
  PERFORM monta_fieldcat USING 'TEXTO' 'LS_TABELA1' 'LS_TABELA1' 'MOTIVO' ' ' ' '.

  CLEAR sort.
  sort-fieldname = 'EBELN'.
  sort-up = 'X'.
  APPEND sort TO sort.

  layout-colwidth_optimize = 'X'.
  layout-zebra = 'X'.

  CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
    EXPORTING
      i_callback_user_command = 'user_command'
      it_fieldcat             = fieldcat[]
      is_layout               = layout
      it_sort                 = sort[]
      i_grid_title            = w_tit
      i_default               = 'X'
      i_save                  = 'A'
      is_variant              = variante
      is_print                = print
    TABLES
      t_outtab                = lt_tabela1
    EXCEPTIONS
      program_error           = 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.
ENDFORM.

*---------------------------------------------------------------------*
*       FORM MONTA_FIELDCAT                                           *
*---------------------------------------------------------------------*
FORM monta_fieldcat USING x_field x_tab x_ref x_text x_sum x_hotspot.
  fieldcat-fieldname     = x_field.
  fieldcat-tabname       = x_tab.
  fieldcat-ref_tabname   = x_ref.
  fieldcat-reptext_ddic  = x_text.
  fieldcat-do_sum        = x_sum.
  fieldcat-hotspot       = x_hotspot.

  IF x_field = 'UDATE' OR x_field = 'AEDAT'.
    fieldcat-inttype = 'D'.
  ENDIF.

  APPEND fieldcat.
  CLEAR fieldcat.
ENDFORM.

*---------------------------------------------------------------------*
*       FORM SET_STATUS                                               *
*---------------------------------------------------------------------*
FORM set_status USING pf_tab TYPE slis_t_extab.
ENDFORM.

*---------------------------------------------------------------------*
*       FORM ALV_INIT                                                 *
*---------------------------------------------------------------------*
FORM alv_init.
  CLEAR: variante.
  repid = sy-repid.

  variante-report = repid.
  CALL FUNCTION 'REUSE_ALV_VARIANT_DEFAULT_GET'
    EXPORTING
      i_save     = 'A'
    CHANGING
      cs_variant = variante
    EXCEPTIONS
      not_found  = 2.
  IF sy-subrc = 0.
  ENDIF.
ENDFORM.

*---------------------------------------------------------------------*
*       FORM USER_COMMAND                                             *
*---------------------------------------------------------------------*
FORM user_command USING r_ucomm LIKE sy-ucomm
                         rs_selfield TYPE slis_selfield.

  CASE r_ucomm.
    WHEN '&IC1'.  
      CASE rs_selfield-fieldname.
        WHEN 'EBELN'.
          READ TABLE lt_tabela1 INTO ls_tabela1 INDEX rs_selfield-tabindex.
          IF sy-subrc = 0.
            SET PARAMETER ID 'BES' FIELD ls_tabela1-EBELN.
            CALL TRANSACTION 'ME23N' AND SKIP FIRST SCREEN.
          ENDIF.
      ENDCASE.
  ENDCASE.
ENDFORM.

In this code, I retrieve data from the ekko, cdhdr, and cdpos tables and place it into internal tables. These tables are then joined on the document number and the resulting data is stored in a final table (lt_tabela1). With this final table, I can call the ALV to display the data. Additionally, I want to set it up so that when I click on the EBELN field, it navigates to the ME23N transaction, displaying the document number that was clicked on.


Solution

  • I see you are using REUSE_ALV_GRID_DISPLAY for the display. Nowadays this is considered obsolate, so you might want to use a SALV or ALV_GRID object instead, which will give you easier, faster and better options for displaying and editing tables.

    But at this point you also have a table called fieldcatalog. It contains all the field settings. The hotspot will be set, which can be created as an event for the other objects and handled within it. This is usually the key to what logic to run when a field is clicked. I usually like to use the object oriented ALV_GRID, where this method can handle the hotspot click.

    Unfortunately, I don't have much experience with the plain REUSE_ALV_GRID_DISPLAY function, but I quickly generated the code I made and tested what might be wrong. What I really suspected is that ABAP is very case sensitive. My first suggestion is to capitalize the word USER_COMMAND when you pass it to it. And the second error was that you missed the i_callback_program parameter when calling the function. In this case it is sufficient to pass the sy-repid value to it.

    ...
        CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
            EXPORTING
              i_callback_program = sy-repid
              i_callback_user_command = 'USER_COMMAND'
    ...
    

    For me, after correcting these it successfully called the transaction, but I still recommend using SALV or ALV_GRID. However, since this is a hotspot click it will take you to the transaction with a single click instead of a double click.