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

OOPs event before_user_command

Former Member
0 Likes
1,150

Hi all,

I was trying to use before_user_command event, it is giving dump in the following program. It is giving dump as follows

In 'SET HANDLER ... FOR src', the reference to the trigger 'GR_ALVGRID' may not be 'NULL'.

please help me.

&----


*& Report Y_SIMPLE_USER_COMMAND_EVENTS

*&

&----


*&

*&

&----


REPORT y_simple_user_command_events.

TABLES kna1.

DATA : gr_alvgrid TYPE REF TO cl_gui_alv_grid,

container_name TYPE scrfname VALUE 'ALV_CONTAINER',

gr_container TYPE REF TO cl_gui_custom_container.

DATA BEGIN OF itab OCCURS 0.

INCLUDE STRUCTURE kna1.

DATA END OF itab.

DATA fieldcat TYPE lvc_t_fcat.

CLASS lcl_events_d0100 DEFINITION DEFERRED.

DATA gr_events_d0100 TYPE REF TO lcl_events_d0100.

----


  • CLASS lcl_events_d0100 DEFINITION

----


*

----


CLASS lcl_events_d0100 DEFINITION.

PUBLIC SECTION.

METHODS:

  • before_user_command FOR EVENT before_user_command

  • OF cl_gui_alv_grid IMPORTING e_ucomm.

before_user_command FOR EVENT before_user_command

OF cl_gui_alv_grid

IMPORTING e_ucomm.

ENDCLASS. "lcl_events_d0100 DEFINITION

----


  • CLASS lcl_events_d0100 IMPLEMENTATION

----


*

----


CLASS lcl_events_d0100 IMPLEMENTATION.

  • METHOD before_user_command.

  • PERFORM user_command_event USING e_ucomm.

  • ENDMETHOD. "user_command

METHOD before_user_command.

PERFORM d0100_event_before_ucomm USING e_ucomm.

ENDMETHOD. "before_user_command

ENDCLASS. "lcl_events_d0100 IMPLEMENTATION

START-OF-SELECTION.

CALL SCREEN 100.

&----


*& Module pf_status OUTPUT

&----


  • text

----


MODULE pf_status OUTPUT.

SET PF-STATUS 'ZTEST'.

SET TITLEBAR 'ZTITLE'.

ENDMODULE. " pf_status OUTPUT

&----


*& Module exit_prog INPUT

&----


  • text

----


MODULE exit_prog INPUT.

CASE sy-ucomm.

WHEN 'EXIT' OR 'CANC' OR 'BACK'.

LEAVE PROGRAM.

ENDCASE.

ENDMODULE. " exit_prog INPUT

&----


*& Module collect_data OUTPUT

&----


  • text

----


MODULE collect_data OUTPUT.

PERFORM display_data TABLES itab.

SKIP.

ENDMODULE. " collect_data OUTPUT

&----


*& Form display_data

&----


  • text

----


  • -->P_ITAB text

----


FORM display_data TABLES p_itab STRUCTURE itab.

SELECT * FROM kna1 INTO CORRESPONDING FIELDS OF TABLE p_itab.

ENDFORM. " display_data

&----


*& Module display_alv OUTPUT

&----


  • text

----


MODULE display_alv OUTPUT.

PERFORM prepare_fieldcatalog CHANGING fieldcat.

IF gr_container IS INITIAL.

CREATE OBJECT gr_container

EXPORTING

  • PARENT =

container_name = container_name

  • STYLE =

  • LIFETIME = lifetime_default

  • REPID =

  • DYNNR =

  • NO_AUTODEF_PROGID_DYNNR =

  • EXCEPTIONS

  • CNTL_ERROR = 1

  • CNTL_SYSTEM_ERROR = 2

  • CREATE_ERROR = 3

  • LIFETIME_ERROR = 4

  • LIFETIME_DYNPRO_DYNPRO_LINK = 5

  • 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 gr_alvgrid

EXPORTING

  • I_SHELLSTYLE = 0

  • I_LIFETIME =

i_parent = gr_container

  • I_APPL_EVENTS = space

  • I_PARENTDBG =

  • I_APPLOGPARENT =

  • I_GRAPHICSPARENT =

  • I_NAME =

  • I_FCAT_COMPLETE = SPACE

  • 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

  • WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.

ENDIF.

CALL METHOD gr_alvgrid->set_table_for_first_display

EXPORTING

  • I_BUFFER_ACTIVE =

  • I_BYPASSING_BUFFER =

  • I_CONSISTENCY_CHECK =

i_structure_name = 'ITAB'

  • IS_VARIANT =

  • I_SAVE =

  • I_DEFAULT = 'X'

  • IS_LAYOUT =

  • IS_PRINT =

  • IT_SPECIAL_GROUPS =

  • IT_TOOLBAR_EXCLUDING =

  • IT_HYPERLINK =

  • IT_ALV_GRAPHICS =

  • IT_EXCEPT_QINFO =

  • IR_SALV_ADAPTER =

