‎2007 Aug 02 10:08 AM
Hi friends,
i have created a view where i join 3 tables - is it possible to create a dynamic internal table based on that view as it is possible with standard tables from ddic ?
regards,
Clemens
‎2007 Aug 02 1:22 PM
Why you need a dynamic internal table if you can create internal table with ref to your view with simple statement
DATA itab TYPE TABLE OF view_name .Sorry if I sound absurd..
Message was edited by:
Pawan Kesari
‎2007 Aug 02 10:15 AM
‎2007 Aug 02 10:23 AM
Hi clemens,
1.
For this purpose,
in my program,
there is an INDEPENDENT FORM
whose inputs are
TABLE NAME / STRUCTURE NAME / VIEWNAME
and from those, it consructs dynamic table.
2. Here is the program.
the dynamic table name will be
<DYNTABLE>.
3. U can use this program (FORM in this program)
to generate any kind of internal table
by specifying TABLE NAME .
4.
REPORT abc.
*----
COMPULSORY
FIELD-SYMBOLS: <dyntable> TYPE ANY TABLE.
FIELD-SYMBOLS: <dynline> TYPE ANY.
DATA: lt TYPE lvc_t_fcat.
DATA: ls TYPE lvc_s_fcat.
FIELD-SYMBOLS: <fld> TYPE ANY.
DATA : fldname(50) TYPE c.
*----
parameters : iname LIKE dd02l-tabname.
*----
START-OF-SELECTION.
*----
PERFORM
PERFORM mydyntable USING lt.
BREAK-POINT.
*----
INDEPENDENT FORM
*----
FORM mydyntable USING ptabname.
*----
Create Dyn Table From FC
FIELD-SYMBOLS: <fs_data> TYPE REF TO data.
FIELD-SYMBOLS: <fs_1>.
FIELD-SYMBOLS: <fs_2> TYPE ANY TABLE.
DATA: lt_data TYPE REF TO data.
data : lt TYPE lvc_t_fcat .
DATA : ddfields LIKE ddfield OCCURS 0 WITH HEADER LINE.
*----
CALL FUNCTION 'DD_NAMETAB_TO_DDFIELDS'
EXPORTING
tabname = iname
TABLES
ddfields = ddfields.
.
*----
CONSTRUCT FIELD LIST
LOOP AT ddfields.
ls-fieldname = ddfields-fieldname.
APPEND ls TO lt.
ENDLOOP.
ASSIGN lt_data TO <fs_data>.
CALL METHOD cl_alv_table_create=>create_dynamic_table
EXPORTING
it_fieldcatalog = lt
IMPORTING
ep_table = <fs_data>
EXCEPTIONS
generate_subpool_dir_full = 1
OTHERS = 2.
IF sy-subrc <> 0.
ENDIF.
*----
Assign Dyn Table To Field Sumbol
ASSIGN <fs_data>->* TO <fs_1>.
ASSIGN <fs_1> TO <fs_2>.
ASSIGN <fs_1> TO <dyntable>.
ENDFORM. "MYDYNTABLE
regards,
amit m.
‎2007 Aug 02 1:09 PM
Hi Amit,
can i use this with a view ? And how to do it then ?
Clemens
‎2007 Aug 02 1:22 PM
Why you need a dynamic internal table if you can create internal table with ref to your view with simple statement
DATA itab TYPE TABLE OF view_name .Sorry if I sound absurd..
Message was edited by:
Pawan Kesari
‎2007 Aug 02 1:35 PM
Thank you for your comment, Pawan! The problem is, that the end-user will give the name of the view as parameter at runtime so i dont know it when developing the code. See the problem ?
Regards,
Clemens
‎2007 Aug 02 1:49 PM
hmm.... In that case Amit's reply will solve your problem...
Personally, I think below method can create dynamic internal table in any situation, you just need to fill 'it_fieldcatalog' properly....
CALL METHOD cl_alv_table_create=>create_dynamic_table
EXPORTING
it_fieldcatalog = lt_fieldcatalog
IMPORTING
ep_table = <fs_data>
EXCEPTIONS
generate_subpool_dir_full = 1
OTHERS = 2
Particularly in this case you can even create fieldcatelog automatically with FM
LVC_FIELDCATALOG_MERGEJust pass the view name in parameter I_STRUCTURE_NAME
‎2007 Aug 02 1:53 PM
Hi Clemens,
i hope the following code solves your problem:
PARAMETERS: p_tabnam LIKE dd02l-tabname.
DATA: ref_tab TYPE REF TO data.
field-symbols: <fs_itab> type any table.
create data ref_tab type standard table of (p_tabnam)
with default key.
assign ref_tab->* to <fs_itab>.
break-point.
Now you have with <fs_itab> an internal table with the structure of input parameter.
Kind Regards
Henner