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

Former Member
0 Likes
409

Hi all,

I have internable of type slis_** .

in which i have the details about the fields to be created.

using this how can i create a dynamic internal table.

thanks alot .

1 ACCEPTED SOLUTION
Read only

anversha_s
Active Contributor
0 Likes
372

Hi,

check this sample code.

TABLES: mara, makt.

TYPE-POOLS: slis.

DATA: it_fcat

TYPE slis_t_fieldcat_alv,

is_fcat LIKE LINE OF it_fcat,

ls_layout TYPE slis_layout_alv.

DATA: it_fieldcat TYPE lvc_t_fcat,

is_fieldcat LIKE LINE OF

it_fieldcat.

DATA: new_table TYPE REF TO data,

new_line TYPE REF TO data,

ob_cont_alv TYPE REF TO cl_gui_custom_container,

ob_alv TYPE REF TO cl_gui_alv_grid,

vg_campos(255) TYPE c,

i_campos LIKE TABLE OF vg_campos,

vg_campo(30) TYPE c,

vg_tables(60) TYPE c.

*DATA: e_params LIKE zutsvga_alv_01.

FIELD-SYMBOLS: <l_table> TYPE table,

<l_line> TYPE ANY,

<l_field> TYPE ANY.

PARAMETERS: p_max(2) TYPE n DEFAULT '20' OBLIGATORY.

is_fcat-fieldname = 'COL01'.

is_fcat-ref_fieldname = 'MATNR'.

is_fcat-ref_tabname = 'MARA'.

APPEND is_fcat TO it_fcat.

is_fcat-fieldname = 'COL02'.

is_fcat-ref_fieldname = 'MAKTX'.

is_fcat-ref_tabname = 'MAKT'.

APPEND is_fcat TO it_fcat.



LOOP AT it_fcat INTO is_fcat.

is_fieldcat-fieldname = is_fcat-fieldname.

is_fieldcat-ref_field = is_fcat-ref_fieldname.

is_fieldcat-ref_table = is_fcat-ref_tabname.

APPEND is_fieldcat TO it_fieldcat.

CONCATENATE is_fieldcat-ref_table is_fieldcat-ref_field INTO

vg_campos SEPARATED BY '~'.

APPEND vg_campos TO i_campos.

ENDLOOP.

*... Create the dynamic internal table

CALL METHOD cl_alv_table_create=>create_dynamic_table

EXPORTING

it_fieldcatalog = it_fieldcat

IMPORTING

ep_table = new_table.

*... Create a new line

ASSIGN new_table->* TO <l_table>.

CREATE DATA new_line LIKE LINE OF <l_table>.

ASSIGN new_line->* TO <l_line>.

SELECT (i_campos) FROM mara INNER JOIN makt ON mara~matnr = makt~matnr

UP TO P_MAX ROWS INTO TABLE <l_table>.

describe table <l_table>.

write :/ sy-tfill.



LOOP AT <l_table> INTO <l_line>.

LOOP AT it_fcat INTO is_fcat.

ASSIGN COMPONENT is_fcat-fieldname OF STRUCTURE <l_line> TO <l_field>.

IF sy-tabix = 1.

WRITE: /2 <l_field>.

ELSE.

WRITE: <l_field>.

ENDIF.

ENDLOOP.

ENDLOOP.
.

some helpful links.

See the below links for more programs:-

<u>http://searchsap.techtarget.com/tip/1,289483,sid21_gci912390,00.html

http://www.sap-img.com/ab030.htm</u>;

Regards

Anver

<i><b>if hlped pls mark points</b></i>

3 REPLIES 3
Read only

Former Member
0 Likes
372

Hi rajini,

1.

For this purpose,

in my program,

<b> there is an INDEPENDENT FORM</b>

whose inputs are

<b> LIST OF FIELDS, (just as u require)</b>

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 list of fields.

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.

DATA : ddfields LIKE ddfield OCCURS 0 WITH HEADER LINE.

*----


START-OF-SELECTION.

*----


field list

ddfields-fieldname = 'BUKRS'.

