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: 

generic class attribute possible?!

Former Member
0 Kudos

Hi,

I'm realizing an individual class for processing different kinds of data ....

the kind of data (table) should be set via parameter ("datatype") while creating an instance of this object ....

Is there a chance to work with generic class attribute types?!

Edited by: Raabiat on Sep 14, 2010 12:06 PM

1 ACCEPTED SOLUTION

sitakant_tripathy2
Active Participant
0 Kudos

Hi...

Yes you can haave a generic type for it...what you can do is to keep the underlying data type as TYPE REF TO Data and then pass pointers to this data type...

Hope this works...

Regards,

Sitakant

9 REPLIES 9

sitakant_tripathy2
Active Participant
0 Kudos

Hi...

Yes you can haave a generic type for it...what you can do is to keep the underlying data type as TYPE REF TO Data and then pass pointers to this data type...

Hope this works...

Regards,

Sitakant

0 Kudos

Hello Sitakant,

May be i'm wrong but TYPE REF TO DATA is not generic type declaration, it is to create data reference objects.

@OP: You can define interface params using generic types viz. TYPE STANDARD TABLE, TYPE SORTED TABLE etc. Did you try it out before posting in the forum ?

BR,

Suhas

0 Kudos

@Suhas:yes I did but the system expects "any table" instead of "standard table" and when using "any table", the system says "Dataobjects may not be generic" ....

this is why I was opening this Thread

0 Kudos

In terms of generictity and class's attribute I think you should stick to using data reference of type ref to data as already suggested. This way you can store ANY data object reference you want, hence you making this attribute generic . Otherwise you won't be able to type generically data object. It can be done only to parameters and field-symbols (which can be defined only localy in methods).

We can argue about what is really called generic and what in fact is only typed generically . For me generic would state for all the data objects/parameters/field-symbols which type is provided DYNAMICALLY. So all that comes during runtime I would call generic. Therefore as in your case by generic class attribute I am thinking of some generic container which can hold (or point to) variously typed data objects during runtime. This makes data reference perfectly tailored to your case.

Regards

Marcin

0 Kudos

Hi Suhas,

>it is to create data reference objects.

You have the answer in your statement if you want to be sure.....When you create a data reference it can be based on a type that has been identified in the runtime...

CREATE DATA DREF TYPE (variable)

for eample you can consider ALV Framework....

Secondly...If I go by the requirement that was posted...the type ref to data would be generic for the class and the calling program has to decide what would be the type of the data and pass it to the class as pointer to that data object...

Regards,

Sitakant..

Edited by: Sitakant Tripathy on Sep 14, 2010 2:38 PM

0 Kudos

Marcin, thanks a lot for that very helpful answer!

in my mind "generic" means exactly the same as you described!

can you give me a small hint how to work like you described (with type ref to data)

in my class Z_MYCLASS I have to set an attribute "it_mytable" type ref to what?!?!

I dont really knowhow to use your hint ...

thanks!

0 Kudos

@OP

Of course


class Z_MYCLASS definition. 
   public section.
   data r_it_mytable type ref to DATA. "use generic TYPE REF TO DATA 
   methods constructor importing i_tab_type type any.  
endclass.

class Z_MYCLASS implementation.
   method constructor.
      "create a pointer to a table of type passed by parameter
      create data R_IT_MYTABLE type table of (I_TAB_TYPE).
   endmethod.
endclass.

start-of-selection.
   data gr_myclass type ref to z_myclass.
   
   create object gr_myclass exporting 'SFLIGHT'.

@Sitakant

When you create a data reference it can be based on a type that has been identified in the runtime...

CREATE DATA DREF TYPE (variable)

for eample you can consider ALV Framework....

I believe Suhas knows that very well, I think he just meant something different.

All in all we all talk about genericity

Regards

Marcin

0 Kudos

Raabiat,

Many thanks for your apprecation, but I think Sitakant should receive those last points instead of me, as he was the first one who gave the idea of how that should work.

Thanks

Marcin

0 Kudos

si ... think you're right