cancel
Showing results for 
Search instead for 
Did you mean: 

call classe methods below in another class code

0 Kudos
269

Hello.
I would like some help on how I can make two classes in code talk to each other, I want to create a Set Handeler of an ALV of a class that is further down in the code.
for exemple, in this code i have ALV in Report but i need set the handle in Control class, there are some on to call the method in below class in code?

 

 

 

 

CLASS cl_report DEFINITION.
  PUBLIC SECTION.
    METHODS: select,
      display.
  PRIVATE SECTION.
    DATA: lt_mara TYPE TABLE OF mara.
ENDCLASS.

CLASS cl_report IMPLEMENTATION.
  METHOD select.
    SELECT *
      FROM mara
      INTO TABLE me->lt_mara.
  ENDMETHOD.

  METHOD display.
    DATA: lo_alv TYPE REF TO cl_salv_table.
    TRY.
        cl_salv_table=>factory(
          IMPORTING
            r_salv_table = lo_alv
          CHANGING
            t_table      = me->lt_mara ).

      CATCH cx_salv_msg.
    ENDTRY.

*       Display ALV, verificando se deve ou não ser Popup.
    IF lo_alv IS BOUND.
*         DEFININ EVENTS
      DATA: o_events TYPE REF TO cl_salv_events_table.
      o_events = lo_alv->get_event( ).
      SET HANDLER cl_control->handler FOR o_events.

      lo_alv->display( ).
    ENDIF.
  ENDMETHOD.

ENDCLASS.


CLASS cl_control DEFINITION.
  PUBLIC SECTION.
    METHODS: constructor,
      init,
      handler FOR EVENT link_click OF cl_salv_events_table.
  PRIVATE SECTION.
    DATA: o_report TYPE REF TO cl_report.
ENDCLASS.

CLASS cl_control IMPLEMENTATION.
  METHOD constructor.
    CREATE OBJECT o_report.
  ENDMETHOD.

  METHOD init.
    o_report->select( ).
    o_report->display( ).
  ENDMETHOD.

  METHOD handler.
    BREAK-POINT.
  ENDMETHOD.
ENDCLASS.

INITIALIZATION.
  DATA: o_cntr TYPE REF TO cl_control.
  CREATE OBJECT o_cntr.
  o_cntr->init( ).

 

 

 

 

 

Ulrich_Schmidt
Product and Topic Expert
Product and Topic Expert
This does not look like a Connectivity question (HTTP or RFC communication). I am adding the "ABAP Development" tag.
Sandra_Rossi
Active Contributor
0 Kudos
Note that your code doesn't compile because you are using CL_CONTROL before declaring it, you are defining a class name before the instance operator (->). Either you refer to the method HANDLER as an instance method, then you must instantiate CL_CONTROL e.g. go_control = NEW cl_control( ), and you can do SET HANDLER go_control->handler, or you define HANDLER as a static method (CLASS-METHODS) and then you can use SET HANDLER cl_control=>handler...

Accepted Solutions (0)

Answers (1)

Answers (1)

raymond_giuseppi
Active Contributor
0 Kudos

Use a CLASS cl_control DEFINITION DEFERRED before using it in the first class.