Application Development 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: 

Attributes in OO

Former Member
0 Kudos

Hi,

i read that in Attributes u have do declare global variables ,

in Function group i declare it in Top,but if i have lot of global Variables where i have to put it ? like table types below

DATA: BEGIN OF t_tab OCCURS 0,

root(20) TYPE c,

description(20) TYPE c,

field01(20) TYPE c,

field02(20) TYPE c,

field03(20) TYPE c,

field04(20) TYPE c,

field05(20) TYPE c,

field06(20) TYPE c,

field07(20) TYPE c,

field08(20) TYPE c,

field09(20) TYPE c,

field10(20) TYPE c,

field11(20) TYPE c,

field12(20) TYPE c,

field13(20) TYPE c,

field14(20) TYPE c,

field15(20) TYPE c,

field16(20) TYPE c,

field17(20) TYPE c,

field18(20) TYPE c,

END OF t_tab.

Regards

1 ACCEPTED SOLUTION

uwe_schieferstein
Active Contributor
0 Kudos

Hello Ricardo

With respect to classes you should no longer talk about global / local but in terms of public, protected or private.

All attributes are "global" for an instance of the class but only the public ones are accessible from the outside.

If you are already working on ECC 6.0 you may define a public table type for your itab, e.g.:


TYPES: begin of ty_s_itab,
root(20) TYPE c,
description(20) TYPE c,
field01(20) TYPE c,
field02(20) TYPE c,
field03(20) TYPE c,
field04(20) TYPE c,
field05(20) TYPE c,
field06(20) TYPE c,
field07(20) TYPE c,
field08(20) TYPE c,
field09(20) TYPE c,
field10(20) TYPE c,
field11(20) TYPE c,
field12(20) TYPE c,
field13(20) TYPE c,
field14(20) TYPE c,
field15(20) TYPE c,
field16(20) TYPE c,
field17(20) TYPE c,
field18(20) TYPE c,
END OF ty_s_itab.
TYPES: ty_t_itab        TYPE STANDARD TABLE OF ty_s_itab
                                 WITH GENERIC KEY. 

You may define your public itab attribute as TYPE OF ty_t_itab.

Regards

Uwe

5 REPLIES 5

Former Member
0 Kudos

Hi,

Create a program Z_TOP_DECLARATION of type I (Include), place all the global variables here and you can call in any program with the statement

INCLUDE Z_top_declaration.

Regards,

Subramanina

0 Kudos

Hi Subramanian,

if so, what i have to declare in Attributes?

Regards

0 Kudos

Type of the program will be "INCLUDE program"

Former Member
0 Kudos

Hi Ricardo,

In classes "attributes" are similar to "variables" in a program.

In a program variable has 2 scope

1.Local

2.Global.

If the Variable is defined in the program (what is called local), it can be accessed within the program and not outside.

If the Varibale is defined in the top (what is called global), it can is used in different programs that includes this top.

Additionally, there is TYPES keyword which is used to define the definition of the structure/table that can be used in the program. Similarly, the TYPE can exists in the program or in the top depending on the scope local or global.

Similarly, you can define attributes of the class. The scope of the variable here is

1. Private ---> Can be accessed fron the class and not from outside.

2. Protected -


> Can be accessed from the class and its child classes but not from outside

3. Public -


> Can be accessed from the class and also from outside the class.

There is an additional scope:

1. Instance ---> If the attribute is instance specific, you will the object of the class to access it.

2. Static -


> If you want a variable at class level (common to all objects) then you define them as static. Here you do not need the object of the class but the class name is sufficient.

Additionally, you have the TYPES tab, where you can define types that can be used within the class. This is a global type definitation for the class attribute and all its method.

I hope this clarifies your question.

Regards,

Saurabh

uwe_schieferstein
Active Contributor
0 Kudos

Hello Ricardo

With respect to classes you should no longer talk about global / local but in terms of public, protected or private.

All attributes are "global" for an instance of the class but only the public ones are accessible from the outside.

If you are already working on ECC 6.0 you may define a public table type for your itab, e.g.:


TYPES: begin of ty_s_itab,
root(20) TYPE c,
description(20) TYPE c,
field01(20) TYPE c,
field02(20) TYPE c,
field03(20) TYPE c,
field04(20) TYPE c,
field05(20) TYPE c,
field06(20) TYPE c,
field07(20) TYPE c,
field08(20) TYPE c,
field09(20) TYPE c,
field10(20) TYPE c,
field11(20) TYPE c,
field12(20) TYPE c,
field13(20) TYPE c,
field14(20) TYPE c,
field15(20) TYPE c,
field16(20) TYPE c,
field17(20) TYPE c,
field18(20) TYPE c,
END OF ty_s_itab.
TYPES: ty_t_itab        TYPE STANDARD TABLE OF ty_s_itab
                                 WITH GENERIC KEY. 

You may define your public itab attribute as TYPE OF ty_t_itab.

Regards

Uwe