CHANGING

it_outtab = itab[]

it_fieldcatalog = fieldcat[]

  • IT_SORT =

  • IT_FILTER =

  • 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.

ENDIF.

ENDMODULE. " display_alv OUTPUT

&----


*& Form PREPARE_FIELDCATALOG

&----


  • text

----


  • <--P_FIELDCAT text

----


FORM prepare_fieldcatalog CHANGING p_fieldcat.

  • DATA w_fcat TYPE lvc_s_fcat.

*

  • w_fcat-fieldname = 'KUNNR'.

  • w_fcat-ref_table = 'KNA1'.

  • w_fcat-outputlen = '10'.

  • w_fcat-inttype = 'C'.

  • w_fcat-seltext = 'Cust No'.

CALL FUNCTION 'LVC_FIELDCATALOG_MERGE'

EXPORTING

  • I_BUFFER_ACTIVE =

i_structure_name = 'KNA1'

  • I_CLIENT_NEVER_DISPLAY = 'X'

  • I_BYPASSING_BUFFER =

  • I_INTERNAL_TABNAME =

CHANGING

ct_fieldcat = fieldcat[]

  • 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.

ENDFORM. " PREPARE_FIELDCATALOG

&----


*& Form user_command_event

&----


  • text

----


  • -->P_E_UCOMM text

----


FORM user_command_event USING p_e_ucomm.

SKIP.

ENDFORM. " user_command_event

&----


*& Module events_handles OUTPUT

&----


  • text

----


MODULE events_handles OUTPUT.

CREATE OBJECT gr_events_d0100.

SET HANDLER gr_events_d0100->before_user_command

FOR gr_alvgrid.

ENDMODULE. " events_handles OUTPUT

FORM d0100_event_before_ucomm USING e_ucomm TYPE sy-ucomm. "#EC *

DATA: l_event TYPE lvc_fname. "#EC NEEDED

  • IF gs_test-info_popup_once EQ con_true.

  • READ TABLE gs_test-events_info_popup INTO l_event

  • WITH KEY table_line = 'BEFORE_USER_COMMAND'.

  • IF sy-subrc NE 0.

  • INSERT 'BEFORE_USER_COMMAND' INTO gs_test-events_info_popup

  • INDEX 1.

  • MESSAGE i000(0k) WITH text-004 e_ucomm.

  • ENDIF.

  • ELSEIF gs_test-no_info_popup EQ space.

MESSAGE i000(0k) WITH text-004 e_ucomm.

  • ENDIF.

*

  • PERFORM d0100_get_grid_infos.

ENDFORM. " d0100_event_before_ucomm

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
724

Try calling the SET HANDLER statement soon after the ALV Grid has been displayed.

Let me know if you still face the issue.

Or Check out this code.




DATA: r_alvgrid TYPE REF TO cl_gui_alv_grid,
      c_grid_name TYPE scrfname VALUE 'C_GRID',
      i_container TYPE REF TO cl_gui_custom_container.

CLASS lcl_event_handler DEFINITION .
PUBLIC SECTION .
METHODS:
"*To implement user commands
handle_user_command
  FOR EVENT user_command OF cl_gui_alv_grid
            IMPORTING e_ucomm,

handle_before_user_command
  FOR EVENT before_user_command OF cl_gui_alv_grid
            IMPORTING e_ucomm.
ENDCLASS.

CLASS lcl_event_handler IMPLEMENTATION .

"* Handle Before User Command
  METHOD handle_before_user_command.
    case e_ucomm.
      when cl_gui_alv_grid=>mc_fc_refresh.
        call method r_alvgrid->set_user_command
              exporting i_ucomm = 'ZREF'.
    endcase.
  ENDMETHOD.

"* Handle User Command
  METHOD handle_user_command.
    CASE e_ucomm.
      WHEN 'ZREF'.
	<<Fetch data again from DB>>
"* Refresh list with latest data
CALL METHOD r_alvgrid->refresh_table_display
      EXCEPTIONS
        finished       = 1
        OTHERS         = 2.

    ENDCASE.
  ENDMETHOD.
ENDCLASS.



START-OF-SELECTION.
  <<Fetch data from DB>>
  <<Populate Field catalog>>

  CALL SCREEN 9000.

"*** PBO of 9000 screen.

MODULE status_9000 OUTPUT.

  SET PF-STATUS 'STATUS1'.
  SET TITLEBAR '100' WITH cnt.

  IF r_alvgrid IS INITIAL.
"* Create custom container instance
    CREATE OBJECT i_container
      EXPORTING
        container_name = c_grid_name.
    IF sy-subrc = 0.
"* Create ALV grid instance
      CREATE OBJECT r_alvgrid
        EXPORTING
          i_parent = i_container.
      IF sy-subrc = 0.
