03-17-2012 4:13 PM
How can i find cutomer account number and account group both in one table.
KUNNR and KTOKD i want to get valid values from these two fields, trying to create some records for testing purposes.
I am new to sap abap.
Is there a way to search the tables in sap which has these two fields: KUNNR and KTOKD.
thank you very much for the helpful info.
03-17-2012 4:44 PM
Hi Raj Reddy,
to search for tables of a specific field you can use the t-code se15-->abap dictionary-->fields-->table fields. write the name of the field for which you wish to find the table. there are about 10 to 15 tables with the field KTOKD and table KNA1 contains both of them.
revert back if you need more help.
chandni
03-17-2012 5:00 PM
Hello Chandni, Thanks a lot for the response.
But is there a way of finding within abap, passing these two fields and find in what tables are these two fields existing.
I can do a search using /nse15 with a field name, that gives me a list of all tables where the searched field is in.
Is there a way can i search in sap bap side, both fields KUNNR and KTOKD, to see what tables are there which has these two fields.
kind regards,
Raj
03-17-2012 5:26 PM
For that you can go to SE16 enter table TBD62 enter the field name in the from and to fields and this will give you all of the tables that these fields exists in.
Hope This Helps,
Regards,
chandni
03-17-2012 9:17 PM
Hello,
TBD62 is used for message types. Don't use this for searching the where used list of fields.
Coming to your question USE transaction SE80 and option 'Repository Information System'. In that open the node ABAP dictionary and subnode Table Fields.
Use the multiple selection option in the Selection screen and enter the fields that you want to search. Use the maximum Hits you want and then the result will be displayed. In the result use the table where you can see both the fields are present.
Example: Table BC490KKNA1 & DKOKS has both the fields KUNNR and KTOKD which you can see in your result.
Try out and let me know if any issues
Br,
Vijay V
03-17-2012 9:26 PM
Hello Vijay, thanks for the response.
ON the table fields screen under Respository info system, i see table name, fieldname
just one text box next to each.
How can i enter both KUNNR and KTOKD at the same time to search, in what tables these two fields are present?
Kind regards.
Raj
03-17-2012 10:42 PM
Hi Raj
There is a button to enter multiple values where you enter the field name. click on that and then enter the two fields.
Br
Vijay V
03-19-2012 1:55 AM
Vijay, please sir.
I did exactly like you said.
There is a icon right next to fieldnames text box, i clicked it is showing miltple text boxes.
Ineash text box i entered a Field name.
KUNNR and KTOKD two different boxes, and lciked clock which is execute on that screen and then did F8 .
it is showing 200 hits, this is wrong.
It is only showing specific to KUNNR field.
if i put KTOKD as first field and KUNNR as second field it is showing 30 hits specific to KTOKD.
My whole whole intention is to find those tables only which has both of these fields KTOKD and KUNNR.
Kind regards.
Raj
03-19-2012 3:19 AM
Hi,
Your requirement is to find tables that has fields KUNNR and KTOKD in your ABAP query right?
So, my suggestion is use table DD03L to get tables with those fields.
Regards,
Jake
03-19-2012 3:35 AM
Take a look at this code:
TYPES: BEGIN OF ty_data,
tabname TYPE dd03l-tabname, " table name
fieldname TYPE dd03l-fieldname, " field name
END OF ty_data.
DATA: it_kunnr TYPE STANDARD TABLE OF ty_data,
it_ktokd TYPE STANDARD TABLE OF ty_data,
wa_kunnr TYPE ty_data,
wa_ktokd TYPE ty_data.
" Get tables with field KUNNR
SELECT tabname
fieldname
FROM dd03l
INTO TABLE it_kunnr
WHERE fieldname EQ 'KUNNR'
AND as4local EQ 'A'.
IF sy-subrc EQ 0.
SORT it_kunnr BY tabname.
ENDIF.
" Get tables with field KTOKD
SELECT tabname
fieldname
FROM dd03l
INTO TABLE it_ktokd
WHERE fieldname EQ 'KTOKD'
AND as4local EQ 'A'.
IF sy-subrc EQ 0.
SORT it_ktokd BY tabname.
ENDIF.
" Get tables names exist in both itab
LOOP AT it_ktokd INTO wa_ktokd.
READ TABLE it_kunnr INTO wa_kunnr
WITH KEY tabname = wa_ktokd-tabname.
IF sy-subrc EQ 0.
WRITE:/ wa_kunnr-tabname.
ENDIF.
ENDLOOP.
Regards,
Jake
03-19-2012 9:15 AM
Hello Raj
If the two fields are used in the same table then you will see them together under the single table else you will get them separately. If you want to do it via coding then there are lots of replies for the same.
Br,
Vijay V
03-19-2012 4:23 AM
Hi,
you can use the below code:
tables : rsrd1.
type-pools : slis.
* Types declaration.
types : begin of gs_where,
tabname type tabname,
fieldname type fieldname,
rollname type rollname,
end of gs_where,
begin of gs_input,
element type rsrd1-ddtype_val,
end of gs_input,
begin of gs_table,
tabname type tabname,
end of gs_table,
begin of gs_result,
tabname type tabname,
end of gs_result,
begin of gs_display,
tabname type tabname,
ddtext type as4text,
end of gs_display.
* Internal tables declaration.
data : gi_where type table of gs_where,
gi_input type table of gs_input,
gi_table type table of gs_table,
gi_result type table of gs_result,
gi_display type table of gs_display,
gi_fcat type slis_t_fieldcat_alv,
gi_bdcdata type table of bdcdata.
* Work areas declaration.
data : gw_where type gs_where,
gw_input type gs_input,
gw_table type gs_table,
gw_result type gs_result,
gw_display type gs_display,
gw_fcat type slis_fieldcat_alv,
gw_layout type slis_layout_alv,
gw_bdcdata type bdcdata.
* Variables declaration.
data : gv_flag type i,
gv_title type string,
gv_text(70) type c,
gv_strlen type i,
gv_tabname type tabname.
selection-screen begin of block b with frame title text-000.
select-options : s_type for rsrd1-ddtype_val.
selection-screen end of block b.
initialization.
* Disabling select-options high option.
loop at screen.
if screen-name = 'S_TYPE-HIGH'.
screen-input = 0.
screen-output = 0.
screen-invisible = 1.
modify screen.
endif.
endloop.
* Tables selection
start-of-selection.
perform get_tablenames.
perform get_multiple_matches.
* Outputing result
end-of-selection.
* Creating field catalog for ALV display.
perform create_fcat using : 'TABNAME' 1 'Table name',
'DDTEXT' 2 'Short description'.
* Displaying the result tables.
perform display_result.
*&---------------------------------------------------------------------*
*& Include ZWHEREUSEDLIST_FORMS
*&---------------------------------------------------------------------*
*&---------------------------------------------------------------------
*& Form GET_TABLENAMES
*&---------------------------------------------------------------------
form get_tablenames.
* Consolidating selection inputs into an internal table.
loop at s_type.
gw_input-element = s_type-low.
append gw_input to gi_input.
endloop.
* Selecting the table names having the input data elements.
select tabname fieldname rollname
from dd03vv
into table gi_where
for all entries in gi_input
where rollname = gi_input-element and
as4local = 'A' and
( tabclass = 'TRANSP' or
tabclass = 'CLUSTER' or
tabclass = 'POOL' ).
* Segregating the table names.
loop at gi_where into gw_where.
gw_table-tabname = gw_where-tabname.
append gw_table to gi_table.
endloop.
sort gi_table by tabname.
delete adjacent duplicates from gi_table comparing all fields.
endform. " GET_TABLENAMES
*&---------------------------------------------------------------------
*& Form GET_MULTIPLE_MATCHES
*&---------------------------------------------------------------------
form get_multiple_matches .
* Selecting the tables which are having all the input table names.
loop at gi_table into gw_table.
gv_flag = 0.
loop at gi_input into gw_input.
read table gi_where into gw_where with key
tabname = gw_table-tabname
rollname = gw_input-element.
if sy-subrc ne 0.
gv_flag = 1.
endif.
endloop.
if gv_flag = 0.
gw_result-tabname = gw_table.
append gw_result to gi_result.
endif.
endloop.
* Retrieving table's short description.
if gi_result[] is not initial.
select tabname ddtext
from dd02t
into table gi_display
for all entries in gi_result
where tabname = gi_result-tabname and
ddlanguage = 'E'.
if sy-subrc = 0.
sort gi_display by tabname ddtext.
delete adjacent duplicates from gi_display comparing tabname.
endif.
endif.
endform. " GET_MULTIPLE_MATCHES
*&--------------------------------------------------------------------*
*& Form CREATE_FCAT
*&---------------------------------------------------------------------
form create_fcat using v_fieldname type c
v_colpos type i
gv_text type c.
* Creating field catalogs
clear gw_fcat.
gw_fcat-fieldname = v_fieldname.
gw_fcat-col_pos = v_colpos.
gw_fcat-seltext_l = gv_text.
gw_fcat-tabname = 'T_DISPLAY'.
append gw_fcat to gi_fcat.
endform. " CREATE_FCAT
*&--------------------------------------------------------------------*
*& Form DISPLAY_RESULT
*&--------------------------------------------------------------------*
form display_result .
* ALV grid title creation
gw_layout-colwidth_optimize = 'X'.
gv_title = 'Where used list for-'.
loop at gi_input into gw_input.
concatenate gv_title gw_input-element ', ' into gv_title.
endloop.
gv_strlen = strlen( gv_title ) - 1.
gv_title = gv_title+0(gv_strlen).
gv_text = gv_title.
* List of tables display
call function 'REUSE_ALV_GRID_DISPLAY'
exporting
i_callback_program = sy-repid
i_callback_user_command = 'USER_COMMAND'
i_grid_title = gv_text
is_layout = gw_layout
it_fieldcat = gi_fcat
tables
t_outtab = gi_display.
endform. " DISPLAY_RESULT
Hope this helps.
Regards,
Gaurav,
03-19-2012 10:19 AM
Hi,
The code written above will work for any number of fields entered.
Regards,
Gaurav.
03-19-2012 4:31 AM
I like Jake's approach....you could even use a join of DD03L to itself...
select KUNNR~tabname from dd03l as kunnr
join dd03l as ktokd
on kunnr~tabname = ktokd~tabname
INTO DD03L-TABNAME
where kunnr~fieldname = 'KUNNR'
AND KTOKD~FIELDNAME = 'KTOKD'.
WRITE:/ DD03L-TABNAME.
ENDSELECT.
03-19-2012 5:26 AM
Hi Raj Reddy!
This is Shyam. Go to SE11-> Data Dictionary.
DB Tables-> Give KNA1-> Its a Customer Master Table-> Click Display.
You Wil Get List Of Fields and There Details..... U can see Kunnr, Ktokd etc.....
There is a Find Button at the Top.....Give the Field Name....u wil get ur exact field there......
03-19-2012 6:58 AM
Hi
Pls use below code to get all transperent tables for specified fields...to acess for other conditions just change where statement
DATA : itab TYPE STANDARD TABLE OF dd03vv WITH HEADER LINE.
SELECT * FROM dd03vv INTO TABLE itab WHERE fieldname EQ 'KUNNR' OR fieldname EQ 'KTOKD' and tabclass = 'TRANSP'.
SORT itab BY tabname fieldname.
DELETE ADJACENT DUPLICATES FROM itab COMPARING tabname fieldname.
LOOP AT itab WHERE fieldname = 'KUNNR'.
READ TABLE itab WITH KEY tabname = itab-tabname fieldname = 'KTOKD' BINARY SEARCH.
IF sy-subrc EQ 0.
WRITE : / itab-tabname.
ELSE.
DELETE itab.
ENDIF.
ENDLOOP.