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

Why no defining variable?

Former Member
0 Likes
544

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

1 ACCEPTED SOLUTION
Read only

marcelo_ramos1
SAP Mentor
SAP Mentor
0 Likes
524

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

3 REPLIES 3
Read only

matt
Active Contributor
0 Likes
524

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

Read only

Former Member
0 Likes
524

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.

Read only

marcelo_ramos1
SAP Mentor
SAP Mentor
0 Likes
525

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