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

how to make dynamic grid

hi

i want to make dynamic grid i m getting column header data in structure and geting value in output table .

i want to put structure value as header of column its not fix its dynamic

so can any one suggest me .

thanks.

Add a comment
10|10000 characters needed characters exceeded

Assigned Tags

Related questions

2 Answers

  • author's profile photo Former Member
    Former Member
    Posted on Sep 21, 2007 at 06:51 AM

    Hi,

    for this you have to create a dynamic itab and on the basis of that you have to make the fieldcatalogue...

    use this code for help.

    * STEP: 1 - get backend field catalog (currently displayed alv)
    
      CLEAR: tl_fieldcatalog. REFRESH: tl_fieldcatalog.
    
      CALL METHOD w_grid->get_backend_fieldcatalog
    
      IMPORTING
    
        et_fieldcatalog = tl_fieldcatalog.
    
     
    
    * STEP: 2 - create a new fieldcatalog for dynamic internal table
    
      CLEAR: sl_fieldcatalog.
    
      CLEAR: t_outtab_fieldname. REFRESH: t_outtab_fieldname.
    
      CLEAR: tl_fieldcatalog_new. REFRESH: tl_fieldcatalog_new.
    
      CLEAR: t_download_fieldname. REFRESH: t_download_fieldname.
    
      CLEAR: t_download_fieldheading. REFRESH: t_download_fieldheading.
    
      LOOP AT tl_fieldcatalog INTO sl_fieldcatalog.
    
     
    
    *   STEP: 2.1 - populate data in T_OUTTAB_FIELDNAME
    
        APPEND sl_fieldcatalog-fieldname TO t_outtab_fieldname.
    
     
    
    *   STEP: 2.2 - populate TL_FIELDCATALOG_NEW & T_DOWNLOAD_FIELDNAME
    
        IF sl_fieldcatalog-no_out EQ ''.
    
     
    
          IF sl_fieldcatalog-fieldname NE 'STATUS'
    
          OR sl_fieldcatalog-fieldname NE 'MESG_STATUS'
    
          OR sl_fieldcatalog-fieldname NE 'ZLOCK'
    
          OR sl_fieldcatalog-fieldname NE 'T_PLANT'
    
          OR sl_fieldcatalog-fieldname NE 'T_CSR'.
    
     
    
    *         If field is COMM_PLANT, change its length
    
            IF sl_fieldcatalog-fieldname EQ 'COMM_PLANT'.
    
              sl_fieldcatalog-outputlen = 1800.
    
              sl_fieldcatalog-intlen = 1800.
    
              sl_fieldcatalog-dd_outlen = 1800.
    
            ENDIF.    "comm_plant
    
     
    
            sl_fieldcatalog_new = sl_fieldcatalog.
    
            APPEND sl_fieldcatalog_new TO tl_fieldcatalog_new.
    
            APPEND sl_fieldcatalog-fieldname TO t_download_fieldname.
    
            APPEND sl_fieldcatalog-scrtext_l TO t_download_fieldheading.
    
            CLEAR: sl_fieldcatalog, sl_fieldcatalog_new.
    
          ENDIF.
    
     
    
        ENDIF.
    
      ENDLOOP.
    
     
    
    * STEP: 3 - create dynamic internal table
    
      FREE: ref_download.
    
      CALL METHOD cl_alv_table_create=>create_dynamic_table
    
        EXPORTING
    
    *      I_STYLE_TABLE             =
    
          it_fieldcatalog           = tl_fieldcatalog_new
    
        IMPORTING
    
          ep_table                  = ref_download
    
    *      E_STYLE_FNAME             =
    
        EXCEPTIONS
    
          generate_subpool_dir_full = 1
    
          OTHERS                    = 2
    
              .
    
      IF sy-subrc <> 0.
    
        MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
    
                   WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
    
      ENDIF.
    
      ASSIGN ref_download->* TO <ft_download>.
    
     
    
      CREATE DATA ref_wa LIKE LINE OF <ft_download>.
    
      ASSIGN ref_wa->* TO <fs_download>.
    
     
    
    * STEP: 4 - populate data in dynamic internal table
    
      LOOP AT t_outtab INTO wa_outtab.
    
     
    
        LOOP AT t_download_fieldname.
    
          ASSIGN COMPONENT t_download_fieldname OF STRUCTURE
    
                           <fs_download> TO <fs_download_field>.
    
     
    
          IF t_download_fieldname-field EQ 'COMM_PLANT'.
    
     
    
    *             STEP: 4.1 - get long text from database table
    
            CLEAR: wal_table.
    
            SELECT SINGLE * FROM zshaven_plnt_txt
    
                            INTO wal_table
    
                            WHERE vbeln   = wa_outtab-vbeln
    
                            AND   posnr   = wa_outtab-posnr
    
                            AND   del_no  = wa_outtab-del_no
    
                            AND   del_itm = wa_outtab-del_itm.
    
     
    
            IF sy-subrc EQ 0.
    
     
    
    *                 STEP: 4.2 - break long-text into separate lines
    
              CLEAR: tl_text. REFRESH: tl_text.
    
              SPLIT wal_table-plant_comm
    
                    AT '~'
    
                    INTO TABLE tl_text.
    
     
    
    *                 STEP: 4.3 - Combine these separate lines with space in
    
    *                             between two lines
    
              CLEAR: wal_text, final_text.
    
              LOOP AT tl_text INTO wal_text.
    
                IF final_text IS INITIAL.
    
                  final_text = wal_text.
    
                ELSE.
    
                  CONCATENATE final_text '-' wal_text
    
                      INTO final_text.
    
                  REPLACE '-' WITH ' ' INTO final_text.
    
                ENDIF.
    
              ENDLOOP.
    
     
    
    *             STEP: 4.4  - move long text to work-area
    
              <fs_download_field> = final_text.
    
     
    
            ENDIF.    "subrc
    
     
    
          ELSE.    "t_download_fieldname
    
            READ TABLE t_outtab_fieldname
    
                WITH KEY field = t_download_fieldname-field.
    
            ASSIGN COMPONENT t_outtab_fieldname-field OF STRUCTURE
    
                             wa_outtab TO <fs_outtab_field>.
    
     
    
            <fs_download_field> = <fs_outtab_field>.
    
          ENDIF.
    
        ENDLOOP.
    
    *     STEP: 4.5 - Move data from work-area to dynamic internal table
    
        APPEND <fs_download> TO <ft_download>.
    
        CLEAR: <fs_download>.
    
      ENDLOOP.
    
     
    
    * STEP: 5 - download
    
     
    
      CALL FUNCTION 'DOWNLOAD'
    
           EXPORTING
    
                filename                = 'C:zshaven.xls'
    
                filetype                = 'DAT'
    
                filetype_no_show        = 'X'
    
                filetype_no_change      = 'X'
    
           TABLES
    
                data_tab                = <ft_download>
    
                fieldnames              = t_download_fieldheading
    
           EXCEPTIONS
    
                invalid_filesize        = 1
    
                invalid_table_width     = 2
    
                invalid_type            = 3
    
                no_batch                = 4
    
                unknown_error           = 5
    
                gui_refuse_filetransfer = 6
    
                customer_error          = 7
    
                OTHERS                  = 8.
    
      IF sy-subrc <> 0.
    
        MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
    
              WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
    
      ENDIF.
    
     
    

    reward if helpful

    vivekanand

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Sep 21, 2007 at 07:00 AM

    hi,

    i have done a similar report,

    iam sending u exmaple,

    first while building fieldcat, u give the name of the field (column ) as the value of the internal table.

    example:

    loop at it_models.

    LS_LVCFIELDCAT-FIELDNAME = IT_models-MODELS.

    LS_LVCFIELDCAT-SELTEXT = IT_models-MODELS.

    LS_LVCFIELDCAT-COLTEXT = IT_models-MODELS.

    LS_LVCFIELDCAT-outputlen = 8.

    LS_LVCFIELDCAT-SP_GROUP = 'A'.

    APPEND LS_LVCFIELDCAT TO LT_LVCFIELDCAT.

    CLEAR:LS_LVCFIELDCAT.

    ENDLOOP.

    declare variables

    DATA: DREF TYPE REF TO DATA,WA_REF TYPE REF TO DATA.

    FIELD-SYMBOLS: <TEMP_TAB> TYPE TABLE, <TEMP_WA> TYPE ANY.

    use the following method.

    CALL METHOD CL_ALV_TABLE_CREATE=>CREATE_DYNAMIC_TABLE

    EXPORTING

    IT_FIELDCATALOG = LT_LVCFIELDCAT

    IMPORTING

    EP_TABLE = DREF.

    ASSIGN dref->* TO <TEMP_TAB>.

    now u need to fill the <temp_tab>

    example:

    FORM FILL_DYN_TAB .

    CREATE DATA WA_REF LIKE LINE OF <TEMP_TAB>.

    ASSIGN WA_REF->* TO <TEMP_WA>.

    LOOP AT IT_ITAB.

    MOVE-CORRESPONDING IT_ITAB TO <TEMP_WA>.

    APPEND <TEMP_WA> TO <TEMP_TAB>.

    CLEAR IT_ITAB.

    ENDLOOP.

    ENDFORM. " FILL_DYN_TAB

    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.