APPEND DDFIELDS.

ddfields-fieldname = 'MATNR'.

APPEND DDFIELDS.

*----


PERFORM mydyntable .

*----


see <DYNTABLE> in debug mode.

BREAK-POINT.

*----


  • INDEPENDENT FORM

*----


FORM mydyntable .

*----


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 .

*----


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
372

Check these blogs,

SAP Developer Network Blog: Dynamic Internal Tables and Structures - ABAP

Check these blogs,

/people/rich.heilman2/blog/2005/07/27/dynamic-internal-tables-and-structures--abap

/people/subramanian.venkateswaran2/blog/2004/11/19/dynamic-internal-table

kishan negi

Read only

anversha_s
Active Contributor
0 Likes
373

Hi,

check this sample code.

TABLES: mara, makt.

TYPE-POOLS: slis.

DATA: it_fcat

TYPE slis_t_fieldcat_alv,

is_fcat LIKE LINE OF it_fcat,

ls_layout TYPE slis_layout_alv.

DATA: it_fieldcat TYPE lvc_t_fcat,

is_fieldcat LIKE LINE OF

it_fieldcat.

DATA: new_table TYPE REF TO data,

new_line TYPE REF TO data,

ob_cont_alv TYPE REF TO cl_gui_custom_container,

ob_alv TYPE REF TO cl_gui_alv_grid,

vg_campos(255) TYPE c,

i_campos LIKE TABLE OF vg_campos,

vg_campo(30) TYPE c,

vg_tables(60) TYPE c.

*DATA: e_params LIKE zutsvga_alv_01.

FIELD-SYMBOLS: <l_table> TYPE table,

<l_line> TYPE ANY,

<l_field> TYPE ANY.

PARAMETERS: p_max(2) TYPE n DEFAULT '20' OBLIGATORY.

is_fcat-fieldname = 'COL01'.

is_fcat-ref_fieldname = 'MATNR'.

is_fcat-ref_tabname = 'MARA'.

APPEND is_fcat TO it_fcat.

is_fcat-fieldname = 'COL02'.

is_fcat-ref_fieldname = 'MAKTX'.

is_fcat-ref_tabname = 'MAKT'.

APPEND is_fcat TO it_fcat.



LOOP AT it_fcat INTO is_fcat.

is_fieldcat-fieldname = is_fcat-fieldname.

is_fieldcat-ref_field = is_fcat-ref_fieldname.

is_fieldcat-ref_table = is_fcat-ref_tabname.

APPEND is_fieldcat TO it_fieldcat.

CONCATENATE is_fieldcat-ref_table is_fieldcat-ref_field INTO

vg_campos SEPARATED BY '~'.

APPEND vg_campos TO i_campos.

ENDLOOP.

*... Create the dynamic internal table

CALL METHOD cl_alv_table_create=>create_dynamic_table

EXPORTING

it_fieldcatalog = it_fieldcat

IMPORTING

ep_table = new_table.

*... Create a new line

ASSIGN new_table->* TO <l_table>.

CREATE DATA new_line LIKE LINE OF <l_table>.

ASSIGN new_line->* TO <l_line>.

SELECT (i_campos) FROM mara INNER JOIN makt ON mara~matnr = makt~matnr

UP TO P_MAX ROWS INTO TABLE <l_table>.

describe table <l_table>.

write :/ sy-tfill.



LOOP AT <l_table> INTO <l_line>.

LOOP AT it_fcat INTO is_fcat.

ASSIGN COMPONENT is_fcat-fieldname OF STRUCTURE <l_line> TO <l_field>.

IF sy-tabix = 1.

WRITE: /2 <l_field>.

ELSE.

WRITE: <l_field>.

ENDIF.

ENDLOOP.

ENDLOOP.
.

some helpful links.

See the below links for more programs:-

<u>http://searchsap.techtarget.com/tip/1,289483,sid21_gci912390,00.html

http://www.sap-img.com/ab030.htm</u>;

Regards

Anver

<i><b>if hlped pls mark points</b></i>