Dynamically changing internal table in 'gui_download'

Hi Experts,
                 i have to download 4 internal tables, each with different structures, to the presentation server using 'gui_download', based on which radio-button is selected in the selection screen. I am hoping to use a single 'form' and 4 'perform' calls. how can I dynamically change the tables in the 'gui_download' function modules.
plz help.....................

Hi ,
Build the field catalog dynamically based on the internal table structure based on the radio button selected.Use the dynamic internal table generated from the filedcatalog and use in GUI_DOWNLOAD.
See the below code:
*& Report  ZRAJESH02
REPORT  zrajesh02.
Dynamic internal table
TYPE-POOLS: slis.
FIELD-SYMBOLS: <dyn_table> TYPE STANDARD TABLE,
              <dyn_wa>.
DATA: alv_fldcat TYPE slis_t_fieldcat_alv,
      it_fldcat TYPE lvc_t_fcat.
DATA: lv_monate TYPE f,
      lv_months TYPE i,
      lv_date TYPE sy-datum,
      p_check1 type n value '1'.
lv_date = sy-datum + 360.
SELECTION-SCREEN BEGIN OF BLOCK b1 WITH FRAME TITLE text-001.
PARAMETERS: p_check TYPE c.
SELECTION-SCREEN END OF BLOCK b1.
START-OF-SELECTION.
  CALL FUNCTION 'MONTHS_BETWEEN_TWO_DATES'
    EXPORTING
      i_datum_bis   = lv_date
      i_datum_von   = sy-datum
      i_kz_incl_bis = ' '
    IMPORTING
      e_monate      = lv_monate.
  lv_months = lv_monate.
  PERFORM f_fcat USING 'AUFNR' 'CHAR' '12'.
  PERFORM f_fcat USING 'POSNR' 'CHAR' '06'.
  while p_check1 LE p_check.
  PERFORM f_fcat USING p_check1 'CHAR' '1'.
  p_check1 = p_check1 + 1.
  endwhile.
  PERFORM build_dyn_itab.
  LOOP AT <dyn_table> INTO <dyn_wa>.
    WRITE:/ <dyn_wa>.
  ENDLOOP.
FORM f_fcat USING fieldname dattyp length.
  DATA:wa_it_fldcat TYPE lvc_s_fcat.
  CLEAR wa_it_fldcat.
  wa_it_fldcat-fieldname = fieldname.
  wa_it_fldcat-datatype = dattyp.
  wa_it_fldcat-intlen = length.
  APPEND wa_it_fldcat TO it_fldcat .
ENDFORM.                    "f_fcat
*&      Form  build_dyn_itab
      text
FORM build_dyn_itab.
  DATA: new_table TYPE REF TO data,
  new_line TYPE REF TO data.
wa_it_fldcat TYPE lvc_s_fcat.
CLEAR wa_it_fldcat.
wa_it_fldcat-fieldname = 'AUFNR'.
wa_it_fldcat-datatype = 'CHAR'.
wa_it_fldcat-intlen = 12.
APPEND wa_it_fldcat TO it_fldcat .
CLEAR wa_it_fldcat.
wa_it_fldcat-fieldname = 'POSNR'.
wa_it_fldcat-datatype = 'CHAR'.
wa_it_fldcat-intlen = 6.
APPEND wa_it_fldcat TO it_fldcat .
Create dynamic internal table and assign to FS
  CALL METHOD cl_alv_table_create=>create_dynamic_table
    EXPORTING
      it_fieldcatalog = it_fldcat
    IMPORTING
      ep_table        = new_table.
  ASSIGN new_table->* TO <dyn_table>.
Create dynamic work area and assign to FS
  CREATE DATA new_line LIKE LINE OF <dyn_table>.
  ASSIGN new_line->* TO <dyn_wa>.
ENDFORM.                    "build_dyn_itab
Thanks,
Rajesh.

