Skip to Content

Archived discussions are read-only. Learn more about SAP Q&A

How can I read all tables to find a table where Field1=ABC & Field2= 123 ?

Hi all,

I have to find a table which starts with T* (650 Text Tables) where Field1 = 'ABC' & Field2= '123' .

How can I read all those tables which starts with T* that match with the given criteria, please ?



Former Member

You will have check that against the table DD02L to see if it is table or a structure. Try this

DATA: tabname LIKE dd02l-tabname.

DATA: BEGIN OF itab_tables OCCURS 0,
        tabname LIKE dd02l-tabname.
DATA: END OF itab_tables.

RANGES: r_tabclass FOR dd02l-tabclass.

r_tabclass-low    = 'INTTAB'.
r_tabclass-sign   = 'EQ'.
r_tabclass-option = 'I'.
APPEND r_tabclass.

CLEAR r_tabclass-low.
r_tabclass-low    = 'APPEND'.
APPEND r_tabclass.

SELECT a~tabname INTO TABLE itab_tables
                       FROM dd03l AS a INNER JOIN
                            dd02l AS b ON
                            a~tabname  = b~tabname  AND
                            a~as4local = b~as4local AND
                            a~as4vers  = b~as4vers
                      WHERE a~fieldname = 'ORD43'
                        AND b~tabclass NOT IN r_tabclass.

*-- Now make sure that hese tables also have the field TXTMD
LOOP AT itab_tables.
  SELECT tabname INTO TABLE itab_tables
                       FROM dd03l
                      WHERE fieldname = 'TXTMD'.
  IF sy-subrc <> 0.
*-- this field is not in the table, ignore it.
    DELETE itab_tables.
*-- Now check the table contents and consider the tables only if they
*   meet the criteria
  SELECT COUNT(*) FROM (itab_tables-tabname)
                 WHERE ord43 = 'XYZ'
                   AND txtmd = 'ABC'.
  IF sy-subrc <> 0.
*-- no record exists satisfying the conditions
    DELETE itab_tables.

*-- now itab_tables will contain only table names that have the two fields
*   and have the fields satisfying the criteria

0 View this answer in context
Not what you were looking for? View more on this topic or Ask a question