10-15-2008 9:52 PM
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
10-15-2008 10:38 PM
Hi,
I think your itab is declared with header line..
Try adding the body operator..
ASSIGN itab[] TO <fs>.
Thanks
Naren
10-15-2008 9:58 PM
Hi,
Can you not directly pass the interface parameters directly to the subroutine?
If not..Please explain your requirement..
Thanks
Naren
10-15-2008 10:08 PM
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.
10-15-2008 10:07 PM
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
10-15-2008 10:11 PM
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
10-15-2008 10:13 PM
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 ?
10-15-2008 10:17 PM
Hi,
Instead of Tables you have to use USING parameter to pass the field symbols...
Thanks
Naren
10-15-2008 10:23 PM
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 ?
10-15-2008 10:28 PM
Yes its correct look at this:
perform xx using <fs_t_rblart>.
form xx USING t TYPE ANY TABLE.
endform.
Regards
10-15-2008 10:30 PM
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
10-15-2008 10:37 PM
ASSIGN itab to <fs>
This gives out an error of type - incompatible.
I declared <fs> type any table. What could I be doing wrong.
10-15-2008 10:38 PM
Hi,
I think your itab is declared with header line..
Try adding the body operator..
ASSIGN itab[] TO <fs>.
Thanks
Naren
10-15-2008 10:48 PM
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.
10-15-2008 10:51 PM
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