Similar Messages

  • Change internal table structure dynamically

    Dear Experts , I have a requirement to add an attribute to already declared internal table which is declared in standard SAP code, is it possible to change internal table structure dynamically.
    my internal table is of type merel_t_grid2 which is standard table type in SAP , now I want to add an attribute of type  LVC_T_STYL in my internal table so that I can modify the cell property of ALV grid.
    I cant append LVC_T_STYL in standard structure because enhancement category of merel_t_grid2 is of type char and not deep
    my internal table contains data to be displayed in ALV.
    please help

    Dear Experts , I have a requirement to add an attribute to already declared internal table which is declared in standard SAP code, is it possible to change internal table structure dynamically.
    my internal table is of type merel_t_grid2 which is standard table type in SAP , now I want to add an attribute of type  LVC_T_STYL in my internal table so that I can modify the cell property of ALV grid.
    I cant append LVC_T_STYL in standard structure because enhancement category of merel_t_grid2 is of type char and not deep
    my internal table contains data to be displayed in ALV.
    please help

  • Uploading data from excel file to a dynamically created internal table

    Hi,
    I have a requirement where i have to upload data from an excel file into a database table. I would be able to determine the structure of the table only at runtime based on the user input.. so i have created an internal table dynamically.
    Could you please tell me if its possible to upload data from an excel file to the dynamically created internal table using any function modules?
    I thought of doing this by declaring a generic internal table of one field and then uploading the *.csv file into it and then splitting it based on "," and then assigning it to the field symbol referencing the internal table.. but my file length exceeds 132 characters and i'm only able to get data of lenght 132 char's in my internal table ( generic one).
    Could anyone please show me a way around this.
    Thanks in advance,
    Harsha

    Sure, check this out.
    report zrich_0002.
    type-pools: slis.
    field-symbols: <dyn_table> type standard table,
                   <dyn_wa>,
                   <dyn_field>.
    data: it_fldcat type lvc_t_fcat,
          wa_it_fldcat type lvc_s_fcat.
    type-pools : abap.
    data: new_table type ref to data,
          new_line  type ref to data.
    data: iflat type table of string.
    data: xflat type string.
      data: irec type table of string with header line.
      data: tabix type sy-tabix.
    data: file type string.
    selection-screen begin of block b1 with frame title text .
    parameters: p_file type  rlgrap-filename default 'c:Test.csv'.
    parameters: p_flds type i.
    selection-screen end of block b1.
    start-of-selection.
    * Add X number of fields to the dynamic itab cataelog
      do p_flds times.
        clear wa_it_fldcat.
        wa_it_fldcat-fieldname = sy-index.
        wa_it_fldcat-datatype = 'C'.
        wa_it_fldcat-inttype = 'C'.
        wa_it_fldcat-intlen = 10.
        append wa_it_fldcat to it_fldcat .
      enddo.
    * Create dynamic internal table and assign to FS
      call method cl_alv_table_create=>create_dynamic_table
                   exporting
                      it_fieldcatalog = it_fldcat
                   importing
                      ep_table        = new_table.
      assign new_table->* to <dyn_table>.
    * Create dynamic work area and assign to FS
      create data new_line like line of <dyn_table>.
      assign new_line->* to <dyn_wa>.
      file = p_file.
      call method cl_gui_frontend_services=>gui_upload
        exporting
          filename                = file
        changing
          data_tab                = iflat
        exceptions
          file_open_error         = 1
          file_read_error         = 2
          no_batch                = 3
          gui_refuse_filetransfer = 4
          invalid_type            = 5
          no_authority            = 6
          unknown_error           = 7
          bad_data_format         = 8
          header_not_allowed      = 9
          separator_not_allowed   = 10
          header_too_long         = 11
          unknown_dp_error        = 12
          access_denied           = 13
          dp_out_of_memory        = 14
          disk_full               = 15
          dp_timeout              = 16
          others                  = 17.
      loop at iflat into xflat.
        clear irec. refresh irec.
        split xflat at ',' into table irec.
        loop at irec.
          tabix = sy-tabix.
          assign component tabix of structure <dyn_wa> to <dyn_field>.
          <dyn_field> = irec.
        endloop.
        append <dyn_wa> to <dyn_table>.
      endloop.
    * Write out data from table.
      loop at <dyn_table> into <dyn_wa>.
        do.
          assign component  sy-index  of structure <dyn_wa> to <dyn_field>.
          if sy-subrc <> 0.
            exit.
          endif.
          if sy-index = 1.
            write:/ <dyn_field>.
          else.
            write: <dyn_field>.
          endif.
        enddo.
      endloop.
    Regards,
    Rich Heilman

  • How to create dynamic nested internal table

    Hi Experts,
    Pleae tell me or give sample code, how to create dynamic nested internal table ?
    I have seen threads saying creation of dynamic internal tables using some table structure only. But now the requirement is to create dynamic nested internal table.
    For example the internal table contains two fields viz., one is field1 of dynamic internal table and other is normal field2 and values as shown below:
    Nested internal table:
    field1                     |     field2 ...
    <table content1>     |     value2..
    <table content1>     |     value2..
    Here the [table content] should also a dynamic internal table.
    Let me know if you need any other info.
    regards
    Saravanan R

    see the complete code..i am currently working in ECC6.0 EHP4. just check which version you are using..
    REPORT  yst_test_000.
    DATA:
          lt_comptab         TYPE cl_abap_structdescr=>component_table,
          ls_comp            LIKE LINE OF lt_comptab,
          lref_newstr        TYPE REF TO cl_abap_structdescr,
          lref_tab_type      TYPE REF TO cl_abap_tabledescr,
          lt_fcat            TYPE lvc_t_fcat,
          ls_fcat            TYPE lvc_s_fcat,
          ls_dd03p           TYPE dd03p,
          lt_data            type ref to data.
    field-symbols: <fs_table> type standard table.
    CALL FUNCTION 'LVC_FIELDCATALOG_MERGE'
      EXPORTING
        i_structure_name       = 'SCARR'
      CHANGING
        ct_fieldcat            = lt_fcat
      EXCEPTIONS
        inconsistent_interface = 1
        program_error          = 2
        OTHERS                 = 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.
    LOOP AT lt_fcat INTO ls_fcat.
      IF ls_fcat-ref_table IS NOT INITIAL.
        CLEAR ls_dd03p.
        CALL FUNCTION 'BUS_DDFIELD_GET'
          EXPORTING
            i_tabnm         = ls_fcat-ref_table
            i_fldnm         = ls_fcat-fieldname
          IMPORTING
            e_dd03p         = ls_dd03p
          EXCEPTIONS
            field_not_found = 1
            OTHERS          = 2.
        IF sy-subrc EQ 0.
          ls_comp-name = ls_fcat-fieldname.
          ls_comp-type ?= cl_abap_datadescr=>describe_by_name( ls_dd03p-rollname ).
          APPEND ls_comp TO lt_comptab.
          CLEAR ls_comp.
        ENDIF.
      ELSE.
        ls_comp-name = ls_fcat-fieldname.
        ls_comp-type ?= cl_abap_datadescr=>describe_by_name( ls_fcat-rollname ).
        APPEND ls_comp TO lt_comptab.
        CLEAR ls_comp.
      ENDIF.
    ENDLOOP.
    *Now for the Field which you want deep table then you can do like this
    ls_fcat-fieldname  = 'NESTED_TABLE'.
    ls_fcat-inttype    = 'C'.
    ls_fcat-intlen     = '000006'.
    ls_fcat-rollname   = 'SFLIGHT_TAB1'. "For SFLIGHT
    APPEND ls_fcat TO lt_fcat.
    ls_comp-name = ls_fcat-fieldname.
    ls_comp-type ?= cl_abap_datadescr=>describe_by_name( ls_fcat-rollname ).
    APPEND ls_comp TO lt_comptab.
    CLEAR ls_comp.
    lref_newstr = cl_abap_structdescr=>create( lt_comptab ).
    lref_tab_type = cl_abap_tabledescr=>create( lref_newstr ).
    create data lt_data type handle lref_tab_type.
    assign lt_data->* to <fs_table>.
    break-point.
    Edited by: Vijay Babu Dudla on Apr 28, 2009 8:05 AM

  • Change internal table data in another program

    Hi Gurus,
    Is there a way to change internal table data from BADI of a method in main program using (SAPLV13A)db_xkondat[] internal table? Here SAPLV13A is main program name and db_xkondat[] is an internal table in the BADi call function.
    Thanks.
    Edited by: K V Subbarao on May 15, 2010 10:55 AM

    Hi,
    yes, you can use the trick with field symbols ( ASSIGN ('(PROGRAM)TABLE[]') TO <table> ). You just need to define field symbol with table type. Just be careful. Let say that this trick is not the proper way and you need to be extra careful.
    Cheers

  • Populating values in dynamically generated internal table

    Hi,
    We can generate internal tables dynamically and also populate them with values from database.But is there any way to populate the dynamically generated internal table(has 2-3 selected fields) with values from another internal table(has all fields required by the program) being populated within the same program?
    Thanks & Regards,
    Savitha

    Hi
    Dynamic internal table is internal table that we create on the fly with flexible column numbers.
    For sample code, please look at this code tutorial. Hopefully it can help you
    Check this link:
    http://www.****************/Tutorials/ABAP/DynamicInternaltable/DynamicInternalTable.htm
    Reward points if useful
    Regards
    Anji

  • Appending column to an dynamically created internal table

    Hi folks,
    i have an dynamically created internal table <dyn_tab> which is based on a parameter p_table (  containing the table name ). now i want to add one more column to this <dyn_tab> table where i can store further information in. how can i do that ?
    i appreciate your help!

    Hi,
    Please check this sample program.
    type-pools : abap.
    field-symbols: <dyn_table> type standard table,
                   <dyn_wa>,
                   <dyn_field>.
    data: dy_table type ref to data,
          dy_line  type ref to data,
          xfc type lvc_s_fcat,
          ifc type lvc_t_fcat.
    selection-screen begin of block b1 with frame.
    parameters: p_table(30) type c default 'T001'.
    selection-screen end of block b1.
    start-of-selection.
      perform get_structure.
      perform create_dynamic_itab.     
    form get_structure.
      data : idetails type abap_compdescr_tab,
           xdetails type abap_compdescr.
      data : ref_table_des type ref to cl_abap_structdescr.
      * Get the structure of the table.
      ref_table_des ?= 
          cl_abap_typedescr=>describe_by_name( p_table ).
      idetails[] = ref_table_des->components[].
        loop at idetails into xdetails.
        clear xfc.
        xfc-fieldname = xdetails-name .
        xfc-datatype = xdetails-type_kind.
        xfc-inttype = xdetails-type_kind.
        xfc-intlen = xdetails-length.
        xfc-decimals = xdetails-decimals.
        append xfc to ifc.
      endloop.
    *Add your new field(s) into table ifc here.
    endform.
    form create_dynamic_itab.
    * Create dynamic internal table and assign to FS
      call method cl_alv_table_create=>create_dynamic_table
                   exporting
                      it_fieldcatalog = ifc
                   importing
                      ep_table        = dy_table.
        assign dy_table->* to <dyn_table>.
      * Create dynamic work area and assign to FS
      create data dy_line like line of <dyn_table>.
      assign dy_line->* to <dyn_wa>.
    endform.
    Regards,
    Ferry Lianto

  • Use 3 internal table in GUI_Download

    Hello expert,
    i have 3 internal table: gt_header, gt_body and gt_footer. how can i used all 3 in gui_download fm. here is my sample code:
      CALL FUNCTION 'GUI_DOWNLOAD'
        EXPORTING
          filename              = gv_file_name
          filetype              = 'ASC'
        TABLES
          data_tab              = gt_header.
    here i can only pass one internal table.
    Help please?

    Hi Hassim,
    Maybe you can declare another internal table, with all fields is type C and length as you wanted.
    Loop those three itabs, append to this new itab. then call this FM download.
    regards,
    Archer

  • How to upload an excel to a dynamically generated internal table?

    Hi,
    I have an excel sheet. I have to create an internal table dynamically according to the fields of the excel sheet. The internal table i have created successfully, the fields are exactly coming as the excel sheet. I need to upload the excel sheet directly to my Internal table.
    Similar to the FM GUI_UPLOAD, which directly uploads the text document into the internal table
    I am not able to pass my dynamic internal table to the GUI_UPLOAD, The tables parameter in the GUI_UPLOAD is accepting only the standard tables.
    How to do?
    -Sudheer

    Hi,
    Use TEXT_CONVERT_XLS_TO_SAP  Function  Module.
    AWARD POINTS IF USEFUL

  • Passing Nested internal table to GUI_DOWNLOAD

    Hi All
    I have got a nested internal table, I want this whole report in excel format, I tried using GUI_DOWNLOAD , it gives error. Does any body have any idea how can I solve this.
    regards
    AJ

    Hi,
    I think nested and deep structure internal tables will not work with gui_download.
    you need to convert before giving it to gui_download
    aRs

  • How to select columns from internal table using 'GUI_DOWNLOAD' ?

    Hi,
    i am running a report & the fields for output is saved in an internal table which has as many as 10 fields. But I want to select only a few fields for output. There is a option COL_SELECT in function 'GUI_DOWNLOAD'. How to use it. If possible with example.

    Hai VijayKumar
    Try with the following code
    tables : mara.
    data : begin of it_mara occurs 0,
           matnr like mara-matnr,
           mbrsh like mara-mbrsh,
           mtart like mara-mtart,
           meins like mara-meins,
           end of it_mara.
    parameters : P_mtart like mara-mtart default 'ROH'.
    start-of-selection.
    perform select_data.
    perform download_data.
    *&      Form  select_data
          text
    -->  p1        text
    <--  p2        text
    FORM select_data .
    select
          matnr
          mbrsh
          mtart
          meins
          from mara into table it_mara
          where mtart = p_mtart.
    ENDFORM.                    " select_data
    *&      Form  download_data
          text
    -->  p1        text
    <--  p2        text
    FORM download_data .
    CALL FUNCTION 'GUI_DOWNLOAD'
      EXPORTING
        FILENAME                        = 'c:\down.txt'
        FILETYPE                        = 'ASC'
        COL_SELECT                      = 'X'
        COL_SELECT_MASK                 = 'X XX'
      TABLES
        DATA_TAB                        = it_mara.
      IF SY-SUBRC = 0.
        SORT IT_MARA BY MATNR.
      ENDIF.
    ENDFORM.                    " download_data
    Thanks & Regards
    Sreenivasulu P

  • How to delete a field from a Dynamically created internal table

    Hi friends,
    I have got a requirement in which, I will be entering the table name and Excel file from seletion-screen.
    based on the Table I have entered in the selection-screen I need to create a dynamic internal table so that I can fill that Execel data into that internal table and later i using BDC i can I can fill the database table using SM30 transaction.
    here. my problem is that, When I am creating internal table dynamically, MANDT filed is also getting created in the internal table.
    please, help in deleteing the filed MANDT from the internal able.
    following is the code which creates the dynamic internal table.
    CREATE DATA dy_table TYPE TABLE OF (p_tabname).
    assign dy_table->* to <dyn_table>.
    please provide, if any sample code is available.
    Regards,
    Xavier.P

    Hi,
    You can use this logic,
    While creating the Dynamic filed catalog try to avoid MANDT field.
    Ex:
    *Dynamic creation of a structure
      CREATE DATA LP_STRUCT TYPE (V_TABLE).
      ASSIGN LP_STRUCT->* TO <FS>.
    *Fields Structure
      OF_SDESCR ?= CL_ABAP_TYPEDESCR=>DESCRIBE_BY_DATA( <FS> ).
    LOOP AT OF_SDESCR->COMPONENTS ASSIGNING <COMPONENTS>.
    *Field MANDT not displayed
        IF SY-TABIX = 1 AND <COMPONENTS>-NAME = 'MANDT'.
          CONTINUE. " Next loop
        ENDIF.
    *Build Fieldcatalog
        LS_LVC_CAT-FIELDNAME = <COMPONENTS>-NAME.
        LS_LVC_CAT-REF_TABLE = V_TABLE.
        APPEND LS_LVC_CAT TO LT_LVC_CAT.
        CLEAR LS_LVC_CAT.
      ENDLOOP.

  • Passing values to dynamically created internal table

    Hi,
    I have the flat file data as
    f1,f2,f3........so on
    where f1 f2 and f3 are field names.
    I have a variable var which contains the data
    V1,0001,0002.........so on
    data: var type string.
    The value of field f1 is v1
    The value of field f2 is 0001
    The value of field f3 is 0002.......so on
    FIELD-SYMBOLS:     <fs_1> TYPE STANDARD TABLE
    I have dynamically created an internal table for fields f1  f2 f3 ...... using 
      CALL METHOD cl_alv_table_create=>create_dynamic_table
        EXPORTING
          it_fieldcatalog           = lt_fieldcatalog
        IMPORTING
          ep_table                  = <fs_data>
        EXCEPTIONS
          generate_subpool_dir_full = 1
          OTHERS                    = 2.
      IF sy-subrc <> 0.
      ENDIF.
    ASSIGN <fs_data>->* TO <fs_1>.
    Now for <fs_1> I have to pass the corresponding values of the fields f1 f2 f3 .
    How can i solve this.
    Thanks and regards ,
    Parvatha Reddy

    Hi,
    There is no data in <fs_1>.
    I need to pass the data form the string var to the fields of <fs_1>..
    I understand that you want to populate the internal table <fs_1>.
    for that you fist need work area.. use below statement to create work area..
    DATA: new_line TYPE REF TO data.
    CREATE DATA new_line LIKE LINE OF <fs_1>.
    ASSIGN new_line->*  TO <fs_2>.
    <fs_2> is not your work aread...
    to assign value to each field of you work aread <fs_2>. use statement
    ASSIGN COMPONENT 1 OF STRUCTURE <fs_2> TO <fs_3>.
    <fs_3> = f1 .
    now <fs_3> will point to the first field of work area <fs_2>, f1 is value from your string .. repeat above for each field in workarea, by increasing the component number. Once your work area is filled
    append it to table.
    append <fs_2> to <fs_1>
    apologies if I am not getting the requiremnt correctly..

  • Dynamic ALV Internal table Problem

    Hi all,I have successfully built an IT using method 'create_dynamic_table'.But my problems are :
    1)When Iam trying to select the data with multiple tables then it is short dumping.
    2)I tried to oselect the data using one table,after selecting the data if I use FM REUSE_ALV_Grid_Display then it is showing short dump with error 'type conflict when calling FM'.
    I never used field symbols before.PLZ complete my program or give me suffecient feedback.Here is my program :
    DATA : g_tdref TYPE REF TO data,
           g_wdref TYPE REF TO data.
    DATA : dats LIKE vbbe-mbdat,
           t_fieldcat TYPE lvc_t_fcat,
           wa_fieldcat TYPE lvc_s_fcat.
    FIELD-SYMBOLS : <it_dyn> TYPE STANDARD TABLE,
                    <wa_dyn>,
                    <dyn_field>.
    SELECTION-SCREEN BEGIN OF BLOCK blk1 WITH FRAME TITLE text-001.
    SELECT-OPTIONS : s_mbdat FOR dats.
    SELECTION-SCREEN END OF BLOCK blk1.
    wa_fieldcat-tabname = 'MSKA'.
    wa_fieldcat-fieldname = 'WERKS'.
    wa_fieldcat-datatype = 'CHAR'.
    wa_fieldcat-intlen = '10'.
    APPEND wa_fieldcat TO t_fieldcat.
    CLEAR : wa_fieldcat.
    wa_fieldcat-tabname = 'MSKA'.
    wa_fieldcat-fieldname = 'MATNR'.
    wa_fieldcat-datatype = 'CHAR'.
    wa_fieldcat-seltext = 'Material Number'.
    wa_fieldcat-intlen = '18'.
    APPEND wa_fieldcat TO t_fieldcat.
    CLEAR : wa_fieldcat.
    wa_fieldcat-tabname = 'MAKT'.
    wa_fieldcat-fieldname = 'MAKTX'.
    wa_fieldcat-datatype = 'CHAR'.
    wa_fieldcat-intlen = '10'.
    APPEND wa_fieldcat TO t_fieldcat.
    CLEAR : wa_fieldcat.
    wa_fieldcat-tabname = 'VBBE'.
    wa_fieldcat-fieldname = 'MBDAT'.
    wa_fieldcat-datatype = 'CHAR'.
    wa_fieldcat-intlen = '10'.
    APPEND wa_fieldcat TO t_fieldcat.
    CLEAR : wa_fieldcat.
    wa_fieldcat-tabname = 'VBBE'.
    wa_fieldcat-fieldname = 'OMENG'.
    wa_fieldcat-datatype = 'QUAN'.
    wa_fieldcat-intlen = '10'.
    APPEND wa_fieldcat TO t_fieldcat.
    CLEAR : wa_fieldcat.
    DATA : d TYPE i,
           v(02) TYPE n VALUE '0',
           day(8) TYPE c.
    d = s_mbdat-high - s_mbdat-low + 1.
    DO d TIMES.
      v = v + 1.
      CONCATENATE 'Day' v INTO day.
      wa_fieldcat-tabname = 'VBBE'.
      wa_fieldcat-fieldname = day.
      wa_fieldcat-datatype = 'DATS'.
      wa_fieldcat-seltext = day.
      wa_fieldcat-intlen = '8'.
      APPEND wa_fieldcat TO t_fieldcat.
      CLEAR : wa_fieldcat.
    ENDDO.
    *-----Building Dynamic internal table.
    CALL METHOD cl_alv_table_create=>create_dynamic_table
      EXPORTING
        it_fieldcatalog = t_fieldcat
      IMPORTING
        ep_table        = g_tdref.
    ASSIGN g_tdref->* TO <it_dyn>.
    CREATE DATA g_wdref LIKE LINE OF <it_dyn>.
    ASSIGN g_wdref->* TO <wa_dyn>.
    SELECT m~werks m~matnr v~omeng v~mbdat INTO CORRESPONDING FIELDS
    OF TABLE <it_dyn> FROM mska AS m INNER JOIN vbbe AS v
    ON m~posnr = v~posnr WHERE v~mbdat IN s_mbdat.

    *DATA : d TYPE i,
          v(02) TYPE n VALUE '0',
          day(8) TYPE c.
    *d = s_mbdat-high - s_mbdat-low + 1.
    *DO d TIMES.
    v = v + 1.
    CONCATENATE 'Day' v INTO day.
    wa_fieldcat-tabname = 'VBBE'.
    wa_fieldcat-fieldname = day.
    wa_fieldcat-datatype = 'DATS'.
    wa_fieldcat-seltext = day.
    wa_fieldcat-intlen = '8'.
    APPEND wa_fieldcat TO t_fieldcat.
    CLEAR : wa_fieldcat.
    *ENDDO.
    *-----Building Dynamic internal table.
    CALL METHOD cl_alv_table_create=>create_dynamic_table
      EXPORTING
        it_fieldcatalog = t_fieldcat
      IMPORTING
        ep_table        = g_tdref.
    ASSIGN g_tdref->* TO <it_dyn>.
    CREATE DATA g_wdref LIKE LINE OF <it_dyn>.
    ASSIGN g_wdref->* TO <wa_dyn>.
    SELECT OMENG FROM VBBE INTO CORRESPONDING FIELDS OF TABLE <IT_DYN> WHERE MBDAT IN S_MBDAT.
    BREAK-POINT.
    YOU WILL GET VALUES IN INTERNAL TABLE.
    TO SOLVE YOUR ISSUE YOU SHOULD USE NUM INSTEAD OF DATS.

  • Reg:doubt in dynamic generated internal table

    hi everyone,
                 i generated a internal table dynamically,the output is in fied symbol,i want to create a internal table using the field symbol sturture,how to create that????
    plz tell me how to create a internal table referencing field symbol structure........
    very urgent plz help.........
    thanks in advance....
    regards,
    balaji.s

    Hi ,
           check out   a small part of an alv report which is using dynamic internal table
    data: dy_table type ref to data,
          dy_line type ref to data.
    field-symbols: <dyn_table> type standard table,
                   <dyn_wa> type any,
                   <dyn_line> type any.
        call method cl_alv_table_create=>create_dynamic_table
          exporting
            it_fieldcatalog = ifc
          importing
            ep_table        = dy_table.
        assign dy_table->* to <dyn_table>.
    CREATE A DYNAMIC WORK AREA.
        create data dy_line like line of <dyn_table>.
        sort it_mard by matnr werks.
        loop at it_mard into wa_mard.
          at new matnr.
            assign dy_line->* to <dyn_wa>.
            assign component 'MATNR' of structure <dyn_wa> to <dyn_line>.
            <dyn_line> = wa_mard-matnr.
            read table it_mard2 into wa_mard1 with key matnr = wa_mard-matnr.
            v_amount = wa_mard1-v_total * p_unit.
            call function 'SPELL_AMOUNT'
              exporting
                amount = v_amount
           currency        = 'INR'
      FILLER          = ' '
            language        = sy-langu
          importing
            in_words        = v_price
          exceptions
            not_found       = 1
            too_large       = 2
            others          = 3
            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 component 'V_TOTAL' of structure <dyn_wa> to <dyn_line>.
            <dyn_line> = wa_mard1-v_total.
            assign component 'V_PRICE' of structure <dyn_wa> to <dyn_line>.
            <dyn_line> = v_price-word.
          endat.
          concatenate 'STOCK' '-' 'IN' '-' wa_mard-werks into v_new.
          assign component v_new of structure <dyn_wa> to <dyn_line>.
          <dyn_line> = wa_mard-labst.
          at end of matnr.
            append <dyn_wa> to <dyn_table>.
            clear wa_mard.
            clear <dyn_wa>.
            unassign <dyn_line>.
            unassign <dyn_wa>.
          endat.
        endloop.
    rewards points if helpful.

Maybe you are looking for