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: 

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

Former Member
0 Kudos

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 ?

Thanks,

Venkat.

1 ACCEPTED SOLUTION

Former Member
0 Kudos

Go to DD03L table and give this criteria.

13 REPLIES 13

former_member387317
Active Contributor
0 Kudos

just go to se11 and write T* to get the tables which are starting with the name T.

Thanks & Regards

ilesh 24x7

Former Member
0 Kudos

Go to DD03L table and give this criteria.

0 Kudos

Hi Srinivas,

From DD03L table, we could find the Table names and Structures by providing the field XYZ in 'FIELDNAME' .

According to me, it will list all the table names and Structures that are with field XYZ, but I am looking with <b>field</b> <b>VALUES</b>, please correct me.

How can I accomplish my requirement please ?

Thanks,

Venkat.

0 Kudos

I am not sure if I understood your requirement correctly. So you want to find all those tables that have two fields, and those two fields have the values that you are looking for. Is this correct?

0 Kudos

Hi Srinivas,

Yes.

I want to find a table and it's name starts with T*. ORD43 & TXTMD are the fields in that table. The condition is where ORD43 = 'ABC' & TXTMD = '123' .

Thanks,

Venkat.

0 Kudos

Try this

DATA: tabname LIKE dd02l-tabname.

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

SELECT tabname INTO TABLE itab_tables
                     FROM dd03l
                    WHERE fieldname = 'ORD43'.

*-- 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.
    CONTINUE.
  ENDIF.
*-- 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.
    CONTINUE.
  ENDIF.
ENDLOOP.

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

0 Kudos

Hi Srinivas,

Thanks for the complete code.

I am getting the following Runtime for '/BI0/C_0077' :

Short Text: Table is not declared as a database table or view in ABAP dictionary.

The reason for this exception is:

You can only perform Open SQL accesses on tables or views that are

defined in the ABAP/4 Dictionary. "/BI0/C_0077" has either not been created

or is not active.

'/BI0/C_0077' is a Extract Structure. DD03L extract all Tables, Views & Structures also. How could we exclude these strctures. It should find only tables.

Thanks,

Venkat.

0 Kudos

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.
    CONTINUE.
  ENDIF.
*-- 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.
    CONTINUE.
  ENDIF.
ENDLOOP.

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

0 Kudos

Hi Srinivas,

Finally, found the table.

Thank you for your time.

Regards,

Venkat

Former Member
0 Kudos

Hi,

Use following code:

data: begin of i_tab occurs 0.

include structure dd03l.

data : end of i_tab.

select tabname from dd03l into i_tab

where tabname like 'T%' and

( fieldname = 'ABC' or

fieldname = '123' ).

Cheers,

Vikram

Former Member
0 Kudos

.

Former Member
0 Kudos

.

Former Member
0 Kudos

.