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: 

Pass unknown table name to FM

Former Member
0 Kudos

I want to pass a table name based on conditions to a functional module. How to do it ?

CALL FUNCTION 'HR_READ_INFOTYPE'

       EXPORTING

         pernr                 = pernr-pernr

         infty                 = ls_infty-line

         begda                 = '18000101'

         endda                 = '99991231'

       TABLES

         infty_tab             = (lv_tabname)

      EXCEPTIONS

         infty_not_found       = 1

         others

lv_tabname could be p0000 or p0001 etc.

1 ACCEPTED SOLUTION

former_member199637
Participant
0 Kudos

Hello,

Create a field symbol of type ANY TABLE and pass it to the tables parameter of the FM.

Regards,

Puneet Desai

5 REPLIES 5

former_member199637
Participant
0 Kudos

Hello,

Create a field symbol of type ANY TABLE and pass it to the tables parameter of the FM.

Regards,

Puneet Desai

0 Kudos

But i have already declared the tables, i didnt want to create the same tables dynamically again. Is there any other way to pass them.

Former Member
0 Kudos

Hello,

You can dynamically assign as below

DATA:  wa_dref TYPE REF TO data,             
         FIELD-SYMBOLS: <info_itab> TYPE ANY TABLE. 

CREATE DATA wa_dref TYPE TABLE OF (p_infty).

  ASSIGN wa_dref ->* TO <info_itab>.


CALL FUNCTION 'HR_READ_INFOTYPE'
EXPORTING
tclas = 'A'
pernr = p_pernr
infty = p_infty
begda = p_begda
endda = p_endda
IMPORTING
subrc = subrc
TABLES
infty_tab = <info_itab>
EXCEPTIONS
infty_not_found = 1
OTHERS = 2.

Katrice

Former Member
0 Kudos

Hello Friend,

If you are using only 2 tables i.e. p0000 and p0001, then create a simple IF ELSE condition before passing data to FM. In your FM you are passing

          infty                     =  ls_infty-line

         begda                 = '18000101'

         endda                 = '99991231'     only these 3 parameters. 

So If you know the exact criteria when to pass which table then yo can do it like below mentioned example.

IF inftly eq ls_infty-line

    AND  (begda < 18000100)

     AND   (endda < 99991231 )

lv_tabname = p0000.

ELSE.

lv_tabname = p0001.

ENDIF.

Similarly check your conditions and adjust IF ELSE IF  statements.

Please provide more information so that you will get accurate solution.

Regards,

Sudhir Kothavale.


Former Member
0 Kudos

Hi,

If I have understood your issue correctly, you can follow the below steps:

If v_tabname = 'p0000'.

   

CALL FUNCTION 'HR_READ_INFOTYPE'

       EXPORTING

         pernr                 = pernr-pernr

         infty                 = ls_infty-line

         begda                 = '18000101'

         endda                 = '99991231'

       TABLES

         infty_tab             = (lv_tabname)

      EXCEPTIONS

         infty_not_found       = 1

         others

elseif v_tabname = 'p0001'.

 

CALL FUNCTION 'HR_READ_INFOTYPE'

       EXPORTING

         pernr                 = pernr-pernr

         infty                 = ls_infty-line

         begda                 = '18000101'

         endda                 = '99991231'

       TABLES

         infty_tab             = (lv_tabname)

      EXCEPTIONS

         infty_not_found       = 1

         others

Regards

Purnand