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: 

Right Click in ALV output ?

Former Member
0 Kudos

Hi,

I have got an ALV output.

The reqmnt now is that, if the user Right Clicks on a particular field which is displayed, it should show two transactions, and then it should go to the transaction which is selected by the user.

How to do this in ALV. Any sample code would be very helpful.

Regards.

1 ACCEPTED SOLUTION

former_member188685
Active Contributor
0 Kudos

Nice example BCALV_GRID_06 provided by SAP ,check it once.

7 REPLIES 7

former_member188685
Active Contributor
0 Kudos

Nice example BCALV_GRID_06 provided by SAP ,check it once.

Former Member
0 Kudos

Hi,

For the field which you click to navigate to another transaction,provide HOTSPOT ON in the field catalogue.

then proceed as given below:

Eg:

-


FORM USER_COMMAND USING UCOMM LIKE SY-UCOMM SEL TYPE SLIS_SELFIELD .

IF SEL-FIELDNAME = 'EBELN'.

EBELN = SEL-VALUE.

READ TABLE ITAB INTO W_ITAB WITH KEY EBELN = SEL-VALUE.

SET PARAMETER ID 'BES' FIELD EBELN.

CALL TRANSACTION 'ME23N' . "AND SKIP FIRST SCREEN.

ENDIF.

ENDFORM.

-


Hope this will be useful.

Regards,

P.S.Chitra

0 Kudos

Chitra,

Actually the user will be right clicking on that particular field, then he will choose between two transactions and then it should go to that transaction.

Your input has been very helpful though, i didnt know about this. Thanks anyway.

Regards.

0 Kudos

Friends,

Still stuck with this.

In case, if someone know how to do it, do let me know.

Regards.

0 Kudos

Hi,

why do you use the Right-Click?

you can you double-click or hotspot, show a popup with 2 possibility and do what the user select.

Regards, Dieter

0 Kudos

Can't help much from our end.

The requirement is like that.

Former Member
0 Kudos

Check this sample program..may be it will help u.


REPORT z_alv_context_menu NO STANDARD PAGE HEADING.

***********************************************************************
* Type pool declaration
***********************************************************************
TYPE-POOLS: slis.

***********************************************************************
* Internal table declaration
***********************************************************************
DATA: BEGIN OF gt_outtab OCCURS 0.
        INCLUDE STRUCTURE sflight.
DATA: END OF gt_outtab.

data: gt_events       TYPE slis_t_event.

**********************************************************************
* Structure / Variable declaration
**********************************************************************
DATA: g_repid         LIKE sy-repid,
      event           TYPE slis_alv_event.


**********************************************************************
* Event: START-OF-SELECTION
**********************************************************************
START-OF-SELECTION.

* Storing the program name
  g_repid = sy-repid.

* Building ALV event table
  CALL FUNCTION 'REUSE_ALV_EVENTS_GET'
    EXPORTING
      i_list_type     = 4
    IMPORTING
      et_events       = gt_events
    EXCEPTIONS
      list_type_wrong = 1
      OTHERS          = 2.

  IF sy-subrc = 0.

    REFRESH gt_events.

*   Adding records for CONTEXT_MENU event
    event-name = 'CONTEXT_MENU'.
    event-form = 'CONTEXT_MENU'.
    APPEND event TO gt_events.

  ENDIF.


* Data Selection
  SELECT * FROM sflight INTO CORRESPONDING FIELDS
                   OF TABLE gt_outtab
                   UP TO 00030 ROWS.

* Display ALV grid
  CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
    EXPORTING
      i_callback_html_top_of_page = 'HTML_TOP_OF_PAGE'
      i_callback_program          = g_repid
      i_callback_user_command     = 'USER_COMMAND'
      i_structure_name            = 'SFLIGHT'
      it_events                   = gt_events
    TABLES
      t_outtab                    = gt_outtab
    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.


***********************************************************************
* FORM html_top_of_page
***********************************************************************
FORM html_top_of_page USING top TYPE REF TO cl_dd_document.

  CALL METHOD top->add_text
    EXPORTING
      text      = 'Hello world '
      sap_style = 'heading'.
  CALL METHOD top->add_gap
    EXPORTING
      width = 200.
  CALL METHOD top->add_picture
    EXPORTING
      picture_id = 'ENJOYSAP_LOGO'.

ENDFORM.                    "html_top_of_page

***********************************************************************
* Form  context_menu
***********************************************************************
FORM context_menu USING e_object TYPE REF TO cl_ctmenu.

  DATA: l_smenu TYPE REF TO cl_ctmenu.

  IF e_object IS BOUND.

*   Create custom Sub-menu to hide column on which right
*   mouse button will be clicked
    CREATE OBJECT l_smenu.
    CALL METHOD l_smenu->add_function
      EXPORTING
        fcode = 'ZFN1'
        text  = 'Hide Column'(001).

    CALL METHOD e_object->add_submenu
      EXPORTING
        menu = l_smenu
        text = 'Hide'(002).


  ENDIF.
ENDFORM.                    "CONTEXT_MENU

***********************************************************************
* Form  user_command
***********************************************************************
FORM user_command  USING r_ucomm TYPE sy-ucomm
                         ls_selfield TYPE slis_selfield.


  DATA: g_grid TYPE REF TO cl_gui_alv_grid,
        t_catalog TYPE lvc_t_fcat,
        w_catalog TYPE lvc_s_fcat,
        l_repid  TYPE sy-repid.


  CASE r_ucomm.


*   When 'hide column' sub-menu is clicked from the context menu
*   then hide the column from where this is happened
    WHEN 'ZFN1'.

*     Get the global instance of the ALV grid as well as
*     it's field catalog info.
      CALL FUNCTION 'GET_GLOBALS_FROM_SLVC_FULLSCR'
        IMPORTING
          e_callback_program = l_repid
          e_grid             = g_grid
          et_fieldcat_lvc    = t_catalog.

      CHECK l_repid = g_repid.

      IF g_grid IS BOUND AND t_catalog[] IS NOT INITIAL.

*       Set the 'NO_OUT' attribute of the catalog to 'X'
        w_catalog-no_out = 'X'.

*       Modify the field with this above value
*       on which right click occured
        MODIFY t_catalog FROM w_catalog TRANSPORTING no_out
            WHERE fieldname = ls_selfield-fieldname.

        IF sy-subrc = 0.

*         Set the field catalog with this modified one
          CALL METHOD g_grid->set_frontend_fieldcatalog
            EXPORTING
              it_fieldcatalog = t_catalog.

        ENDIF.
      ENDIF.
    WHEN OTHERS.

* Do nothing

  ENDCASE.
  ls_selfield-refresh = 'X'.
ENDFORM.                    "USER_COMMAND