0

I have two string variables:

  • lv_table_name contains a table name
  • lv_column_name contains a column name

Is there a way to check if there is a table (or view) which has the given column?

Boghyon Hoffmann
  • 17,103
  • 12
  • 72
  • 170
guettli
  • 25,042
  • 81
  • 346
  • 663

2 Answers2

5

You can find table and view definitions in table DD03L. If you can access the table with your mentioned combination table/column it will be noticably faster.

REPORT.

DATA: lv_column_name TYPE string VALUE 'MY_FIELD'.

"this will tell you which tables/views exist containing the column 'MY_FIELD'
SELECT tabname
  FROM dd03l INTO TABLE @DATA(lt_tables)
  WHERE fieldname EQ @lv_column_name.
andrecito
  • 476
  • 5
  • 13
  • 1
    I think that the question is for TABLE + COLUMN, not COLUMN only, hopefully. Otherwise you'd get a rather long response time. Note that DD03L also contain ABAP Dictionary structures, so you might filter based on DD02L-TABCLASS IN ('TRANSP','CLUSTER','POOL','VIEW'). – Sandra Rossi Oct 05 '18 at 13:40
  • 3
    Note that checking DD03L (only) would be equivalent to `cl_abap_classdescr=>describe_by_name( EXPORTING p_name = |\TYPE={ lv_table_name }-{ lv_column_name }| EXCEPTIONS type_not_found = 1 ).` (sy-subrc = 1 means that the table or the column does not exist) – Sandra Rossi Oct 05 '18 at 13:45
  • @SandraRossi you wrote "Note that checking DD03L (only) would be equivalent to .." do you think checking DD03L only is not enough? – guettli Oct 15 '18 at 11:26
  • @SandraRossi sorry, I was blind. Yes DD02L looks better. Thank you. – guettli Oct 15 '18 at 11:39
1

For Netweaver 7.5, you can use a simple OPEN SQL select on DD03L https://help.sap.com/doc/abapdocu_750_index_htm/7.50/en-US/abensql_expr_literal_abexa.htm

SELECT SINGLE @abap_true
       FROM DD03L
       WHERE tabname EQ @lv_table_name AND fieldname EQ @lv_column_name
       INTO @DATA(lv_exists).
Haojie
  • 5,665
  • 1
  • 15
  • 14