<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Dynamic ALV in Application Development and Automation Discussions</title>
    <link>https://community.sap.com/t5/application-development-and-automation-discussions/dynamic-alv/m-p/4088765#M977691</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I am working on an a alv report.In the selection screen,if the fiscal period is input based on that the dates have to be calculated and have to be displayed as column headers in the o/p.This colum is dynamic and will change based on the values given in the selection screen.Now I need to populate the values for these dates under the corresponding columns respectively.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Can anyone tell me how can I achieve this?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Regards,&lt;/P&gt;&lt;P&gt;Hema&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Thu, 26 Jun 2008 12:11:48 GMT</pubDate>
    <dc:creator>Former Member</dc:creator>
    <dc:date>2008-06-26T12:11:48Z</dc:date>
    <item>
      <title>Dynamic ALV</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/dynamic-alv/m-p/4088765#M977691</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I am working on an a alv report.In the selection screen,if the fiscal period is input based on that the dates have to be calculated and have to be displayed as column headers in the o/p.This colum is dynamic and will change based on the values given in the selection screen.Now I need to populate the values for these dates under the corresponding columns respectively.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Can anyone tell me how can I achieve this?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Regards,&lt;/P&gt;&lt;P&gt;Hema&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 26 Jun 2008 12:11:48 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/dynamic-alv/m-p/4088765#M977691</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2008-06-26T12:11:48Z</dc:date>
    </item>
    <item>
      <title>Re: Dynamic ALV</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/dynamic-alv/m-p/4088766#M977692</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;hi check this..&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;REPORT  Z_DYNALV                                     .&lt;/P&gt;&lt;P&gt;*Type pools declaration for ALV&lt;/P&gt;&lt;P&gt;TYPE-POOLS: SLIS.   " ALV Global Types*data declaration for dynamic internal table and alv&lt;/P&gt;&lt;P&gt;DATA:     L_STRUCTURE   TYPE REF TO DATA,&lt;/P&gt;&lt;P&gt;          L_TABLE    TYPE REF TO DATA,&lt;/P&gt;&lt;P&gt;          STRUC_DESC   TYPE REF TO CL_ABAP_STRUCTDESCR,&lt;/P&gt;&lt;P&gt;          LT_LAYOUT   TYPE SLIS_LAYOUT_ALV,&lt;/P&gt;&lt;P&gt;          LS_LVC_FIELDCATALOGUE  TYPE LVC_S_FCAT,&lt;/P&gt;&lt;P&gt;          LT_LVC_FIELDCATALOGUE  TYPE LVC_T_FCAT,&lt;/P&gt;&lt;P&gt;          LS_FIELDCATALOGUE TYPE SLIS_FIELDCAT_ALV,&lt;/P&gt;&lt;P&gt;          LT_FIELDCATALOGUE TYPE SLIS_T_FIELDCAT_ALV.&lt;/P&gt;&lt;P&gt;*field symbols declaration&lt;/P&gt;&lt;P&gt;FIELD-SYMBOLS :&lt;/P&gt;&lt;P&gt;  &amp;lt;IT_TABLE&amp;gt;    TYPE STANDARD TABLE,&lt;/P&gt;&lt;P&gt;  &amp;lt;DYN_STR&amp;gt;         TYPE ANY,&lt;/P&gt;&lt;P&gt;  &amp;lt;STR_COMP&amp;gt; TYPE ABAP_COMPDESCR.&lt;/P&gt;&lt;P&gt;*declarations for grid title&lt;/P&gt;&lt;P&gt;DATA : T1(30),&lt;/P&gt;&lt;P&gt;       T2(10),&lt;/P&gt;&lt;P&gt;       T3(50).&lt;/P&gt;&lt;P&gt;*selection screen declaration for table input&lt;/P&gt;&lt;P&gt;PARAMETERS : P_TABLE LIKE DD02L-TABNAME.&lt;/P&gt;&lt;P&gt;*initialization event&lt;/P&gt;&lt;P&gt;INITIALIZATION.&lt;/P&gt;&lt;P&gt;*start of selection event&lt;/P&gt;&lt;P&gt;START-OF-SELECTION.&lt;/P&gt;&lt;P&gt;*texts for grid title&lt;/P&gt;&lt;P&gt;  T1 = 'Dynamic ALV display for table'.&lt;/P&gt;&lt;P&gt;  T2 = P_TABLE.  CONCATENATE T1 T2 INTO T3 SEPARATED BY SPACE.&lt;/P&gt;&lt;UL&gt;&lt;LI level="1" type="ul"&gt;&lt;P&gt;Dynamic creation of a structure&lt;/P&gt;&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;  CREATE DATA L_STRUCTURE TYPE (P_TABLE).&lt;/P&gt;&lt;P&gt;  ASSIGN L_STRUCTURE-&amp;gt;* TO &amp;lt;DYN_STR&amp;gt;.&lt;/P&gt;&lt;UL&gt;&lt;LI level="1" type="ul"&gt;&lt;P&gt;Fields Structure&lt;/P&gt;&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;  STRUC_DESC ?= CL_ABAP_TYPEDESCR=&amp;gt;DESCRIBE_BY_DATA( &amp;lt;DYN_STR&amp;gt; ).&lt;/P&gt;&lt;P&gt;  LOOP AT STRUC_DESC-&amp;gt;COMPONENTS ASSIGNING &amp;lt;STR_COMP&amp;gt;.&lt;/P&gt;&lt;UL&gt;&lt;LI level="1" type="ul"&gt;&lt;P&gt;  Build Fieldcatalog&lt;/P&gt;&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;    LS_LVC_FIELDCATALOGUE-FIELDNAME = &amp;lt;STR_COMP&amp;gt;-NAME.&lt;/P&gt;&lt;P&gt;    LS_LVC_FIELDCATALOGUE-REF_TABLE = P_TABLE.&lt;/P&gt;&lt;P&gt;    APPEND LS_LVC_FIELDCATALOGUE TO LT_LVC_FIELDCATALOGUE.&lt;/P&gt;&lt;UL&gt;&lt;LI level="1" type="ul"&gt;&lt;P&gt;  Build Fieldcatalog&lt;/P&gt;&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;    LS_FIELDCATALOGUE-FIELDNAME = &amp;lt;STR_COMP&amp;gt;-NAME.&lt;/P&gt;&lt;P&gt;    LS_FIELDCATALOGUE-REF_TABNAME = P_TABLE.&lt;/P&gt;&lt;P&gt;    APPEND LS_FIELDCATALOGUE TO LT_FIELDCATALOGUE.&lt;/P&gt;&lt;P&gt;  ENDLOOP.&lt;/P&gt;&lt;UL&gt;&lt;LI level="1" type="ul"&gt;&lt;P&gt;Create internal table dynamic&lt;/P&gt;&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;  CALL METHOD CL_ALV_TABLE_CREATE=&amp;gt;CREATE_DYNAMIC_TABLE&lt;/P&gt;&lt;P&gt;    EXPORTING&lt;/P&gt;&lt;P&gt;      IT_FIELDCATALOG = LT_LVC_FIELDCATALOGUE&lt;/P&gt;&lt;P&gt;    IMPORTING&lt;/P&gt;&lt;P&gt;      EP_TABLE        = L_TABLE.&lt;/P&gt;&lt;P&gt;      ASSIGN L_TABLE-&amp;gt;* TO &amp;lt;IT_TABLE&amp;gt;.&lt;/P&gt;&lt;UL&gt;&lt;LI level="1" type="ul"&gt;&lt;P&gt;Read data from the table selected.&lt;/P&gt;&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;  SELECT * FROM (P_TABLE)&lt;/P&gt;&lt;P&gt;    INTO CORRESPONDING FIELDS OF TABLE &amp;lt;IT_TABLE&amp;gt;.&lt;/P&gt;&lt;UL&gt;&lt;LI level="1" type="ul"&gt;&lt;P&gt;ALV Layout&lt;/P&gt;&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;  LT_LAYOUT-ZEBRA = 'X'.&lt;/P&gt;&lt;P&gt;  LT_LAYOUT-COLWIDTH_OPTIMIZE = 'X'.&lt;/P&gt;&lt;P&gt;  LT_LAYOUT-WINDOW_TITLEBAR = T3.&lt;/P&gt;&lt;P&gt;*ALV  output&lt;/P&gt;&lt;P&gt;  CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'&lt;/P&gt;&lt;P&gt;    EXPORTING&lt;/P&gt;&lt;P&gt;      IS_LAYOUT     = LT_LAYOUT&lt;/P&gt;&lt;P&gt;      IT_FIELDCAT   = LT_FIELDCATALOGUE&lt;/P&gt;&lt;P&gt;    TABLES&lt;/P&gt;&lt;P&gt;      T_OUTTAB      = &amp;lt;IT_TABLE&amp;gt;&lt;/P&gt;&lt;P&gt;    EXCEPTIONS&lt;/P&gt;&lt;P&gt;      PROGRAM_ERROR = 1&lt;/P&gt;&lt;P&gt;      OTHERS        = 2.&lt;/P&gt;&lt;P&gt;  IF SY-SUBRC &amp;lt;&amp;gt; 0.&lt;/P&gt;&lt;UL&gt;&lt;LI level="1" type="ul"&gt;&lt;P&gt;MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO&lt;/P&gt;&lt;/LI&gt;&lt;LI level="1" type="ul"&gt;&lt;P&gt;        WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.&lt;/P&gt;&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;  ENDIF.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 26 Jun 2008 12:13:47 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/dynamic-alv/m-p/4088766#M977692</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2008-06-26T12:13:47Z</dc:date>
    </item>
    <item>
      <title>Re: Dynamic ALV</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/dynamic-alv/m-p/4088767#M977693</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt; Refer to the code in the following code.&lt;/P&gt;&lt;P&gt; &lt;A href="http://saptechnical.com/Tutorials/ALV/DynamicALV/Demo.htm" target="test_blank"&gt;http://saptechnical.com/Tutorials/ALV/DynamicALV/Demo.htm&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;It may be useful ..&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Regards,&lt;/P&gt;&lt;P&gt;Jaya Vani&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 26 Jun 2008 12:15:22 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/dynamic-alv/m-p/4088767#M977693</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2008-06-26T12:15:22Z</dc:date>
    </item>
    <item>
      <title>Re: Dynamic ALV</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/dynamic-alv/m-p/4088768#M977694</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;check this.. sample code..&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;REPORT  ztest_dynamic_code.


