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: 

Passing dynamic internal table in a class object

former_member355937
Participant
0 Kudos

Hi Experts,

Is there a way I can pass a dynamic internal table to a class as a parameter and manipulate on it?

Thanks very much,

Jeffrey

3 REPLIES 3

Former Member
0 Kudos

<b>Here is the scenario...</b>

I have 4 fields in my internal table itab.

And i have 1 DYNAMIC internal table having more than 20 fields.

1st two field values of itab has to go into DYNAMIC internal table 1st two fields, and my itab 3rd field value will be the name of one of the field in DYNAMIC itab.

4th field value of itab has to go into respective field of DYNAMIC itab.

Example in itab i have one record as

US01 5000 USD 12500.00

now US01 will go in 1st field of DYNAMIC itab.

5000 will go in 2and field.

USD will be name of one field in DYNAMIC itab.

12500.00 should go into USD field of DYNAMIC itab.

<b>Sample code </b>

data: begin of it_per occurs 10,

BUKRS like glt0-bukrs,

RACCT like glt0-racct,

RTCUR like glt0-rtcur,

amount like glt0-tslvt,

end of it_per.

FIELD-SYMBOLS: <FS_DATA> type ref to DATA,

<FS_1> type any table,

<FS_2> type any,

<FS_3>.

LS_FIELDCATALOG-FIELDNAME = 'BUKRS'.

append LS_FIELDCATALOG to LT_FIELDCATALOG.

LS_FIELDCATALOG-FIELDNAME = 'HKONT'.

append LS_FIELDCATALOG to LT_FIELDCATALOG.

loop at curr_tab.

LS_FIELDCATALOG-FIELDNAME = curr_tab-WAERS.

append LS_FIELDCATALOG to LT_FIELDCATALOG.

endloop.

assign LT_DATA to <FS_DATA>.

call method cl_alv_table_create=>create_dynamic_table

exporting

it_fieldcatalog = LT_FIELDCATALOG

importing

ep_table = <FS_DATA>

exceptions

generate_subpool_dir_full = 1

others = 2.

Just go on from here....

Regards,

Pavan.

Former Member
0 Kudos

Hi,

Look bellow sample program

report ytest.

data: lt_fieldcatalog type lvc_t_fcat.

data: ls_fieldcatalog type lvc_s_fcat.

field-symbols: <fs_data> type ref to data.

field-symbols: <fs_1>.

field-symbols: <fs_2> type any table.

field-symbols: <fs_3> type ypoll.

data: lt_data type ref to data.

assign lt_data to <fs_data>.

ls_fieldcatalog-fieldname = 'MANDT'.

ls_fieldcatalog-tabname = 'LT_TAB'.

append ls_fieldcatalog to lt_fieldcatalog.

ls_fieldcatalog-fieldname = 'POLLID'.

ls_fieldcatalog-tabname = 'LT_TAB'.

append ls_fieldcatalog to lt_fieldcatalog.

ls_fieldcatalog-fieldname = 'TEAM'.

ls_fieldcatalog-tabname = 'LT_TAB'.

append ls_fieldcatalog to lt_fieldcatalog.

ls_fieldcatalog-fieldname = 'INITIATOR'.

ls_fieldcatalog-tabname = 'LT_TAB'.

append ls_fieldcatalog to lt_fieldcatalog.

ls_fieldcatalog-fieldname = 'DESCRIPTION'.

ls_fieldcatalog-tabname = 'LT_TAB'.

append ls_fieldcatalog to lt_fieldcatalog.

ls_fieldcatalog-fieldname = 'APPROVED'.

ls_fieldcatalog-tabname = 'LT_TAB'.

append ls_fieldcatalog to lt_fieldcatalog.

ls_fieldcatalog-fieldname = 'INITIATED_DATE'.

ls_fieldcatalog-tabname = 'LT_TAB'.

append ls_fieldcatalog to lt_fieldcatalog.

ls_fieldcatalog-fieldname = 'END_DATE'.

ls_fieldcatalog-tabname = 'LT_TAB'.

append ls_fieldcatalog to lt_fieldcatalog.

ls_fieldcatalog-fieldname = 'WINNER'.

ls_fieldcatalog-tabname = 'LT_TAB'.

append ls_fieldcatalog to lt_fieldcatalog.

call method cl_alv_table_create=>create_dynamic_table

exporting

it_fieldcatalog = lt_fieldcatalog

importing

ep_table = <fs_data>

exceptions

generate_subpool_dir_full = 1

others = 2

.

if sy-subrc <> 0.

endif.

assign <fs_data>->* to <fs_1>.

assign <fs_1> to <fs_2>.

loop at <fs_2> assigning <fs_3>.

write: <fs_3>-pollid.

endloop.

Regards

Gaurav

0 Kudos

Hi,

Pass it using TYPE REF TO DATA.

Declare your class importing paramters as TYPE REF TO DATA.

DATA: dat TYPE REF TO DATA.

And then use GET REFERENCE OF ITAB INTO dat.

pass the dat. to the class.

Regards,

Sesh