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 ALV output

Former Member
0 Likes
1,519

Hi,

can anybody help me how to output an dynamic number of fields in the ALV?

Thank you...

regards,

mae

1 ACCEPTED SOLUTION
Read only

RichHeilman
Developer Advocate
Developer Advocate
0 Likes
1,283

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.

Regards,

Rich Heilman

Hi,

can anybody help me how to output an dynamic number of fields in the ALV?

Thank you...

regards,

mae

9 REPLIES 9
Read only

Former Member
0 Likes
1,283

The final Internal table that you pass to the function Module should be build dynamic.

Shreekant

Read only

0 Likes
1,283

hi,

can i have a sample code for that?

thank you...

regards,

mae

Read only

RichHeilman
Developer Advocate
Developer Advocate
0 Likes
1,284

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.

Regards,

Rich Heilman

Read only

0 Likes
1,283

*Hi friends;*

I tried one ALV Report Program.,Based on the input ,various storage location value will be dispalyed...

example : i will(statically) generate 30 output fields using filed catalog .

based on input, in 30 fields

some of the fields the value will be dispalyed..

remains the fields the value will be un filled.

i want to generate the fields dynamically, only the fields having values....

i searching the document in net ,using field symbol it may possible... but i not having idea in field symbol....

PLZ help me....

my mail id

[email protected]

Best regards

K.S.Kannan.

i think

Read only

former_member194669
Active Contributor
0 Likes
1,283

Hi,

You can do it without creating dynamic internal table by controlling the fields in the field catalog using NO_OUT,

Read only

0 Likes
1,283

*Hi friends;*

I tried one ALV Report Program.,Based on the input ,various storage location value will be dispalyed...

example : i will(statically) generate 30 output fields using filed catalog .

based on input, in 30 fields

some of the fields the value will be dispalyed..

remains the fields the value will be un filled.

i want to generate the fields dynamically, only the fields having values....

i searching the document in net ,using field symbol it may possible... but i not having idea in field symbol....

PLZ help me....

my mail id

[email protected]

Best regards

K.S.Kannan.

Read only

0 Likes
1,283

*Hi friends;*

I tried one ALV Report Program.,Based on the input ,various storage location value will be dispalyed...

example : i will(statically) generate 30 output fields using filed catalog .

based on input, in 30 fields

some of the fields the value will be dispalyed..

remains the fields the value will be un filled.

i want to generate the fields dynamically, only the fields having values....

i searching the document in net ,using field symbol it may possible... but i not having idea in field symbol....

PLZ help me....

my mail id

[email protected]

Best regards

K.S.Kannan.

Read only

Former Member
0 Likes
1,283

Hi Rich Heilman,

Thank you for your help...

regards,

mayang

Read only

Former Member
0 Likes
1,283

Hi,

How can i combine a static and a dynamic ALV?

thank you...

regards,

mae