Application Development and Automation 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:Ā 
Read only

Finding common structures

dave_price
Participant
0 Likes
1,699

Hello, building a lot of RFCs and I find I'm often looking for very simple structures like, say, KUNNR+KUNWE, that probably already exist somewhere.  Unfortunately, as far as I know there's no SAP utility that will find only the structures that have both fields -- obviously I could do a where-used on either alone but I'd get a huge number of results even among just our Z structures.

Is there a (custom?) utility out there that would find structures based on multiple fields?  I need this so often, I am sorely tempted to just write my own, it seems doable...

1 ACCEPTED SOLUTION
Read only

freek_cavens2
Participant
0 Likes
1,634

Hi Dave,

I have written a program for this that does exactly what you require : it give you all tables/structures where both fields exist.  You will need to make some minor changes to use it.  In the select on dd02l, the tabclass for structures is 'INTTAB' (I normally use this to search actual database tables).  The export method uses a wrapper class for excel.  You should replace it by a simple ALV or use

cl_gui_frontend_services=>gui_download to download the result and you'll be fine.

*&---------------------------------------------------------------------*
*& Report  ZFIELDCOMMONTABLESFINDER
*&
*&---------------------------------------------------------------------*
*&
*&
*&---------------------------------------------------------------------*

REPORT  zfieldcommontablesfinder.

TABLES : dd03l.

PARAMETERS : fname1 TYPE fname,
              fname2 TYPE fname,
              all RADIOBUTTON GROUP r1,
              tab RADIOBUTTON GROUP r1.

*----------------------------------------------------------------------*
*       CLASS cl_fieldcommontablesfinder DEFINITION
*----------------------------------------------------------------------*
*
*----------------------------------------------------------------------*
CLASS cl_fieldcommontablesfinder DEFINITION.
   PUBLIC SECTION.
     CLASS-METHODS :
       main.

   PRIVATE SECTION.
     TYPES :
       BEGIN OF ty_fields,
         tabname TYPE tabname,
         dummy TYPE dummy,
       END OF ty_fields.

     CLASS-DATA :
       gt_fields TYPE TABLE OF ty_fields.

     CLASS-METHODS :
       find_tables,
       export.
ENDCLASS.                    "cl_fieldcommontablesfinder DEFINITION

*----------------------------------------------------------------------*
*       CLASS cl_fieldcommontablesfinder IMPLEMENTATION
*----------------------------------------------------------------------*
*
*----------------------------------------------------------------------*
CLASS cl_fieldcommontablesfinder IMPLEMENTATION.
   METHOD main.

     find_tables( ).
     export( ).

   ENDMETHOD.                    "main

   METHOD find_tables.

     DATA : lt_tab TYPE HASHED TABLE OF ty_fields WITH UNIQUE KEY tabname.

     IF all EQ 'X'.
       SELECT DISTINCT tabname FROM dd03l
              INTO CORRESPONDING FIELDS OF TABLE lt_tab
              WHERE fieldname EQ fname1.

       SELECT tabname FROM dd03l
              INTO CORRESPONDING FIELDS OF TABLE gt_fields
              FOR ALL ENTRIES IN lt_tab
              WHERE tabname EQ lt_tab-tabname
                AND fieldname EQ fname2.
     ELSE.
       SELECT DISTINCT a~tabname FROM dd03l AS a INNER JOIN dd02l AS b
                                            ON a~tabname EQ b~tabname
              INTO CORRESPONDING FIELDS OF TABLE lt_tab
              WHERE a~fieldname EQ fname1
                AND b~tabclass IN ('TRANSP','CLUSTER','POOL').

       SELECT DISTINCT a~tabname FROM dd03l AS a INNER JOIN dd02l AS b
                                            ON a~tabname EQ b~tabname
              INTO CORRESPONDING FIELDS OF TABLE gt_fields
              FOR ALL ENTRIES IN lt_tab
              WHERE a~fieldname EQ fname2
                AND b~tabclass IN ('TRANSP','CLUSTER','POOL')
                AND a~tabname EQ lt_tab-tabname.
     ENDIF.

   ENDMETHOD.                    "find_tables

   METHOD export.

     DATA : lw_fields TYPE ty_fields.

     CALL METHOD zcl_excel=>export
       EXPORTING
         i_structure = lw_fields
       CHANGING
         c_tab       = gt_fields.

   ENDMETHOD.                    "export
ENDCLASS.                    "cl_fieldcommontablesfinder IMPLEMENTATION

START-OF-SELECTION.

   cl_fieldcommontablesfinder=>main( ).

Regards,

Freek

6 REPLIES 6
Read only

Former Member
0 Likes
1,634

Hi Dave,

I am not sure If you are looking for this.

Transaction - SE80 ---> Click on Repository Information System -----> ABAP Dictionary -----> Fields -----> Structure Fields

On the right Side, you can enter multiple fields and then  click execute, it will being all the structures that has both the fields.

Read only

0 Likes
1,634

Thanks for the response.  That's interesting, but unfortunately that will return all the stuctures that have KUNWE or KUNNR, not the structures that have KUNWE and KUNNR.

.

Read only

freek_cavens2
Participant
0 Likes
1,635

Hi Dave,

I have written a program for this that does exactly what you require : it give you all tables/structures where both fields exist.  You will need to make some minor changes to use it.  In the select on dd02l, the tabclass for structures is 'INTTAB' (I normally use this to search actual database tables).  The export method uses a wrapper class for excel.  You should replace it by a simple ALV or use

cl_gui_frontend_services=>gui_download to download the result and you'll be fine.

