Skip to Content
author's profile photo Former Member
Former Member

Dynamic ALv

Hi Gurus,

I want to create Dynamic Alv using Grid Layout. Can anyone sent me the sample code.

Regards,

Bhuvana.

Add a comment
10|10000 characters needed characters exceeded

Assigned Tags

Related questions

3 Answers

  • author's profile photo Former Member
    Former Member
    Posted on Sep 18, 2008 at 07:30 AM

    Hi,

    Check this link

    https://blogs.sap.com/?p=42904

    Regards,

    Anirban

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Sep 18, 2008 at 08:38 AM

    Hi,

    Just run this sample code you will get an idea of how to go about while creating any type of Dynamic ALV report.

    type-pools: slis.

    field-symbols: <dyn_table> type standard table,

    <dyn_wa>.

    data: alv_fldcat type slis_t_fieldcat_alv,

    it_fldcat type lvc_t_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.

    data: new_table type ref to data,

    new_line type ref to data,

    wa_it_fldcat type lvc_s_fcat.

    *Create fields .

    clear wa_it_fldcat.

    wa_it_fldcat-fieldname = 'name1'.

    wa_it_fldcat-datatype = 'mara-matnr'.

    wa_it_fldcat-intlen = 5.

    append wa_it_fldcat to it_fldcat .

    *

    *clear wa_it_fldcat.

    wa_it_fldcat-fieldname = sy-index.

    wa_it_fldcat-datatype = 'CHAR'.

    wa_it_fldcat-intlen = 5.

    append wa_it_fldcat to it_fldcat .

    *

    do p_flds times.

    clear wa_it_fldcat.

    wa_it_fldcat-fieldname = sy-index.

    wa_it_fldcat-datatype = 'CHAR'.

    wa_it_fldcat-intlen = 6.

    append wa_it_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.

    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.

    data: wa_cat like line of alv_fldcat.

    do p_flds times.

    clear wa_cat.

    wa_cat-fieldname = sy-index.

    wa_cat-seltext_s = sy-index.

    wa_cat-outputlen = '6'.

    append wa_cat to alv_fldcat.

    enddo.

    *Call ABAP List Viewer (ALV)

    call function 'REUSE_ALV_GRID_DISPLAY'

    exporting

    it_fieldcat = alv_fldcat

    tables

    t_outtab = <dyn_table>.

    endform.

    Also check the following link might help you.

    interanl-table-output-problem

    With best wishes,

    Murthy.

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Sep 19, 2008 at 04:56 PM

    Hi,

    Check the following steps.

    Steps:-

    1. Create your field catalog either manually or automatically using the function module, LVC_FIELDCATALOG_MERGE. Add more rows to the field catalog table (T_FIELDCAT) at run time.

    2. Use the field catalog to create a table dynamically using the method below.

    DATA: T_OUTPUT TYPE REF TO DATA 
    FIELD-SYMBOLS: <T_OUTPUT> TYPE TABLE 
    
    Call Method CL_ALV_TABLE_CREATE->CREATE_DYNAMIC_TABLE 
       Exporting 
          IT_FIELDCATALOG = T_FIELDCAT 
       Importing 
          EP_TABLE = T_OUTPUT. 
    
    ASSIGN T_OUTPUT->* TO <T_OUTPUT>.

    Now the field symbol <T_OUTPUT> is pointing to an output table of the structure that contains the fields which were determined at runtime. Now fill this table with the data and pass <T_OUTPUT> to the method SET_TABLE_FOR_FIRST_DISPLAY and the ALV grid should show the data properly.

    Example:

    * the content of itab will be fields of the new table
    loop at itab1 into wa1.
      Gs_FIELDCAT-TABNAME     = 'itab2'.
      GS_FIELDCAT-FIELDNAME = wa1-packid.
      GS_FIELDCAT-OUTPUTLEN = 2.
      GS_FIELDCAT-KEY         = space.
      GS_FIELDCAT-SELTEXT_L = wa1-packid.
      GS_FIELDCAT-COL_POS     =  1.
      GS_FIELDCAT-JUST        = 'L'.
      APPEND GS_FIELDCAT TO GT_FIELDCAT.
    endloop.
    
     LOOP AT GT_FIELDCAT INTO GS_FIELDCAT.
         MOVE-CORRESPONDING GS_FIELDCAT TO ls_fcat.
         APPEND ls_fcat TO lt_fieldcat.
     ENDLOOP.
    
    CALL METHOD cl_alv_table_create=>create_dynamic_table
           EXPORTING
                it_fieldcatalog = lt_fieldcat
           IMPORTING 
                ep_table = t_output.

    Fill the dynamic internal table with the data.

    Now pass the fieldcatalog and internal table to the FM or method.

    Hope this helps.

    Regards,

    Kinshuk

    Add a comment
    10|10000 characters needed characters exceeded

Before answering

You should only submit an answer when you are proposing a solution to the poster's problem. If you want the poster to clarify the question or provide more information, please leave a comment instead, requesting additional details. When answering, please include specifics, such as step-by-step instructions, context for the solution, and links to useful resources. Also, please make sure that you answer complies with our Rules of Engagement.
You must be Logged in to submit an answer.

Up to 10 attachments (including images) can be used with a maximum of 1.0 MB each and 10.5 MB total.