TYPES: BEGIN OF ty_data,

        abc(3),
        xyz(3),
        pqr(3),
        item1,
        item2,
        item3,
        item4,
        item5,
        item6,
        item7,
        item8,
        item9,
      END OF ty_data.

DATA: BEGIN OF it_tab OCCURS 0,
       abc(3),
       xyz(3),
       pqr(3),
       item,
     END OF it_tab.

DATA: it_fieldcatalog  TYPE lvc_t_fcat,
wa_fieldcat TYPE lvc_s_fcat.


DATA:  i_dyntab  TYPE REF TO data. " To create dyn.Itab
DATA:
       w_dref TYPE REF TO data,
       ind(2) TYPE n,
       w_data TYPE REF TO data,
       w_text(5),
       w_grid TYPE REF TO cl_gui_alv_grid.
DATA: grid TYPE REF TO cl_gui_alv_grid,
      cont TYPE REF TO cl_gui_custom_container.

FIELD-SYMBOLS: &amp;lt;t_itab&amp;gt; TYPE STANDARD TABLE,
               &amp;lt;fs_wa&amp;gt; TYPE ANY,&amp;lt;fs&amp;gt; TYPE ANY.
DATA: in TYPE i.


*Data population

it_tab-abc = 'ABC'.
it_tab-xyz = 'XYZ'.
it_tab-pqr = 'PQR'.
DO 9 TIMES.
  in = in + 1.
  it_tab-item = in.
  APPEND it_tab.
