Application Development 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: 

ALV dynamic list

Former Member
0 Kudos

Hi,

I am trying to modify a standard program that will generate the list of notifications ( QM15) , Before displaying the list , i insert a small code to modify the g_fieldcat_tab & object_tab to add some more dynamic colunms( we do know the amount of cols to add , this depends on some condition) into object_tab but i can not do this , because object_tab is a fix internal table .

I tried to use CALL METHOD cl_alv_table_create=>create_dynamic_table but i did not succeed ,

please help me out of this

If possible please give me a small line of code for doing this

Thanks

2 REPLIES 2

Former Member
0 Kudos

Hi Hoa,

plz go thru this code, it may be help you.

REPORT ZDYNAMIC_TABLE .

type-pools : abap.

field-symbols: <dyn_table> type standard table,

<dyn_wa>,

<dyn_field>.

data: dy_table type ref to data,

dy_line type ref to data,

xfc type lvc_s_fcat,

ifc type lvc_t_fcat.

selection-screen begin of block b1 with frame.

parameters: p_table(30) type c default 'T001'.

selection-screen end of block b1.

start-of-selection.

perform get_structure.

perform create_dynamic_itab.

perform get_data.

perform write_out.

form get_structure.

data : idetails type abap_compdescr_tab,

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( p_table ).

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.

endform.

form create_dynamic_itab.

  • Create dynamic internal table and assign to FS

call method cl_alv_table_create=>create_dynamic_table

exporting

it_fieldcatalog = ifc

importing

ep_table = dy_table.

assign dy_table->* to <dyn_table>.

  • Create dynamic work area and assign to FS

create data dy_line like line of <dyn_table>.

assign dy_line->* to <dyn_wa>.

endform.

form get_data.

  • Select Data from table.

select * into table <dyn_table>

from (p_table).

endform.

form write_out.

  • Write out data from table.

loop at <dyn_table> into <dyn_wa>.

do.

assign component sy-index

of structure <dyn_wa> to <dyn_field>.

if sy-subrc <> 0.

exit.

endif.

if sy-index = 1.

write:/ <dyn_field>.

else.

write: <dyn_field>.

endif.

enddo.

endloop.

endform.

Regards,

Vishvesh

If helpful, plz rewards it.

Former Member
0 Kudos

Hi,

Here is a quick example.

report zrich_0001.

type-pools: slis.

field-symbols: <dyn_table> type standard table,

<dyn_wa>.

data: it_alvfc type slis_t_fieldcat_alv,

wa_alvfc type slis_fieldcat_alv,

it_fldcat type lvc_t_fcat,

wa_fldcat type lvc_s_fcat.

selection-screen begin of block b1 with frame title text-001.

parameters: p_flds(5) type c.

selection-screen end of block b1.

start-of-selection.

build the dynamic internal table

perform build_dyn_itab.

write 5 records to the alv grid

do 5 times.

perform build_report.

enddo.

call the alv grid.

perform call_alv.

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

Build_dyn_itab

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

form build_dyn_itab.

Create the dynamic internal table

data: new_table type ref to data,

new_line type ref to data.

Create fields .

do p_flds times.

clear wa_fldcat.

wa_fldcat-fieldname = sy-index.

wa_fldcat-datatype = 'CHAR'.

wa_fldcat-intlen = 5.

append wa_fldcat to it_fldcat .

enddo.

Create dynamic internal table and assign to FS

call method cl_alv_table_create=>create_dynamic_table

exporting

it_fieldcatalog = it_fldcat

importing

ep_table = new_table.

assign new_table->* to <dyn_table>.

Create dynamic work area and assign to FS

create data new_line like line of <dyn_table>.

assign new_line->* to <dyn_wa>.

endform.

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

Form build_report

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

form build_report.

Fill some values into the dynamic internal table

data: fieldname(20) type c.

data: fieldvalue(5) type c.

data: index(3) type c.

field-symbols: <fs1>.

do p_flds times.

index = sy-index.

Set up fieldvalue

concatenate 'FLD' index into

fieldvalue.

condense fieldvalue no-gaps.

assign component index of structure <dyn_wa> to <fs1>.

<fs1> = fieldvalue.

enddo.

Append to the dynamic internal table

append <dyn_wa> to <dyn_table>.

endform.

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

CALL_ALV

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

form call_alv.

Build FC for ALV

loop at it_fldcat into wa_fldcat.

wa_alvfc-fieldname = wa_fldcat-fieldname.

wa_alvfc-seltext_s = sy-tabix.

wa_alvfc-outputlen = wa_fldcat-intlen.

append wa_alvfc to it_alvfc.

endloop.

Call ABAP List Viewer (ALV)

call function 'REUSE_ALV_GRID_DISPLAY'

exporting

it_fieldcat = it_alvfc

tables

t_outtab = <dyn_table>.

endform.

Reward Points if found helpfull..

Cheers,

Chandra Sekhar.