Skip to Content
0
Former Member
Jan 05, 2007 at 06:48 AM

how to populate data in dynamic internal table

30 Views

Hi Expert,

fyi. My dynamic internal table field is created base on data selected. Eg. select table qpcd has 5 records. These 5 recods will become fieldname to my dynamic internal table. My dynamic internal table will be

...itab

01

02

03

04

05

The 5 records from qpcd is populated in another table call viqmel. I need to find the occurance of each code in viqmel and populate the number of occurance in itab in each of column. The final dynamic itab will be like this

table itab

01 02 03 04 05 -


> field name

2 0 1 0 1 -


> data

my source code like below

-


Report ZPLYGRND2.

TABLES: mara, makt.

TYPE-POOLS: slis, sydes.

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.

types : begin of t_qpcd,

codegruppe like qpcd-codegruppe,

code like qpcd-code,

end of t_qpcd.

data:wa_qpcd type t_qpcd,

i_qpcd type standard table of t_qpcd initial size 0.

FIELD-SYMBOLS: <l_table> TYPE table,

<l_line> TYPE ANY,

<l_field> TYPE ANY.

select * into corresponding fields of wa_qpcd from qpcd

where katalogart = 'D'

and codegruppe = 'OOT01'.

append wa_qpcd to i_qpcd.

endselect.

loop at i_qpcd into wa_qpcd.

is_fcat-fieldname = wa_qpcd-code.

APPEND is_fcat TO it_fcat.

endloop.

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.

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.

if sy-subrc = 0.

endif.

*... 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>.

LOOP AT <l_table> INTO <l_line>.

ENDLOOP.

-