ENDDO.

*Field cat population.
wa_fieldcat-fieldname = 'ABC'.
wa_fieldcat-outputlen = 3.
wa_fieldcat-coltext = 'abc'.
APPEND wa_fieldcat TO it_fieldcatalog.

wa_fieldcat-fieldname = 'XYZ'.
wa_fieldcat-outputlen = 3.
wa_fieldcat-coltext = 'XYZ'.
APPEND wa_fieldcat TO it_fieldcatalog.

wa_fieldcat-fieldname = 'PQR'.
wa_fieldcat-outputlen = 3.
wa_fieldcat-coltext = 'pqr'.
APPEND wa_fieldcat TO it_fieldcatalog.
ind = 1.
DO 9 TIMES.
  CONCATENATE 'ITEM' ind INTO wa_fieldcat-fieldname.
  CONCATENATE 'ITEM' ind INTO wa_fieldcat-coltext.
  wa_fieldcat-outputlen = 1.
  APPEND wa_fieldcat TO it_fieldcatalog.
  CLEAR wa_fieldcat .
  ind  = ind + 1.
ENDDO.


*-Dynamic Table creation
CALL METHOD cl_alv_table_create=&amp;gt;create_dynamic_table
  EXPORTING
    it_fieldcatalog = it_fieldcatalog
  IMPORTING
    ep_table        = i_dyntab.

