diff --git a/04_ABAP_Object_Orientation.md b/04_ABAP_Object_Orientation.md index 18c962d..b1c15db 100644 --- a/04_ABAP_Object_Orientation.md +++ b/04_ABAP_Object_Orientation.md @@ -15,6 +15,8 @@ - [Methods](#methods) - [Parameter Interface](#parameter-interface) - [Formal and Actual Parameters](#formal-and-actual-parameters) + - [Complete Typing of Formal Parameters](#complete-typing-of-formal-parameters) + - [Generic Typing of Formal Parameters](#generic-typing-of-formal-parameters) - [Defining Parameters as Optional](#defining-parameters-as-optional) - [Defining Input Parameters as Preferred](#defining-input-parameters-as-preferred) - [Constructors](#constructors) @@ -559,6 +561,386 @@ In the simplest form, methods can have no parameter at all. Apart from that, met - If passing by reference is used, a local data object is not created for the actual parameter. Instead, the procedure is given a [reference](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abenreference_glosry.htm "Glossary Entry") to the actual parameter during the call and works with the actual parameter itself. - Note that parameters that are input and passed by reference cannot be modified in the procedure. However, the use of a reference is beneficial regarding the performance compared to creating a local data object. +The following example shows a class with a simple method demonstrating the syntax for formal paremeter specifications. Complete types are used. + +```abap +CLASS zcl_some_class DEFINITION + PUBLIC + FINAL + CREATE PUBLIC . + + PUBLIC SECTION. + INTERFACES if_oo_adt_classrun. + + "Passing by reference and value + METHODS: meth IMPORTING i_a TYPE i + REFERENCE(i_b) TYPE string + VALUE(i_c) TYPE i + RETURNING VALUE(r_a) TYPE string. + + + PROTECTED SECTION. + PRIVATE SECTION. +ENDCLASS. + + + +CLASS zcl_some_class IMPLEMENTATION. + + METHOD if_oo_adt_classrun~main. + + DATA(result) = meth( i_a = 1 + i_b = `hello` + i_c = 2 ). + + ENDMETHOD. + + METHOD meth. + ... "Method implementation + + "No change for input parameters passed by reference + "i_a += 1. + "i_b &&= ` world`. + + "Input parameters passed by reference can be changed in the method. + i_c += 1. + + ENDMETHOD. + +ENDCLASS. +``` + +
+ +#### Complete Typing of Formal Parameters + +Syntax for [completely](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/index.htm?file=abencomplete_data_type_glosry.htm "Glossary Entry") typing a formal parameter: +- `TYPE complete_type` +- `TYPE LINE OF complete_type` +- `TYPE REF TO type` +- `LIKE dobj` +- `LIKE LINE OF dobj` +- `LIKE REF TO dobj` + +> **💡 Note**