‎2007 Nov 28 8:50 AM
Hi abapers,
In next code of example:
1) Why no defining <b>var</b> variable?
2) Is not necesary?
2) What contain <b>var</b> variable ( is a type c ?)
thanks for your attention.
***********************************************
Class Definition
----
CLASS main DEFINITION
----
CLASS main DEFINITION.
PUBLIC SECTION.
METHODS add_data IMPORTING i_data TYPE i.
METHODS get_data EXPORTING e_data TYPE char20.
PRIVATE SECTION.
DATA atribute TYPE char01.
ENDCLASS.
Class Implementation
----
CLASS main IMPLEMENTATION
----
CLASS main IMPLEMENTATION.
METHOD add_data.
ADD i_data TO atribute.
ENDMETHOD.
METHOD get_data.
CONCATENATE 'Atribute value' atribute
INTO r_data SEPARATED BY space.
ENDMETHOD.
ENDCLASS.
Creation Object
DATA: object_reference TYPE REF TO main.
Instance Creation
CREATE OBJECT object_reference.
Calling Methods
CALL METHOD object_reference->add_data( i_data = 3 ).
<b>var</b> = object_reference->get_data( ).
WRITE <b>var</b>.
The atribute value is printed
" Atribute value 3 "
********************************************************
Cordial greetings
‎2007 Nov 28 2:45 PM
Hi Lopes,
I created this program and i forgot to copy and past the variable definition. But i have just fixed this problem on Wiki page <a href="https://wiki.sdn.sap.com/wiki/display/Snippets/ABAPObjects-CreatingyourFirstLocalClass-DefiningComponents">ABAP Objects - Creating your First Local Class - Defining Components</a>.
<b>You and ALL ABAPers can correct any problem with my examples and/or comments on wiki page <a href="https://wiki.sdn.sap.com/wiki/display/ABAP/ABAP+Objects">ABAP Objects</a>.
My intention is to encourage all ABAP developers to use more the concept of the Abject oriented in ABAP Guidance, and wiki is the best tool in SDN to do it because anyone can contribute.
You can also comment on comment tab in wiki page.</b>
Best Regards and thank you all for helping us with your comments.
Marcelo Ramos
‎2007 Nov 28 9:40 AM
What you have here is pseudocode that looks like ABAP. It isn't ABAP, more a hint to how your program should look.
I've corrected the wiki with syntactically correct code, and definition of VAr.
m@t
Added reference to wiki
Message was edited by:
Matthew Billingham
‎2007 Nov 28 9:55 AM
Hi here you have to declare VAR. Otherwise it should be a global variable. Otherwise the program dont work.
Here is the code..
*Class Definition
----
CLASS main DEFINITION
----
CLASS main DEFINITION.
PUBLIC SECTION.
METHODS add_data IMPORTING i_data TYPE i.
METHODS get_data returning value(e_data) TYPE char20.
PRIVATE SECTION.
DATA atribute TYPE char01.
ENDCLASS.
*Class Implementation
----
CLASS main IMPLEMENTATION
----
CLASS main IMPLEMENTATION.
METHOD add_data.
ADD i_data TO atribute.
ENDMETHOD.
METHOD get_data.
CONCATENATE 'Atribute value' atribute
INTO e_data SEPARATED BY space.
ENDMETHOD.
ENDCLASS.
*Creation Object
DATA: var type char20.
DATA: object_reference TYPE REF TO main.
start-of-selection.
*Instance Creation
CREATE OBJECT object_reference.
*Calling Methods
CALL METHOD object_reference->add_data( i_data = 3 ).
var = object_reference->get_data( ).
WRITE var.
‎2007 Nov 28 2:45 PM
Hi Lopes,
I created this program and i forgot to copy and past the variable definition. But i have just fixed this problem on Wiki page <a href="https://wiki.sdn.sap.com/wiki/display/Snippets/ABAPObjects-CreatingyourFirstLocalClass-DefiningComponents">ABAP Objects - Creating your First Local Class - Defining Components</a>.
<b>You and ALL ABAPers can correct any problem with my examples and/or comments on wiki page <a href="https://wiki.sdn.sap.com/wiki/display/ABAP/ABAP+Objects">ABAP Objects</a>.
My intention is to encourage all ABAP developers to use more the concept of the Abject oriented in ABAP Guidance, and wiki is the best tool in SDN to do it because anyone can contribute.
You can also comment on comment tab in wiki page.</b>
Best Regards and thank you all for helping us with your comments.
Marcelo Ramos