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

alv oops concept

Former Member
0 Likes
790

Hi,

I have one query regarding OO alv.

My requirement is like is that

In output whenever I click on sales order no the control will moves to VA01 tcode.

Could anybody pls send me the coding for this.

I am totally new in OO ALV. I just wrote all the logic for my output. I wanted to know the logic when I double click on any row of sales order no.

Hi,

I have one query regarding OO alv.

My requirement is like is that

In output whenever I click on sales order no the control will moves to VA01 tcode.

Could anybody pls send me the coding for this.

I am totally new in OO ALV. I just wrote all the logic for my output. I wanted to know the logic when I double click on any row of sales order no.

3 REPLIES 3
Read only

uwe_schieferstein
Active Contributor
0 Likes
502

Hello Neha

The following sample report ZUS_SDN_ALVGRID_EVENTS shows how to call a transaction when event HOTSPOT_CLICK was raised:

*&---------------------------------------------------------------------*
*& Report  ZUS_SDN_TWO_ALV_GRIDS
*&
*&---------------------------------------------------------------------*
*&
*&
*&---------------------------------------------------------------------*

REPORT  ZUS_SDN_ALVGRID_EVENTS.



DATA:
  gd_okcode        TYPE ui_func,
*
  gt_fcat          TYPE lvc_t_fcat,
  go_docking       TYPE REF TO cl_gui_docking_container,
  go_grid1         TYPE REF TO cl_gui_alv_grid.


DATA:
  gt_knb1          TYPE STANDARD TABLE OF knb1.


PARAMETERS:
  p_bukrs      TYPE bukrs  DEFAULT '1000'  OBLIGATORY.



*---------------------------------------------------------------------*
*       CLASS lcl_eventhandler DEFINITION
*---------------------------------------------------------------------*
*
*---------------------------------------------------------------------*
CLASS lcl_eventhandler DEFINITION.
  PUBLIC SECTION.

    CLASS-METHODS:
      handle_hotspot_click FOR EVENT hotspot_click OF cl_gui_alv_grid
        IMPORTING
          e_row_id
          e_column_id
          es_row_no
          sender.

ENDCLASS.                    "lcl_eventhandler DEFINITION


*---------------------------------------------------------------------*
*       CLASS lcl_eventhandler IMPLEMENTATION
*---------------------------------------------------------------------*
*
*---------------------------------------------------------------------*
CLASS lcl_eventhandler IMPLEMENTATION.

  METHOD handle_hotspot_click.
*   define local data
    DATA:
      ls_knb1     TYPE knb1,
      ls_col_id   type lvc_s_col.

    READ TABLE gt_knb1 INTO ls_knb1 INDEX e_row_id-index.
    CHECK ( ls_knb1-kunnr IS NOT INITIAL ).

    SET PARAMETER ID 'KUN' FIELD ls_knb1-kunnr.
    SET PARAMETER ID 'BUK' FIELD ls_knb1-bukrs.

    CALL TRANSACTION 'XD03' AND SKIP FIRST SCREEN.


*   Set active cell to field BUKRS otherwise the focus is still on
*   field KUNNR which will always raise event HOTSPOT_CLICK
    ls_col_id-fieldname = 'BUKRS'.
    CALL METHOD go_grid1->set_current_cell_via_id
      EXPORTING
        IS_ROW_ID    = e_row_id
        IS_COLUMN_ID = ls_col_id.



  ENDMETHOD.                    "handle_hotspot_click

ENDCLASS.                    "lcl_eventhandler IMPLEMENTATION


START-OF-SELECTION.

  SELECT        * FROM  knb1 INTO TABLE gt_knb1
         WHERE  bukrs  = p_bukrs.



* Create docking container
  CREATE OBJECT go_docking
    EXPORTING
      parent                      = cl_gui_container=>screen0
      ratio                       = 90
    EXCEPTIONS
      OTHERS                      = 6.
  IF sy-subrc <> 0.
*   MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
*              WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
  ENDIF.


* Create ALV grid
  CREATE OBJECT go_grid1
    EXPORTING
      i_parent          = go_docking
    EXCEPTIONS
      OTHERS            = 5.
  IF sy-subrc <> 0.
*   MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
*              WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
  ENDIF.

* Set event handler
  SET HANDLER:
    lcl_eventhandler=>handle_hotspot_click FOR go_grid1.


* Build fieldcatalog and set hotspot for field KUNNR
  PERFORM build_fieldcatalog_knb1.



