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 control

Former Member
0 Likes
415

I have four containers in my final output.

TYPES: BEGIN OF GS_OUTTAB.

TYPES: CHECKBOX TYPE C. "field for checkbox

TYPES: CELLTAB TYPE LVC_T_STYL. "field to switch editability

INCLUDE STRUCTURE PA0001.

TYPES: END OF GS_OUTTAB.

Thats the final output table for the first container. How Can I do it dynamically for four different infotype tables. A field symbol for PA0001? Is that possible.

Please advice.

3 REPLIES 3
Read only

ravi_lanjewar
Contributor
0 Likes
384

Hi,

1) Create fieldcatlog of your define fields.

2) Pass the fieldcatlog to this function module REUSE_ALV_FIELDCATALOG_MERGE and Name of table structure of infotype you want.

It create dynamic fieldcatlog of your pass structure infotype.

Rgds

Ravi Lanjewar

Read only

kesavadas_thekkillath
Active Contributor
0 Likes
384

I have four containers in my final output.

A single container is enough, create the internal table dynamically and pass it.

This example might help you.

Please search in SCN , you will get lot of posts related to this( dynamic internal table )


 data:    wf_ref TYPE REF TO data,
     wf_line TYPE REF TO data.
   field-symbols:           <fs_tab> TYPE table,
              <fs_line> TYPE ANY.
  SELECT * FROM dd03l INTO TABLE i_dd03l WHERE tabname EQ wf_tab.
  IF sy-subrc EQ 0.
    SORT i_dd03l BY position ASCENDING.
    DELETE i_dd03l WHERE fieldname CP '.INCLU*'.
  ENDIF.

 LOOP AT i_dd03l ASSIGNING <fs_dd03l>.
    IF <fs_dd03l>-keyflag EQ abap_true.
      wa_cat-key = abap_true.
    ENDIF.
    wa_cat-fieldname = <fs_dd03l>-fieldname.
    wa_cat-col_pos = sy-tabix.
    wa_cat-inttype = <fs_dd03l>-inttype.
    wa_cat-datatype = <fs_dd03l>-datatype.
    wa_cat-intlen = <fs_dd03l>-intlen.
    wa_cat-seltext = <fs_dd03l>-fieldname.
    wa_cat-decimals = <fs_dd03l>-decimals.
    wa_cat-ref_field = <fs_dd03l>-fieldname.
    wa_cat-ref_table = wf_tab.
    APPEND wa_cat TO i_cat.
    CLEAR wa_cat.
 ENDLOOP.


 CALL METHOD cl_alv_table_create=>create_dynamic_table
    EXPORTING
      it_fieldcatalog = i_cat
    IMPORTING
      ep_table        = wf_ref.

  ASSIGN wf_ref->* TO <fs_tab>.
  ASSIGN wf_ref TO <fs_line>.


SELECT * FROM (wf_tab) INTO TABLE <fs_tab>.

  IF wf_event_handler IS INITIAL.
    CREATE OBJECT wf_event_handler.
  ENDIF.	

  IF wf_container IS INITIAL.
    CREATE OBJECT wf_container
      EXPORTING
        container_name = 'CONT'.

    CREATE OBJECT wf_grid
      EXPORTING
        i_parent = wf_container.
  ENDIF.

  CALL METHOD wf_grid->set_table_for_first_display
    EXPORTING
      i_structure_name     = wf_tab
      it_toolbar_excluding = i_exclude
      is_layout            = wa_layout
    CHANGING
      it_fieldcatalog      = i_cat
      it_outtab            = <fs_tab>.

Edited by: Keshav.T on May 19, 2010 6:35 PM

Read only

0 Likes
384

You only need a few lines to create a dynamic internal table...

DATA: dataref TYPE REF TO data.

FIELD-SYMBOLS: <fs_tab> TYPE ANY TABLE.

CREATE DATA dataref TYPE STANDARD TABLE OF (wf_tab).

ASSIGN dataref->* TO <fs_tab>.

Che Eky