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

dynamic internal table based on view ?

0 Likes
1,281

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

1 ACCEPTED SOLUTION
Read only

Pawan_Kesari
Active Contributor
0 Likes
947

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

7 REPLIES 7
Read only

Former Member
0 Likes
947

searchsap.techtarget.com/tip/0,289483,sid21_gci1250455,00.html

Read only

Former Member
0 Likes
947

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.

Read only

0 Likes
947

Hi Amit,

can i use this with a view ? And how to do it then ?

Clemens

Read only

Pawan_Kesari
Active Contributor
0 Likes
948

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

Read only

0 Likes
947

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

Read only

0 Likes
947

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_MERGE

Just pass the view name in parameter I_STRUCTURE_NAME

Read only

Former Member
0 Likes
947

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