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

Call method within a Method in Class Implementation

Former Member
0 Likes
2,785

HI,

I have a method in Class definition which gets triggered on the EVENT AFTER_USER_COMMAND.

I wish to call method (get_filtered_entries) within the above method.

Is that possible. ? I am new to OO programming.

For your refernec I have my code snippets attached.


[code]CLASS lcl_event_receiver DEFINITION .
PUBLIC:
METHODS:
        handle_user_command
            FOR EVENT after_user_command OF cl_gui_alv_grid
                IMPORTING e_ucomm e_not_processed.
ENDCLASS.                    "lcl_event_receiver 

CLASS lcl_event_receiver IMPLEMENTATION.
  METHOD handle_user_command.

*    IF e_not_processed IS INITIAL.

    <b>  CALL METHOD cl_gui_alv_grid->get_filtered_entries                   
      IMPORTING
          et_filtered_entries = lt_entries.</b>

*    ENDIF.
  ENDMETHOD.                           "handle_user_command

ENDCLASS. "lcl_event_receiver IMPLEMENTATION

DATA: g_event_receiver TYPE REF TO lcl_event_receiver,
      g_grid_2000      TYPE REF TO lcl_method_call,
      g_grid_3000      TYPE REF TO lcl_method_call.

INITIALIZATION.
perform check_screen.

START-OF-SELECTION.
perform get_data

[/code]

The program dumps when it tries to call the method get_filtered_entries above.

Can you suggest where I am going wrong.

Regards

RK

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
1,158

Hi Rajiv,

You should call method g_grid_2000->get_filtered_entries. (or g_grid_3000) depending on which grid you are actually using.

Regards,

John.

8 REPLIES 8
Read only

FredericGirod
Active Contributor
0 Likes
1,158

Hi,

we don't see in the code where you have define the cl_gui_alv_grid and where you have create the grid object.

Rgd

Frédéric

Read only

Former Member
0 Likes
1,159

Hi Rajiv,

You should call method g_grid_2000->get_filtered_entries. (or g_grid_3000) depending on which grid you are actually using.

Regards,

John.

Read only

0 Likes
1,158

You are not calling the method correctly. You need to call the method of the instance(object) of the class.



      CALL METHOD <b>grid_0002->get_filtered_entries</b>                   
      IMPORTING
          et_filtered_entries = lt_entries.


or use grid_0003, which ever grid you are working with at the time.

Regards,

RIch Heilman

Read only

0 Likes
1,158

Does this event reciever support both grids, or just one of them?

Regards,

RIch Heilman

Read only

0 Likes
1,158

What is lcl_method_call?

Regards,

Rich Heilman

Read only

0 Likes
1,158

What is g_custom_2000?

CALL METHOD
 <b>g_custom_2000-></b>get_filtered_entries
                   
       IMPORTING
           et_filtered_entries = lt_entries.

the g_grid_2000 object is your alv_grid object since it inherits from cl_Gui_alv_grid. You should be calling the method against that object.

CALL METHOD
 <b>g_grid_2000-></b>get_filtered_entries
                   
       IMPORTING
           et_filtered_entries = lt_entries.

Regards,

Rich Heilman

Read only

Former Member
0 Likes
1,158

Hi All,

Infact I tried to cal the method from my GRID but its showing an syntax error.

I am attaching the code bit again with cl_gui_alv_grid implementation for your reference. Maybe you can tell me whats the mistake I am doing.

> [code]
 [code]CLASS lcl_event_receiver DEFINITION .
 PUBLIC:
 METHODS:
         handle_user_command
 FOR EVENT after_user_command OF
 r_command OF cl_gui_alv_grid
                 IMPORTING e_ucomm e_not_processed.
 ENDCLASS.                    "lcl_event_receiver
 

CLASS lcl_event_receiver IMPLEMENTATION.
   METHOD handle_user_command.
 
 *    IF e_not_processed IS INITIAL.
 
 <b>  CALL METHOD
 g_custom_2000->get_filtered_entries
                   
       IMPORTING
           et_filtered_entries = lt_entries.</b>
 
 *    ENDIF.
 ENDMETHOD.
 D.
 
                          "handle_user_command

ENDCLASS. "lcl_event_receiver

IMPLEMENTATION

DATA: g_event_receiver TYPE REF TO
 lcl_event_receiver,
       g_grid_2000      TYPE REF TO lcl_method_call,
       g_grid_3000      TYPE REF TO lcl_method_call.
CLASS lcl_method_call DEFINITION INHERITING FROM cl_gui_alv_grid.
  PUBLIC SECTION.
    METHODS: get_row EXPORTING row TYPE lvc_s_row.


ENDCLASS.                    "lcl_method_call DEFINITION

*---------------------------------------------------------------------*
*       CLASS lcl_method_cal IMPLEMENTATION
*---------------------------------------------------------------------*
*
*---------------------------------------------------------------------*
CLASS lcl_method_call IMPLEMENTATION.
  METHOD get_row.
    CALL METHOD me->get_current_cell_row_id
      IMPORTING
        row_id = row.
  ENDMETHOD.                    "get_row

ENDCLASS.                    "lcl_method_call IMPLEMENTATION

> INITIALIZATION.

> perform check_screen.

>

> START-OF-SELECTION.

> perform get_data[/code][/code]

Read only

Former Member
0 Likes
1,158

Thanks Jhon and Rich,

I was calling the method from my ALV container and not the GRid as rightly pointed out by you.

The issue is sorted .

Thanks for the help.

Really appreciated

RK