*&---------------------------------------------------------------------*
*& Report  ZFIELDCOMMONTABLESFINDER
*&
*&---------------------------------------------------------------------*
*&
*&
*&---------------------------------------------------------------------*

REPORT  zfieldcommontablesfinder.

TABLES : dd03l.

PARAMETERS : fname1 TYPE fname,
              fname2 TYPE fname,
              all RADIOBUTTON GROUP r1,
              tab RADIOBUTTON GROUP r1.

*----------------------------------------------------------------------*
*       CLASS cl_fieldcommontablesfinder DEFINITION
*----------------------------------------------------------------------*
*
*----------------------------------------------------------------------*
CLASS cl_fieldcommontablesfinder DEFINITION.
   PUBLIC SECTION.
     CLASS-METHODS :
       main.

   PRIVATE SECTION.
     TYPES :
       BEGIN OF ty_fields,
         tabname TYPE tabname,
         dummy TYPE dummy,
       END OF ty_fields.

     CLASS-DATA :
       gt_fields TYPE TABLE OF ty_fields.

     CLASS-METHODS :
       find_tables,
       export.
ENDCLASS.                    "cl_fieldcommontablesfinder DEFINITION

*----------------------------------------------------------------------*
*       CLASS cl_fieldcommontablesfinder IMPLEMENTATION
*----------------------------------------------------------------------*
*
*----------------------------------------------------------------------*
CLASS cl_fieldcommontablesfinder IMPLEMENTATION.
   METHOD main.

     find_tables( ).
     export( ).

   ENDMETHOD.                    "main

   METHOD find_tables.

     DATA : lt_tab TYPE HASHED TABLE OF ty_fields WITH UNIQUE KEY tabname.

     IF all EQ 'X'.
       SELECT DISTINCT tabname FROM dd03l
              INTO CORRESPONDING FIELDS OF TABLE lt_tab
              WHERE fieldname EQ fname1.

       SELECT tabname FROM dd03l
              INTO CORRESPONDING FIELDS OF TABLE gt_fields
              FOR ALL ENTRIES IN lt_tab
              WHERE tabname EQ lt_tab-tabname
                AND fieldname EQ fname2.
     ELSE.
       SELECT DISTINCT a~tabname FROM dd03l AS a INNER JOIN dd02l AS b
                                            ON a~tabname EQ b~tabname
              INTO CORRESPONDING FIELDS OF TABLE lt_tab
              WHERE a~fieldname EQ fname1
                AND b~tabclass IN ('TRANSP','CLUSTER','POOL').

       SELECT DISTINCT a~tabname FROM dd03l AS a INNER JOIN dd02l AS b
                                            ON a~tabname EQ b~tabname
              INTO CORRESPONDING FIELDS OF TABLE gt_fields
              FOR ALL ENTRIES IN lt_tab
              WHERE a~fieldname EQ fname2
                AND b~tabclass IN ('TRANSP','CLUSTER','POOL')
                AND a~tabname EQ lt_tab-tabname.
     ENDIF.

   ENDMETHOD.                    "find_tables

   METHOD export.

     DATA : lw_fields TYPE ty_fields.

     CALL METHOD zcl_excel=>export
       EXPORTING
         i_structure = lw_fields
       CHANGING
         c_tab       = gt_fields.

   ENDMETHOD.                    "export
ENDCLASS.                    "cl_fieldcommontablesfinder IMPLEMENTATION

START-OF-SELECTION.

   cl_fieldcommontablesfinder=>main( ).

Regards,

Freek

Read only

0 Likes
1,634

Thanks Freek!  That's just what I was thinking, and doubtless a much nicer program than I would have thrown together

The table version also seems useful, thanks.

Read only

0 Likes
1,634

Just for fun, here's my (very lazy) version (which requires you to update the where clause), which also tells you how many fields are in the structure and gives you any table types built against it, and filters out all the structures with more than 5 fields.

Based on the results for WERKS and NAME1, I'm thinking vanilla SAP developers needed this function years ago

REPORT ZDAVE_FIND_STRUCTURE.

TYPES: begin of ty_DD03L,
         TABNAME type TABNAME,
         FIELDNAME type FIELDNAME,
        end of ty_DD03L.


DATA :       lt_DD03L  type table of ty_DD03L,
              ls_DD03L  type ty_DD03L,
              lt_DD03L2 type table of ty_DD03L,
              lv_lines type i,
              lv_typename like DD40L-typename.

*get all structures with first field
select distinct d1~tabname INTO CORRESPONDING FIELDS OF TABLE lt_DD03L
  from DD03L as d1
  inner join DD02L as b on d1~tabname EQ b~tabname
  inner join DD03L as d2 on d1~tabname EQ d2~tabname
* WHERE d1~fieldname EQ 'WERKS' and d2~fieldname = 'NAME1'
  WHERE d1~fieldname EQ 'VTWEG' and d2~fieldname = 'VKORG'

  AND b~tabclass = 'INTTAB'.


loop at lt_DD03L into ls_DD03L.
   clear lt_DD03L2.
   select tabname fieldname into CORRESPONDING FIELDS OF TABLE lt_DD03L2  from DD03L where tabname = ls_DD03L-tabname.
   lv_lines = lines( lt_DD03L2 ).

   if lv_lines < 5.
     clear lv_typename.
     select single typename into lv_typename from DD40L where rowtype = ls_DD03L-tabname.
     write: / ls_DD03L-tabname, ls_DD03L-fieldname, lv_lines, lv_typename.
   endif.
ENDLOOP.

Read only

Former Member
0 Likes
1,634

You Can also get structure information to the respective filed using SE15 T-code same as which is suggested by raja above reply...

Regard's

Smruti