Thursday 5 July 2012

To create the dynamic internal table in programs

To create the dynamic internal table we have to create one Ztable with all the field names and the sequence number and required information.

*Example
  typesbegin of ty_tdgt_prgm,
         program_name type ztdgt_prgm-program_name,
         field_name   type ztdgt_prgm-field_name,
         sequence_number type ztdgt_prgm-sequence_number,
         table_name type ztdgt_prgm-table_name,
         domain_name type ztdgt_prgm-domain_name,
         description type ztdgt_prgm-description,
       end of ty_tdgt_prgm.


  it_tdgt_prgm type standard table of ty_tdgt_prgm,
      wa_tdgt_prgm type ty_tdgt_prgm.


  select program_name
         field_name
         sequence_number
         table_name
         domain_name
         description
    from ztdgt_prgm
    into table it_tdgt_prgm
    for all entries in it_prgm_details
    where program_name = it_prgm_details-program_name.

      sort it_tdgt_prgm by sequence_number.


*Declerations
  data : it_fldcat type lvc_t_fcat,
       wa_fldcat like line of it_fldcat.


*We have to loop the table to create the structure.
*for every one loop it will add one field and the structure will remains in wa_qual_tab-table.
* we can use this structure by wa_qual_tab-table->* 

 
   loop at it_tdgt_prgm into wa_tdgt_prgm where program_name = wa_prgm_details-program_name.

      wa_fldcat-fieldname = wa_tdgt_prgm-field_name.
      wa_fldcat-tabname = wa_tdgt_prgm-table_name.

           append wa_fldcat to it_fldcat.

      call method cl_alv_table_create=>create_dynamic_table
        exporting
          it_fieldcatalog = it_fldcat
        importing
          ep_table        = wa_qual_tab-table.

    endloop.



*to use the dynamic structure created we have to do below.
   assign wa_qual_tab-table->* to <it_final>.
    import <it_final> from memory id 'memo1'.
  



No comments:

Post a Comment