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

Create dynamic internal table from another internal table

Former Member
0 Likes
1,085

Hi experts,

My requirement is to create one internal table dynamically based upon the number of entries of a field of another internal table and display all the entries in a single line using alv. Problem is no. of entries of that field varies time by time.

I've used method cl_alv_table_create=>create_dynamic_table , but the problem is here:

TYPES: BEGIN OF gty_qamv,

PRUEFLOS TYPE QPLOS,

VERWMERKM TYPE QMERKNR,

END OF gty_qamv.

data: gt_qamv TYPE TABLE OF gty_qamv,

gs_qamv TYPE gty_qamv.

data : ref_table_des type ref to cl_abap_structdescr.

ref_table_des = ??? . (what I've to pass here)

cl_abap_typedescr=>describe_by_name( ??? ) . (what I've to pass here)

idetails[] = ref_table_des->components[].

LOOP AT idetails INTO xdetails.

CLEAR xfc.

xfc-fieldname = xdetails-name .

xfc-datatype = xdetails-type_kind.

xfc-inttype = xdetails-type_kind.

xfc-intlen = xdetails-length.

xfc-decimals = xdetails-decimals.

APPEND xfc TO ifc.

ENDLOOP.

CALL METHOD cl_alv_table_create=>create_dynamic_table

EXPORTING

it_fieldcatalog = ifc

IMPORTING

ep_table = dy_table.

iF sy-subrc <> 0.

  • MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO

  • WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.

ENDIF.

ASSIGN dy_table->* TO <dyn_table>.

CREATE DATA dy_line LIKE LINE OF <dyn_table>.

ASSIGN dy_line->* TO <dyn_wa>.

I've to track how many MICs are there in the itab gt_qamv according to that Lot No.

Can anybody send any sample code or program for this issue?

Thanks in Inadvance.

Goutam

6 REPLIES 6
Read only

Former Member
0 Likes
1,012

Hi Goutam,

http://wiki.sdn.sap.com/wiki/display/Snippets/Programfordynamictabledisplay



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.


Read only

0 Likes
1,012

Hi Pravin,

Thanks for the help. But your code is for the dynamic table to fetch the data from db to itab .

My requirement is to arrange all MICs in one line according to Lot no which I've fetch in another itab before. I know how to arrange these but don't know how to arrange dynamically. B'cos the MIC may differ from 3 to 100.

Give some logic, how can I increase the number of fields of itab dynamically so that I can arrange all the MICs in one line?

Thnaks in Advance.

Goutam

Read only

0 Likes
1,012

Hi Goutam,

Actually I din't understand completely your requirement. So I tried to simulate your problem of making an internal table having same no. of columns as of another internal table having same no. of rows. Hope it helps.

Please copy paste the below code snippet to any report and execute. <fs_tab> will hold the no. of columns as many CONNID s are fetched from SFLIGHT.

*********************************

TYPES: BEGIN OF ty_connid,

connid TYPE s_conn_id,

END OF ty_connid,

ty_t_connid TYPE STANDARD TABLE OF ty_connid.

DATA: i_connid TYPE ty_t_connid,

wa_connid TYPE ty_connid,

i_fldcat TYPE lvc_t_fcat,

wa_fldcat TYPE lvc_s_fcat,

v_cnt TYPE char2,

i_tab TYPE REF TO data.

FIELD-SYMBOLS: <fs_tab> TYPE STANDARD TABLE.

SELECT connid

FROM sflight

INTO TABLE i_connid.

LOOP AT i_connid INTO wa_connid.

v_cnt = sy-tabix.

CONCATENATE 'CONNID' v_cnt INTO wa_fldcat-fieldname.

wa_fldcat-datatype = 'NUMC'.

wa_fldcat-inttype = 'NUMC'.

wa_fldcat-intlen = 4.

APPEND wa_fldcat TO i_fldcat.

ENDLOOP.

CALL METHOD cl_alv_table_create=>create_dynamic_table

EXPORTING

it_fieldcatalog = i_fldcat

IMPORTING

ep_table = i_tab.

IF sy-subrc EQ 0.

  • MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO

  • WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.

ENDIF.

ASSIGN i_tab->* TO <fs_tab>.

IF sy-subrc EQ 0.

ENDIF.

****************

Thanks,

Mainak

Read only

anversha_s
Active Contributor
0 Likes
1,012

This message was moderated.

Read only

Marcal_Oliveras
Active Contributor
0 Likes
1,012

Edited

Edited by: Marshal on Dec 15, 2009 1:51 PM

Read only

Former Member
0 Likes
1,012

Hi Goutham,

Please check the below links to get an idea about how to create dynamic internal table.

[http://wiki.sdn.sap.com/wiki/display/Snippets/DynamicInternalTable]

[http://wiki.sdn.sap.com/wiki/display/Snippets/DynamicInternalTablehttp://wiki.sdn.sap.com/wiki/display/ABAP/DynamicInternaltablehttp://wiki.sdn.sap.com/wiki/display/Snippets/dynamicinternaltableallfieldshttp://wiki.sdn.sap.com/wiki/display/Snippets/Creatingadynamicinternaltablebasedondata|http://wiki.sdn.sap.com/wiki/display/Snippets/DynamicInternal+Table]