ASSIGN i_dyntab-&amp;gt;* TO &amp;lt;t_itab&amp;gt;.
CREATE DATA w_data LIKE LINE OF &amp;lt;t_itab&amp;gt;.
ASSIGN w_data-&amp;gt;* TO &amp;lt;fs_wa&amp;gt;.

SORT it_tab BY abc xyz pqr.
CLEAR ind.
ind = 4.

*-Final Internal table as per Requirement
LOOP AT it_tab.

  ASSIGN COMPONENT 1 OF STRUCTURE &amp;lt;fs_wa&amp;gt; TO &amp;lt;fs&amp;gt;.
  &amp;lt;fs&amp;gt; = it_tab-abc.
  ASSIGN COMPONENT 2 OF STRUCTURE &amp;lt;fs_wa&amp;gt; TO &amp;lt;fs&amp;gt;.
  &amp;lt;fs&amp;gt; = it_tab-xyz.
  UNASSIGN &amp;lt;fs&amp;gt;.
  ASSIGN COMPONENT 3 OF STRUCTURE &amp;lt;fs_wa&amp;gt; TO &amp;lt;fs&amp;gt;.
  &amp;lt;fs&amp;gt; = it_tab-pqr.
  UNASSIGN &amp;lt;fs&amp;gt;.

  ASSIGN COMPONENT ind OF STRUCTURE &amp;lt;fs_wa&amp;gt; TO &amp;lt;fs&amp;gt;.

  &amp;lt;fs&amp;gt; = it_tab-item.
  UNASSIGN &amp;lt;fs&amp;gt;.
  ind = ind + 1.

  AT END OF pqr.

    APPEND &amp;lt;fs_wa&amp;gt; TO &amp;lt;t_itab&amp;gt;.
    ind = 4.
    CLEAR &amp;lt;fs_wa&amp;gt;.

  ENDAT.

ENDLOOP.

*-Display

CALL SCREEN 100.


*&amp;amp;---------------------------------------------------------------------*
*&amp;amp;      Module  STATUS_0100  OUTPUT
*&amp;amp;---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
MODULE status_0100 OUTPUT.
  DATA: layout TYPE lvc_s_layo.

  CREATE OBJECT cont
     EXPORTING
       container_name              = 'CONT'
     EXCEPTIONS
       cntl_error                  = 1
       cntl_system_error           = 2
       create_error                = 3
       lifetime_error              = 4
       lifetime_dynpro_dynpro_link = 5
       OTHERS                      = 6
       .
  IF sy-subrc NE 0.
    MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
               WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
  ENDIF.

  CREATE OBJECT grid
    EXPORTING
      i_parent          = cont
    EXCEPTIONS
      error_cntl_create = 1
      error_cntl_init   = 2
      error_cntl_link   = 3
      error_dp_create   = 4
      OTHERS            = 5
      .
  IF sy-subrc NE 0.
    MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
               WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
  ENDIF.
  grid-&amp;gt;set_table_for_first_display(
     EXPORTING
       is_layout                      =  layout
     CHANGING
       it_outtab                     = &amp;lt;t_itab&amp;gt;
       it_fieldcatalog               = it_fieldcatalog
   EXCEPTIONS
     invalid_parameter_combination = 1
     program_error                 = 2
     too_many_lines                = 3
          ).
  IF sy-subrc  NE 0.
    MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
               WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
  ENDIF.


ENDMODULE.                 " STATUS_0100  OUTPUT&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 26 Jun 2008 12:15:48 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/dynamic-alv/m-p/4088768#M977694</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2008-06-26T12:15:48Z</dc:date>
    </item>
  </channel>
</rss>

