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

Importing object parameter to method

Former Member
0 Likes
1,354

Hi Abapers,

    i was practicing local interface in report i got sample code from Zevolving, please look the code once ( ABAP Objects - Achieve Multiple Inheritance using Interfaces ).

    if we said importing parameter is character it should accept only character type, same like that if we declared the importing parameter is TYPE REF TO lif_data it should accept only the object which is reference of lif_data, am i right ???.

Here the piece of sample code(  Here_Complete_Code )

CLASS lcl_main DEFINITION.

  PUBLIC SECTION.

   CLASS-METHODS: select_Data IMPORTING io_Data TYPE REF TO lif_data,

  write_Data  IMPORTING io_output TYPE REF TO lif_output.

ENDCLASS.

START-OF-SELECTION.

  DATA: lo_report TYPE REF TO lcl_summary.

  CREATE OBJECT lo_report.

  lcl_main=>select_Data( lo_report ).

  lcl_main=>write_Data( lo_report ).

i'm wondering how select_data and write_data method support input lo_report object !  lo_report is the reference of lcl_summary class which contain interface lif_data and lif_output, as far i know the formal parameter should not support objects other than lif_data or lif_output reference.

it seem code does not any issue,can you explain me how it is working without error?

Thanks & Regards,

Lokesh Srinivasan.

2 REPLIES 2
Read only

hubert_heitzer
Contributor
0 Likes
942

Everything is fine!

When LCL_SUMMARY implements LIF_DATA and LIF_OUTPUT, every object of type LCL_SUMMARY also ownes type LIF_DATA and LIF_OUTPUT.

In your example implementation of LCL_MAIN=>SELECT_DATA only works with the LIF_DATA-part of lo_report. Same for LCL_SUMMARY=>WRITE_DATA.

Regards,

Hubert

Read only

0 Likes
942

To add some more to this: If your parameter is TYPE REF TO some_interface, it accepts any object implementing that interface. It does not care about what or how many other interfaces the class implements.

Implementing several interfaces in one class is not what typically is called multiple inheritance, as the linked article suggests. There are many reasons to implement several interfaces in a class. Maybe have a look at the interface segregation principle.

kind regards,

Thomas