* Display data
  CALL METHOD go_grid1->set_table_for_first_display
    CHANGING
      it_outtab       = gt_knb1
      it_fieldcatalog = gt_fcat
    EXCEPTIONS
      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.




* Link the docking container to the target dynpro
  CALL METHOD go_docking->link
    EXPORTING
      repid                       = syst-repid
      dynnr                       = '0100'
*      CONTAINER                   =
    EXCEPTIONS
      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.


* ok-code field = GD_OKCODE
  CALL SCREEN '0100'.


END-OF-SELECTION.

*&---------------------------------------------------------------------*
*&      Module  STATUS_0100  OUTPUT
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
MODULE status_0100 OUTPUT.
  SET PF-STATUS 'STATUS_0100'.
*  SET TITLEBAR 'xxx'.


ENDMODULE.                 " STATUS_0100  OUTPUT

*&---------------------------------------------------------------------*
*&      Module  USER_COMMAND_0100  INPUT
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
MODULE user_command_0100 INPUT.

  CASE gd_okcode.
    WHEN 'BACK' OR
         'END'  OR
         'CANC'.
      SET SCREEN 0. LEAVE SCREEN.


    WHEN OTHERS.
  ENDCASE.

  CLEAR: gd_okcode.

ENDMODULE.                 " USER_COMMAND_0100  INPUT


*&---------------------------------------------------------------------*
*&      Form  BUILD_FIELDCATALOG_KNB1
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM build_fieldcatalog_knb1 .
* define local data
  DATA:
    ls_fcat        TYPE lvc_s_fcat.

  CALL FUNCTION 'LVC_FIELDCATALOG_MERGE'
    EXPORTING
*     I_BUFFER_ACTIVE              =
      i_structure_name             = 'KNB1'
*     I_CLIENT_NEVER_DISPLAY       = 'X'
*     I_BYPASSING_BUFFER           =
*     I_INTERNAL_TABNAME           =
    CHANGING
      ct_fieldcat                  = gt_fcat
    EXCEPTIONS
      inconsistent_interface       = 1
      program_error                = 2
      OTHERS                       = 3.
  IF sy-subrc <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
*         WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
  ENDIF.

  READ TABLE gt_fcat INTO ls_fcat
       WITH KEY fieldname = 'KUNNR'.
  IF ( syst-subrc = 0 ).
    ls_fcat-hotspot = abap_true.
    MODIFY gt_fcat FROM ls_fcat INDEX syst-tabix.
  ENDIF.


ENDFORM.                    " BUILD_FIELDCATALOG_KNB1

Please note that the direct CALL TRANSACTION does not check the user's authority. To do so you could call the transaction using function module <b>ABAP4_CALL_TRANSACTION</b>.

Regards

Uwe

Read only

uwe_schieferstein
Active Contributor
0 Likes
502

Hello Neha

The sample report <b>ZUS_SDN_ALVGRID_EVENTS_1</b> shows how to handle event <b>DOUBLE_CLICK</b>. Of course you can call your required transaction with the event handler method.

*&---------------------------------------------------------------------*
*& Report  ZUS_SDN_TWO_ALV_GRIDS
*&
*&---------------------------------------------------------------------*
*&
*&
*&---------------------------------------------------------------------*

REPORT  zus_sdn_alvgrid_events_1.



DATA:
  gd_okcode        TYPE ui_func,
*
  gt_fcat          TYPE lvc_t_fcat,
  go_docking       TYPE REF TO cl_gui_docking_container,
  go_docking2      TYPE REF TO cl_gui_docking_container,
  go_grid1         TYPE REF TO cl_gui_alv_grid,
  go_grid2         TYPE REF TO cl_gui_alv_grid.


DATA:
  gt_t001          TYPE STANDARD TABLE OF t001,
  gt_knb1          TYPE STANDARD TABLE OF knb1.




*---------------------------------------------------------------------*
*       CLASS lcl_eventhandler DEFINITION
*---------------------------------------------------------------------*
*
*---------------------------------------------------------------------*
CLASS lcl_eventhandler DEFINITION.
  PUBLIC SECTION.

    CLASS-METHODS:
      handle_double_click FOR EVENT double_click OF cl_gui_alv_grid
        IMPORTING
          e_row
          e_column
          es_row_no
          sender.

ENDCLASS.                    "lcl_eventhandler DEFINITION


