Application Development Blog Posts
Learn and share on deeper, cross technology development topics such as integration and connectivity, automation, cloud extensibility, developing at scale, and security.
cancel
Showing results for 
Search instead for 
Did you mean: 
Former Member
0 Kudos

Business Scenario:

Sometimes you know the field names but you are not sure about the table names which contains your desired field names in that case you have to consult function person to help you out. So here is the program which gives you the table names whatever field names you give.

Note:  you can change the following code for your desired no. of fields, here I’m explaining with 2 fields

Note: Please handle validations and messages whenever you give wrong filed names or empty filed names. This program is just for reference.

REPORT  yh69_example.* Tables

TABLES dd02l.

* structure to hold table name and field name

TYPES:
      
BEGIN OF ty_data,
       tabname  
TYPE dd03l-tabname,   " Table name
       fieldname
TYPE dd03l-fieldname, " Field name
      
END OF ty_data.

* Declaration of internal tables to hold the table nameDATA:
       t_tab1
TYPE STANDARD TABLE OF ty_data,
       t_tab2
TYPE STANDARD TABLE OF ty_data,
       wa_tab1
TYPE ty_data,
       wa_tab2
TYPE ty_data.

PARAMETERS : p_filed1(30) TYPE c,
             p_filed2
(30) TYPE c.
" Get table names which contain your filed names

* Select

SELECT tabname
       fieldname
  
FROM dd03l
  
INTO TABLE t_tab1
  
WHERE fieldname EQ p_filed1
  
AND as4local  EQ 'A'.
IF sy-subrc EQ 0.

* Sort the table
 
SORT t_tab1 BY tabname.ENDIF.                                 " IF SY-SUBRC EQ 0
" Get table names which contain your filed names

* Select

SELECT tabname
       fieldname
  
FROM dd03l
  
INTO TABLE t_tab2
 
WHERE fieldname EQ p_filed2
   
AND as4local  EQ 'A'.
IF sy-subrc EQ 0.

* Sort the table
 
SORT t_tab2 BY tabname.

ENDIF.                                 " IF SY-SUBRC EQ 0
" Get tables names exist in both itab

LOOP AT t_tab2 INTO wa_tab2.

 
READ TABLE t_tab1 INTO wa_tab1
                 
WITH KEY tabname = wa_tab2-tabname.
 
IF sy-subrc = 0.
   
SELECT SINGLE * FROM dd02l WHERE tabname  = wa_tab1-tabname
                              
AND tabclass = 'TRANSP'.
   
IF sy-subrc EQ 0.
     
WRITE:/ wa_tab1-tabname.
   
ELSE.
     
CLEARwa_tab1 .                " CLEAR WORK AREA
   
ENDIF.                             " IF SY-SUBRC EQ 0
 
ENDIF.                               " IF SY-SUBRC EQ 0
 
CLEAR wa_tab2.                       " CLEAR WORK AREA
ENDLOOP.

8 Comments