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: 

declaring table of type any table

Former Member
0 Kudos

Is it possible to declare a table variable of type any table

data: i_tab type any table.

I know this can be done as a parameter in the interface of a function module but can it be done in a program. I have a strong requirement to do such a thing.

I need to write some code in a user exit function module, the interface of which contains many tables. I want to call a program dynamically based on which of the tables has been populated.

if i_tab1 is not initial. 
move itab1 to i_tab.
elseif i_tab2 is not initial.
move itab2 to i_itab.
....
...
endif. 

perform routine from program (lv_prog_name) tables i_tab.

and then I can create numerous programs

1 ACCEPTED SOLUTION

Former Member
0 Kudos

Hi,

I think your itab is declared with header line..

Try adding the body operator..

ASSIGN itab[] TO <fs>.

Thanks

Naren

13 REPLIES 13

Former Member
0 Kudos

Hi,

Can you not directly pass the interface parameters directly to the subroutine?

If not..Please explain your requirement..

Thanks

Naren

0 Kudos

Narendran ,

With what you are saying I would have to do something like this

if itab1 is not initial.
perform routine in program (l_prog_name) tables itab1.
if itab2 is not initial.
perform routine in program (l_prog_name) tables itab2.
endif.

instead what I am trying to do which I feel is much neater, but may have to ditch if I cannot declare a variable of type any table is the following

if itab1 is not initial.
move itab1 to itab.
if itab2 is not initial.
move itab2 to itab.
endif.

perform routine in program (l_prog_name) tables itab.

itab1 and itab2 are of different structure types.

Former Member

Hi, you can't declare a table variable of type any table but you can do this:

FIELD-SYMBOLS:

<fs_t_rblart> TYPE ANY TABLE.

ASSIGN internat_table TO <fs_t_rblart>.

Regards,

Carlos

Former Member
0 Kudos

Hi,

As mentioned by Carlos Bruschetti ....You can also use Field-symbols..

Field-symbols: <FS> TYPE ANY TABLE.

ASSIGN ITAB1 TO <FS>.

Check sy-subrc = 0.

Thanks

Naren

0 Kudos

but then what about perform routine in program (l_prog_name) tables itab.

will itab be replaced with field symbol <FS>

thats not going to work is it ?

Former Member
0 Kudos

Hi,

Instead of Tables you have to use USING parameter to pass the field symbols...

Thanks

Naren

0 Kudos

PERFORM processing IN PROGRAM (l_prog_name) using <fs_table>

is that correct? Its giving a dump.

What should the form processing look like? form processing using fs_table type any table

is that correct ?

0 Kudos

Yes its correct look at this:

perform xx using <fs_t_rblart>.

form xx USING t TYPE ANY TABLE.

endform.

Regards

Former Member
0 Kudos

Hi,

Yes you are correct..

Check this example..

DATA: t_mara TYPE STANDARD TABLE OF mara,
      t_marc TYPE STANDARD TABLE OF marc.

FIELD-SYMBOLS: <fs> TYPE ANY TABLE.

* Mara
ASSIGN t_mara TO <fs>.
PERFORM form1 USING  <fs>.

* Marc
ASSIGN t_marc TO <fs>.
PERFORM form1 USING  <fs>.


*&---------------------------------------------------------------------*
*&      Form  for1
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*      -->T_DATA     text
*----------------------------------------------------------------------*
FORM form1 USING t_data TYPE table.


ENDFORM.                                                    "form1

Thanks

Naren

0 Kudos

ASSIGN itab to <fs>

This gives out an error of type - incompatible.

I declared <fs> type any table. What could I be doing wrong.

Former Member
0 Kudos

Hi,

I think your itab is declared with header line..

Try adding the body operator..

ASSIGN itab[] TO <fs>.

Thanks

Naren

0 Kudos

Narendra,

Thanks a lot. Now it seems to work.

Although I dont quite understand how this part of your solution works

perform routine in program (l_prog_name) using <fs>.

form processing using fs type table. (table is not any type, Am I not right? So how does it convert)
endform.

Former Member
0 Kudos

Hi,

It treats it as generic table...and based on the internal table passed it converts it automatically....Like how it works for the function module...

Thanks

Naren