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: 

Function Module to check if a table exists in DB which is entered by user.

Former Member
0 Kudos

HI all,

Can anyone please help me, in finding the name of the function module, which checks, if a table exists in DD02L. But the output should be only in the form of sy-subrc. I mean, if such a table exists, sy-subrc should be 0.

I am entering the table name in selection screen. So, I have to check if it exists or not. If it does, sy-subrc should be 0, else i'll display a popup.

I tried with RS_TABLE_LIST_CREATE. But it navigates directly to SE16 , if a table exists (Which is what I dont want).So, for this, which function module should I use ?

Kindly Suggest.

Regards ,

Neha.

1 ACCEPTED SOLUTION

Sougata
Active Contributor
0 Kudos

Is it a must that you <b>have to</b> use a FM? Write your logic like this:

data: v_count type i.

select count(*) from  dd02l
                into    v_count
                where   tabname = <your selection-screen input>
                and     as4local  = 'A'.       "Entry was activated

if v_count > 0.
 "means table exists and is active in the database
else.
 " means table doesn't exist as an Active table in the database
 " call your popup here
endif.

Don't forget to reward points.

Cheers,

Sougata.

11 REPLIES 11

Former Member
0 Kudos

you can check the fm DD_EXIST_TABLE

or use select query on the table DD02L.

regards

shiba dutta

Former Member
0 Kudos

use this function module.

<b>SCPR_DB_TABLE_EXIST</b>

<b>DD_EXIST_TABLE</b>

where status field say like this.

<b>A Activity was generated or activated</b> use this.

L Lock entry

N Entry was edited but not activated

S Preveious active,backup copy

T Temporary version

Message was edited by:

Amit Singla

former_member200338
Active Contributor
0 Kudos

Hi,

Goto table TADIR. give the table name in object name. check whether you are getting the output. if yes, then use a select query on this table.

you can use object id also to restrict the database hit,

Regards,

Niyaz

Former Member
0 Kudos

The problem is, I only have to use a Function module for it, Cant directly write a query on dd02l or any other table.

0 Kudos

<<The problem is, I only have to use a Function module for it, Cant directly write a query on dd02l or any other table. >>

and why is that??

0 Kudos

Hi Neha,

U can use the Function Module 'DB_EXISTS_TABLE' for checking the table exists in data base or not.

It will return a parameter subrc 0 when table exists other wise returns 4.

Hope this will be helpfull in resolving the problem.

Regards,

Kasinath Babu

0 Kudos

Hello Neha,

With SCPR_DB_TABLE_EXIST and DD_EXIST_TABLE you can find out whether the table is existing or not. After providing the table name to these functions just check the sy-subrc value. If its zero, you have your table available...

Thanks and Regards

Joe

0 Kudos

You are not using the function modules i suggested???

it giving the result what you want ( DD_EXIST_TABLE)

in status hardcord 'A' always.

reward if useful..

Amit Singla

Sougata
Active Contributor
0 Kudos

Is it a must that you <b>have to</b> use a FM? Write your logic like this:

data: v_count type i.

select count(*) from  dd02l
                into    v_count
                where   tabname = <your selection-screen input>
                and     as4local  = 'A'.       "Entry was activated

if v_count > 0.
 "means table exists and is active in the database
else.
 " means table doesn't exist as an Active table in the database
 " call your popup here
endif.

Don't forget to reward points.

Cheers,

Sougata.

rainer_hbenthal
Active Contributor
0 Kudos

You can try to ctach the system error:



try.
  select a,b from (tabname).

  catch cx_sy_sql_error.
    perform error_handling.
end-try.

Former Member
0 Kudos

Thanks all, for answering my question and helping me. I am rewarding points to all those who've posted.