‎2008 Feb 22 2:38 PM
Hi.
I want to pass the Standard and Hashed Table to Methods of CLass.
Can anyone please provide a code snippet ?
Currently it only has string as passed by value
My Class code is :
class ZCL_SHM definition
public
final
create public .
public section.
data STRING_ATTR type STRING .
Theses Statements does not work :
data z_Table type any table.
data z_Table type Hashed Table.
‎2008 Feb 22 2:41 PM
Please look at this example.
CLASS: c_biker DEFINITION DEFERRED,
c_bicycle DEFINITION DEFERRED.
*-----------------------------------------------------------------------
CLASS c_team DEFINITION.
PUBLIC SECTION.
TYPES: biker_ref TYPE REF TO c_biker,
biker_ref_tab TYPE STANDARD TABLE OF biker_ref
WITH DEFAULT KEY,
BEGIN OF status_line_type,
flag(1) TYPE c,
text1(5) TYPE c,
id TYPE i,
text2(7) TYPE c,
text3(6) TYPE c,
gear TYPE i,
text4(7) TYPE c,
speed TYPE i,
END OF status_line_type.
CLASS-METHODS: class_constructor.
METHODS: constructor,
create_team,
selection,
execution.
PRIVATE SECTION.
CLASS-DATA: team_members TYPE i,
counter TYPE i.
DATA: id TYPE i,
status_line TYPE status_line_type,
status_list TYPE SORTED TABLE OF status_line_type
WITH UNIQUE KEY id,
biker_tab TYPE biker_ref_tab,
biker_selection LIKE biker_tab,
biker LIKE LINE OF biker_tab.
METHODS: write_list.
ENDCLASS.
Edited by: Naren Someneni on Feb 22, 2008 8:43 AM
‎2008 Feb 22 2:41 PM
Please look at this example.
CLASS: c_biker DEFINITION DEFERRED,
c_bicycle DEFINITION DEFERRED.
*-----------------------------------------------------------------------
CLASS c_team DEFINITION.
PUBLIC SECTION.
TYPES: biker_ref TYPE REF TO c_biker,
biker_ref_tab TYPE STANDARD TABLE OF biker_ref
WITH DEFAULT KEY,
BEGIN OF status_line_type,
flag(1) TYPE c,
text1(5) TYPE c,
id TYPE i,
text2(7) TYPE c,
text3(6) TYPE c,
gear TYPE i,
text4(7) TYPE c,
speed TYPE i,
END OF status_line_type.
CLASS-METHODS: class_constructor.
METHODS: constructor,
create_team,
selection,
execution.
PRIVATE SECTION.
CLASS-DATA: team_members TYPE i,
counter TYPE i.
DATA: id TYPE i,
status_line TYPE status_line_type,
status_list TYPE SORTED TABLE OF status_line_type
WITH UNIQUE KEY id,
biker_tab TYPE biker_ref_tab,
biker_selection LIKE biker_tab,
biker LIKE LINE OF biker_tab.
METHODS: write_list.
ENDCLASS.
Edited by: Naren Someneni on Feb 22, 2008 8:43 AM
‎2008 Feb 22 2:47 PM
i wan to define a table so that i can store that in the public attribute by calling method and passing table to it .
????
‎2008 Feb 22 3:02 PM
If I understood you correctly, you want to declare a table in public section and want to populate it in a method of that class?
‎2008 Feb 22 3:04 PM
yes. because other programs will send the table to the method of that class as a parameter and then this method will update its instance of table type that is declared in class definition.
‎2008 Feb 22 3:14 PM
You can't use generic types in the way you want to. But there's a way round - pass references. So in your class, you want an attribute to be a table that can be any kind of table and any structure. What you do is instead have a class attribute my_table_ref TYPE REF TO DATA.
Now you need to work out how to set the class attribute my_table_ref. One way is to use a setter method, like SET_TABLE_REF, which has one importing parameter i_ref TYPE REF TO DATA. Body is me->my_table_ref = i_ref.
From the program using the class, assuming you've defined a table somewhere "t_my_table", you can set the attribute like this.
DATA: io TYPE REF TO myclass.
...
GET REFERENCE OF t_my_table INTO io->my_table_ref.When you want to access the table within the class, you dereference to a field-symbol in the method.
FIELD-SYMBOLS: <my_table> TYPE ANY TABLE.
ASSIGN my_table_ref->* TO <my_table>.You can then access <my_table> as you would any other dynamic table.
( Note - you can use generic table as IMPORTING and EXPORTING parameters of method. Just not as attributes or RETURNING parameters - for those, you just need to pass the reference instead ).
matt
‎2008 Feb 22 3:41 PM
have anyone of you worked with Shared Memory Object Classes ?
I am trying to store the table the way you have shown, its throwing a dump exception.
‎2008 Feb 22 5:20 PM
Seeing as you've said this question is answered, it's probably better to post a new one. And give details of precisely what the dump is...
regards
matt