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.
CLEAR: wa_tab1 . " CLEAR WORK AREA
ENDIF. " IF SY-SUBRC EQ 0
ENDIF. " IF SY-SUBRC EQ 0
CLEAR wa_tab2. " CLEAR WORK AREA
ENDLOOP.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
5 | |
5 | |
4 | |
3 | |
3 | |
2 | |
2 | |
2 | |
2 | |
1 |