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 table with alv rows & colums

Former Member
0 Likes
651

Hey,

How to create dynamic internal table with alv grid rows & columns with data .

Hey,

How to create dynamic internal table with alv grid rows & columns with data .

4 REPLIES 4
Read only

Former Member
0 Likes
601

Hi,

Search on SCN.

Anyways see these links.

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

Thanks

Nitesh

Edited by: Nitesh Kumar on Dec 2, 2008 12:13 PM

Read only

former_member386202
Active Contributor
0 Likes
601

Hi,

Refer Below code

DO g_count TIMES.

CONDENSE g_cnt.

CONCATENATE 'F' g_cnt INTO wa_fcat-fieldname.

CONDENSE wa_fcat-fieldname.

wa_fcat-datatype = 'CHAR40'.

wa_fcat-intlen = 40.

APPEND wa_fcat TO it_fcat.

g_cnt = g_cnt + 1.

ENDDO.

*--Create dynamic internal table and assign to FS

CALL METHOD cl_alv_table_create=>create_dynamic_table

EXPORTING

it_fieldcatalog = it_fcat

IMPORTING

ep_table = dy_table.

ASSIGN dy_table->* TO <dyn_table>.

CREATE DATA dy_lines LIKE LINE OF <dyn_table>.

ASSIGN dy_lines->* TO <wa_dytab>.

Regards,

Prashant

Read only

Former Member
0 Likes
601

This message was moderated.

Read only

Former Member
0 Likes
601

TYPE-POOLS : abap.

FIELD-SYMBOLS: <f_dyn_table> TYPE STANDARD TABLE,

<f_dyn_wa>.

DATA: t_dy_table TYPE REF TO data,

dy_line TYPE REF TO data,

wa_xfc TYPE lvc_s_fcat,

t_ifc TYPE lvc_t_fcat.

*get the structure

DATA: $field TYPE lvc_fname,

$counter(2) TYPE n.

DATA: $output_field(25) TYPE c,

$fld_len TYPE i.

FIELD-SYMBOLS: <f_out_field> TYPE ANY.

DATA : $t_idetails TYPE abap_compdescr_tab,

$wa_xdetails TYPE abap_compdescr.

DATA : $ref_table_des TYPE REF TO cl_abap_structdescr.

    • get the structure of the table.*

$ref_table_des ?=

cl_abap_typedescr=>describe_by_name( c_struc ).

$t_idetails[] = $ref_table_des->components[].

LOOP AT $t_idetails INTO $wa_xdetails.

CLEAR: wa_xfc, $output_field, $fld_len.

wa_xfc-fieldname = $wa_xdetails-name .

wa_xfc-datatype = $wa_xdetails-type_kind.

wa_xfc-inttype = $wa_xdetails-type_kind.

IF $wa_xdetails-type_kind EQ 'C'

OR $wa_xdetails-type_kind EQ 'N'.

CONCATENATE 'WA_OUTTAB' '-' $wa_xdetails-name

INTO $output_field.

ASSIGN ($output_field) TO <f_out_field>.

IF <f_out_field> IS ASSIGNED.

DESCRIBE FIELD <f_out_field> LENGTH $fld_len

IN CHARACTER MODE.

wa_xfc-intlen = $fld_len.

ENDIF.

ELSE.

wa_xfc-intlen = $wa_xdetails-length.

ENDIF.

wa_xfc-decimals = $wa_xdetails-decimals.

APPEND wa_xfc TO t_ifc.

CLEAR $wa_xdetails.

ENDLOOP.

here if you have any other fields to be added to the dynamic structure based on your requirement, you can add then and apped them to t_ifc. There is a special handling for unicode conversion- so for the numc and char fields the length is passed in a different mothed.

    • create dynamic internal table and assign to fs*

CALL METHOD cl_alv_table_create=>create_dynamic_table

EXPORTING

it_fieldcatalog = t_ifc

i_length_in_byte = 'X'

IMPORTING

ep_table = t_dy_table

EXCEPTIONS

generate_subpool_dir_full = 1

OTHERS = 2.

IF sy-subrc <> 0.

ELSE.

ASSIGN t_dy_table->* TO <f_dyn_table>.

  • create dynamic work area and assign to fs

CREATE DATA dy_line LIKE LINE OF <f_dyn_table>.

ASSIGN dy_line->* TO <f_dyn_wa>.

ENDIF.

*move the data into <f_dyn_wa> and then append this to output table <f_dyn_table>.

example:-

IF <f_dyn_wa> IS ASSIGNED AND <f_dyn_table> IS ASSIGNED.

MOVE-CORRESPONDING wa_outtab TO <f_dyn_wa>.

APPEND <f_dyn_wa> TO <f_dyn_table>.

endif.

Edited by: Krishna Adabala on Dec 2, 2008 7:57 AM