Monday, December 20, 2010
This programs is used to create dynamic fieldcatat. We will give number of columns to be displayed on selection screen.

REPORT  ztest_notepad.
TYPE-POOLS:slis.
DATA: it_fcat      TYPE STANDARD TABLE OF lvc_s_fcat,
     it_fcatalog  TYPE STANDARD TABLE OF slis_fieldcat_alv,
     wa_fcat      TYPE lvc_s_fcat,
     wa_fcatalog  TYPE slis_fieldcat_alv.
DATA: it_dyn_tab   TYPE REF TO data,
     wa_newline   TYPE REF TO data.
FIELD-SYMBOLS:
     <gt_table>   TYPE STANDARD TABLE,
     <fs_dyntable>,
     <fs_fldval>  TYPE ANY,
     <l_field>    TYPE ANY.
DATA: l_fieldname  TYPE lvc_s_fcat-fieldname,
     l_fieldtext  TYPE lvc_s_fcat-seltext,
     l_index      TYPE char2.
PARAMETERS:columns   TYPE i.

START-OF-SELECTION.
  DEFINE fieldcat.
    wa_fcat-fieldname = &1.
    wa_fcat-tabname   = '<GT_TABLE>'.
    wa_fcat-seltext   = &2.
    append wa_fcat to it_fcat.
    clear  wa_fcat.
  END-OF-DEFINITION.
  DO  columns TIMES.
    CLEAR l_index.
    l_index = sy-index.
    CONCATENATE 'FIELD' l_index INTO l_fieldname.
    CONCATENATE 'Field' l_index INTO l_fieldtext.
    wa_fcat-fieldname = l_fieldname.
    wa_fcat-tabname   = '<GT_TABLE>'.
    wa_fcat-seltext   = l_fieldtext.
    APPEND wa_fcat TO it_fcat.
    CLEAR  wa_fcat.
  ENDDO.
  CALL METHOD cl_alv_table_create=>create_dynamic_table
    EXPORTING
      it_fieldcatalog = it_fcat
    IMPORTING
      ep_table        = it_dyn_tab.

  ASSIGN it_dyn_tab->* TO <gt_table>.
  CREATE DATA wa_newline LIKE LINE OF <gt_table>.
  ASSIGN wa_newline->* TO <fs_dyntable>.
  DO 20 TIMES.
    DO columns TIMES.
      l_index = sy-index.
      CONCATENATE 'FIELD' l_index INTO l_fieldname.
      ASSIGN COMPONENT l_fieldname OF STRUCTURE <fs_dyntable> TO <l_field>.
      <l_field> = sy-index.
    ENDDO.
    INSERT <fs_dyntable> INTO TABLE <gt_table>.
  ENDDO.
  LOOP AT it_fcat INTO wa_fcat.
    wa_fcatalog-fieldname = wa_fcat-fieldname.
    wa_fcatalog-tabname   = wa_fcat-tabname.
    wa_fcatalog-seltext_m = wa_fcat-seltext.
    APPEND wa_fcatalog TO it_fcatalog.
    CLEAR  wa_fcatalog.
  ENDLOOP.
  CALL FUNCTION 'REUSE_ALV_LIST_DISPLAY'
    EXPORTING
      i_callback_program = 'ZTEST_NOTEPAD'
      it_fieldcat        = it_fcatalog
    TABLES
      t_outtab           = <gt_table>.



2 comments:

Your useful comments, suggestions are appreciated.Your comments are moderated.

Followers

Contact Form

Name

Email *

Message *

Web Dynpro ABAP Book

An SAP Consultant

Follow US


Want to Contribute ?

If you are interested in writing about the new stuff you learn everyday while working, please write to the.sap.consultants@gmail.com.

Click on Contribution for more details.