"* Initial display
        CALL METHOD r_alvgrid->set_table_for_first_display
           EXPORTING
            is_variant                    = s_variant
            i_save                        = 'A'
            is_layout                     = s_layout
            it_toolbar_excluding          = t_exclude[]
          CHANGING
            it_outtab                     = itab[]
            it_fieldcatalog               = t_fieldcat[]
          EXCEPTIONS
            invalid_parameter_combination = 1
            program_error                 = 2
            too_many_lines                = 3
            OTHERS                        = 4.
        CALL METHOD r_alvgrid->register_edit_event
          EXPORTING
            i_event_id = cl_gui_alv_grid=>mc_evt_modified.
"* Raise event TOOLBAR:
        CALL METHOD r_alvgrid->set_toolbar_interactive.
      ENDIF.
    ENDIF.
  ELSE.
"* Refresh display
    CALL METHOD r_alvgrid->refresh_table_display
      EXCEPTIONS
        finished       = 1
        OTHERS         = 2.
  ENDIF.

DATA gr_event_handler TYPE REF TO lcl_event_handler .

"*--Creating an instance for the event handler
CREATE OBJECT gr_event_handler .

"*--Registering handler methods to handle ALV Grid events
SET HANDLER gr_event_handler->handle_user_command FOR r_alvgrid .
SET handler gr_event_handler->handle_before_user_command for r_alvgrid.


ENDMODULE.                 " STATUS_9000  OUTPUT

Hope this helps.

Thanks & Regards,

Balaji

1 REPLY 1
Read only

Former Member
0 Likes
725

Try calling the SET HANDLER statement soon after the ALV Grid has been displayed.

Let me know if you still face the issue.

Or Check out this code.




DATA: r_alvgrid TYPE REF TO cl_gui_alv_grid,
      c_grid_name TYPE scrfname VALUE 'C_GRID',
      i_container TYPE REF TO cl_gui_custom_container.

CLASS lcl_event_handler DEFINITION .
PUBLIC SECTION .
METHODS:
"*To implement user commands
handle_user_command
  FOR EVENT user_command OF cl_gui_alv_grid
            IMPORTING e_ucomm,

handle_before_user_command
  FOR EVENT before_user_command OF cl_gui_alv_grid
            IMPORTING e_ucomm.
ENDCLASS.

CLASS lcl_event_handler IMPLEMENTATION .

"* Handle Before User Command
  METHOD handle_before_user_command.
    case e_ucomm.
      when cl_gui_alv_grid=>mc_fc_refresh.
        call method r_alvgrid->set_user_command
              exporting i_ucomm = 'ZREF'.
    endcase.
  ENDMETHOD.

"* Handle User Command
  METHOD handle_user_command.
    CASE e_ucomm.
      WHEN 'ZREF'.
	<<Fetch data again from DB>>
"* Refresh list with latest data
CALL METHOD r_alvgrid->refresh_table_display
      EXCEPTIONS
        finished       = 1
        OTHERS         = 2.

    ENDCASE.
  ENDMETHOD.
ENDCLASS.



START-OF-SELECTION.
  <<Fetch data from DB>>
  <<Populate Field catalog>>

  CALL SCREEN 9000.

"*** PBO of 9000 screen.

MODULE status_9000 OUTPUT.

  SET PF-STATUS 'STATUS1'.
  SET TITLEBAR '100' WITH cnt.

  IF r_alvgrid IS INITIAL.
"* Create custom container instance
    CREATE OBJECT i_container
      EXPORTING
        container_name = c_grid_name.
    IF sy-subrc = 0.
"* Create ALV grid instance
      CREATE OBJECT r_alvgrid
        EXPORTING
          i_parent = i_container.
      IF sy-subrc = 0.
"* Initial display
        CALL METHOD r_alvgrid->set_table_for_first_display
           EXPORTING
            is_variant                    = s_variant
            i_save                        = 'A'
            is_layout                     = s_layout
            it_toolbar_excluding          = t_exclude[]
          CHANGING
            it_outtab                     = itab[]
            it_fieldcatalog               = t_fieldcat[]
          EXCEPTIONS
            invalid_parameter_combination = 1
            program_error                 = 2
            too_many_lines                = 3
            OTHERS                        = 4.
        CALL METHOD r_alvgrid->register_edit_event
          EXPORTING
            i_event_id = cl_gui_alv_grid=>mc_evt_modified.
"* Raise event TOOLBAR:
        CALL METHOD r_alvgrid->set_toolbar_interactive.
      ENDIF.
    ENDIF.
  ELSE.
"* Refresh display
    CALL METHOD r_alvgrid->refresh_table_display
      EXCEPTIONS
        finished       = 1
        OTHERS         = 2.
  ENDIF.

DATA gr_event_handler TYPE REF TO lcl_event_handler .

"*--Creating an instance for the event handler
CREATE OBJECT gr_event_handler .

"*--Registering handler methods to handle ALV Grid events
SET HANDLER gr_event_handler->handle_user_command FOR r_alvgrid .
SET handler gr_event_handler->handle_before_user_command for r_alvgrid.


ENDMODULE.                 " STATUS_9000  OUTPUT

Hope this helps.

Thanks & Regards,

Balaji