*---------------------------------------------------------------------*
*       CLASS lcl_eventhandler IMPLEMENTATION
*---------------------------------------------------------------------*
*
*---------------------------------------------------------------------*
CLASS lcl_eventhandler IMPLEMENTATION.

  METHOD handle_double_click.
*   define local data
    DATA:
      ls_t001     TYPE t001,
      ls_col_id   TYPE lvc_s_col.


    CHECK ( sender = go_grid1 ).


    READ TABLE gt_t001 INTO ls_t001 INDEX e_row-index.
    CHECK ( ls_t001-bukrs IS NOT INITIAL ).

    SELECT * FROM knb1 INTO TABLE gt_knb1
      WHERE bukrs = ls_t001-bukrs.
    IF ( syst-subrc NE 0 ).
      MESSAGE 'No customers found' TYPE 'S'.

    ELSE.
*     Trigger PAI of dynpro '0100' and set new ok-code
      CALL METHOD cl_gui_cfw=>set_new_ok_code( 'CALL_SCREEN_0200' ).
    ENDIF.


  ENDMETHOD.                    "handle_hotspot_click

ENDCLASS.                    "lcl_eventhandler IMPLEMENTATION




START-OF-SELECTION.

  SELECT * FROM t001 INTO TABLE gt_t001.
  REFRESH: gt_knb1.



* Create docking container
  CREATE OBJECT go_docking
    EXPORTING
      parent                      = cl_gui_container=>screen0
      ratio                       = 90
    EXCEPTIONS
      OTHERS                      = 6.
  IF sy-subrc <> 0.
*   MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
*              WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
  ENDIF.
  CREATE OBJECT go_docking2
    EXPORTING
      parent                      = cl_gui_container=>screen0
      ratio                       = 90
    EXCEPTIONS
      OTHERS                      = 6.
  IF sy-subrc <> 0.
*   MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
*              WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
  ENDIF.


* Create ALV grid
  CREATE OBJECT go_grid1
    EXPORTING
      i_parent          = go_docking
    EXCEPTIONS
      OTHERS            = 5.
  IF sy-subrc <> 0.
*   MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
*              WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
  ENDIF.
  CREATE OBJECT go_grid2
    EXPORTING
      i_parent          = go_docking2
    EXCEPTIONS
      OTHERS            = 5.
  IF sy-subrc <> 0.
*   MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
*              WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
  ENDIF.


* Set event handler
  SET HANDLER:
    lcl_eventhandler=>handle_double_click FOR go_grid1.






* Display data
  CALL METHOD go_grid1->set_table_for_first_display
    EXPORTING
      i_structure_name = 'T001'
    CHANGING
      it_outtab        = gt_t001
    EXCEPTIONS
      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.

  CALL METHOD go_grid2->set_table_for_first_display
    EXPORTING
      i_structure_name = 'KNB1'
    CHANGING
      it_outtab        = gt_knb1
    EXCEPTIONS
      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.



* Link the docking container to the target dynpro
  CALL METHOD go_docking->link
    EXPORTING
      repid                       = syst-repid
      dynnr                       = '0100'
*      CONTAINER                   =
    EXCEPTIONS
      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.

  CALL METHOD go_docking2->link
    EXPORTING
      repid                       = syst-repid
      dynnr                       = '0200'
*      CONTAINER                   =
    EXCEPTIONS
      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.


* ok-code field = GD_OKCODE
  CALL SCREEN '0100'.


END-OF-SELECTION.

*&---------------------------------------------------------------------*
*&      Module  STATUS_0100  OUTPUT
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
MODULE status_0100 OUTPUT.
  SET PF-STATUS 'STATUS_0100'.
*  SET TITLEBAR 'xxx'.


ENDMODULE.                 " STATUS_0100  OUTPUT

*&---------------------------------------------------------------------*
*&      Module  USER_COMMAND_0100  INPUT
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
MODULE user_command_0100 INPUT.

  CASE gd_okcode.
    WHEN 'BACK' OR
         'END'  OR
         'CANC'.
      SET SCREEN 0. LEAVE SCREEN.

    WHEN 'CALL_SCREEN_0200'.
      go_grid2->refresh_table_display( ).  " necessary

      CALL SCREEN '0200'.


    WHEN OTHERS.
  ENDCASE.

  CLEAR: gd_okcode.

ENDMODULE.                 " USER_COMMAND_0100  INPUT

Regards

Uwe

Read only

raja_thangamani
Active Contributor