Data Definition
For first part of Introduction first and then go on with the below details for a better understanding of concepts.
DATA(ld_erg) = lo_obj->get_data( ). "The first example calls the get_data method of the object lo_obj, which returns a result as the returning parameter.
Passing values to constructor
Now we can pass value while creating the object itself check the line highlighted in yellow.
*&---------------------------------------------------------------------*
*& Report y_class_basics
*&---------------------------------------------------------------------*
*&
*&---------------------------------------------------------------------*
report y_class_basics.
class abap_basics definition.
public section.
data : num type i value '10'.
methods : display,
constructor importing lv_value type i.
private section.
data value_to_constrictor type i. "private data can be accessed within the same class
endclass.
class abap_basics implementation.
method display.
data : num type i value '200'.
write : 'value = ', num.
write : 'value in me = ', me->num.
endmethod.
method constructor.
value_to_constrictor = lv_value. " lv_value holds value 1
endmethod.
endclass.
start-of-selection.
DATA(lo_object) = NEW abap_basics( lv_value = '1' ). "passing parameter which is present in the constructor
lo_object->display( ).
You can convert the data passed to the method to the type that method needs.
DATA(lo_object) = NEW abap_basics( CONV #('1' ) ).
Method Chaining
go_invoice_manager->mt_invoices[ 4 ]-ref->do_payment( ).
Let’s break down the entire chain step by step and look at the individual elements:
- go_invoice_manager – Global reference to an object
- mt_invoices – Public attribute of the reference go_invoice_manager and a table by name
- [ 4 ] – Read the 4th line of the table
- -ref – Access to a field of the 4th line with the name “ref”, which in turn is a reference
- do_payment( ) – Calling the method of the object