Problem creating an internal table dynamically

Hi,
I'm trying to create an internal table dynamically as i would be able to determine the structure of the table based on the user input.
I've used the sample code from this forum ...
REPORT  ZRICH_0003       .
type-pools: slis.
field-symbols: <dyn_table> type standard table,
               <dyn_wa>,
               <dyn_field>.
data: alv_fldcat type slis_t_fieldcat_alv,
               it_fldcat type lvc_t_fcat.
               type-pools : abap.
data : it_details type abap_compdescr_tab,
       wa_details type abap_compdescr.
data : ref_descr type ref to cl_abap_structdescr.
data: new_table type ref to data,
      new_line  type ref to data,
      wa_it_fldcat type lvc_s_fcat.
      selection-screen begin of block b1 with frame title text.
parameters: p_table(30) type c.
selection-screen end of block b1.
Get the structure of the table.
ref_descr ?= cl_abap_typedescr=>describe_by_name( p_table ).
it_details[] = ref_descr->components[].
loop at it_details into wa_details.
  clear wa_it_fldcat.
  wa_it_fldcat-fieldname = wa_details-name .
  wa_it_fldcat-datatype = wa_details-type_kind.
  wa_it_fldcat-inttype = wa_details-type_kind.
  wa_it_fldcat-intlen = wa_details-length.
  wa_it_fldcat-decimals = wa_details-decimals.
  append wa_it_fldcat to it_fldcat .
  endloop.
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>.
<b>* Select Data from table.
select * into table <dyn_table>           from
(p_table).</b>
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.
I'm able to get the structure of the table that i want, but when i'm trying to select data from the table into this internal table..as highlighted in the sample code above..i'm getting a short dump...saying that ' the database table is 600 bytes wide but the internal table is only 576 bytes wide.
The internal table is declared as
field-symbols: <dyn_table> type standard table..
Could anyone please tell me how to rectify this.
Thanks in advance,
Harsha.

Hi Smitha,
I'm building the internal table by getting the structure using the method
cl_abap_typedescr=>describe_by_name( p_table ).
where p_table is the table name determined dynamically..
Now using this structure, i'm building an internal table by calling the method
call method cl_alv_table_create=>create_dynamic_table
I've checked all the fields after the internal table has been created .. and it contains all the fields of the table that i'm supplying initially..
But when i read data into that internal table, it gives me that dump..I've described it in this post earlier.
Any more suggestions would be very helpful.
Thanks,
Harsha

Similar Messages

  • Create internal table dynamically for IDoc fields

    Hi,
    I need to create an internal table dynamically based on the segment field names that are returned in the table pt_fields when calling function 'IDOCTYPE_READ_COMPLETE'.  I see many posts suggesting classes such as 'cl_wrf_dynamic_table=>create_dynamic_table', but it does not work for me.  The problem I have with the classes is that it doesn't allow you to have the same column name more than once.  But in the scenario I am testing, I have some column names that are duplicated, and I cannot remove the duplicates.  Are there any functions or classes that I can use to create a dynamic internal table that will not check if a column name is used twice?
    Thanks,
    Carrie

    Hello Carrie
    My first thought was that RTTI might be able to do this but it does not (see the dump below). And it is obvious that RTTI behave likes this.
    Error analysis
        An exception occurred which is explained in detail below.
        The exception, which is assigned to class 'CX_SY_STRUCT_COMP_NAME', was not
         caught and
        therefore caused a runtime error.
        The reason for the exception is:
        Multiple Specification of the Name 'CUSTOMER' as a Component Name (Component 7)
    Just think about any way  to define statically an itab or structure containing duplicated field names. You will always get a syntax error irrespective of whether you use a DDIC structure, a TYPE or a DATA variable.
    If there is no way to define such a structure statically why should it be different when defining dynamically?
    Regards
      Uwe

  • How to fill internal table dynamically

    Hi All,
       how to fill internal table dynamically.
    for example:
    begin of itab occurs 0,
    empid like pa0000-pernr,
    empname like pa0001-ename,
    grade(5),
    end of itab.
    now i want to append dynamically field itab-grade along with rest fields.
    is this possible?? if yes kindly let me know how to do that.
    Regards,
    Kiran I

    Hi kiran,
    To fill and create and internal table dynamically you can use this code.
    TYPE-POOLS: slis.
    DATA: it_fcat TYPE slis_t_fieldcat_alv,
          is_fcat LIKE LINE OF it_fcat.
    DATA: it_fieldcat TYPE lvc_t_fcat,
          is_fieldcat LIKE LINE OF it_fieldcat.
    DATA: new_table TYPE REF TO data.
    DATA: new_line  TYPE REF TO data.
    FIELD-SYMBOLS: <l_table> TYPE ANY TABLE,
                   <l_line>  TYPE ANY,
                   <l_field> TYPE ANY.
    is_fieldcat-fieldname = 'FIELD1'.
    is_fieldcat-ref_field = 'MATNR'.
    is_fieldcat-ref_table = 'MARA'.
    APPEND is_fieldcat TO it_fieldcat.
    is_fieldcat-fieldname = 'FIELD2'.
    is_fieldcat-ref_field = 'SPRPS'.
    is_fieldcat-ref_table = 'PA0001'.
    APPEND is_fieldcat TO it_fieldcat.
    is_fieldcat-fieldname = 'FIELD3'.
    is_fieldcat-ref_field = 'BEGDA'.
    is_fieldcat-ref_table = 'PA0002'.
    APPEND is_fieldcat TO it_fieldcat.
    Create a new Table
    CALL METHOD cl_alv_table_create=>create_dynamic_table
      EXPORTING
        it_fieldcatalog = it_fieldcat
      IMPORTING
        ep_table        = new_table.
    Create a new Line with the same structure of the table.
    ASSIGN new_table->* TO <l_table>.
    CREATE DATA new_line LIKE LINE OF <l_table>.
    ASSIGN new_line->* TO <l_line>.
    Test it...
    DO 40 times.
      ASSIGN COMPONENT 'FIELD1' OF STRUCTURE <l_line> TO <l_field>.
      <l_field> = '12345'.
      ASSIGN COMPONENT 'FIELD2' OF STRUCTURE <l_line> TO <l_field>.
      <l_field> = 'X'.
      ASSIGN COMPONENT 'FIELD3' OF STRUCTURE <l_line> TO <l_field>.
      <l_field> = '20030101'.
      INSERT <l_line> INTO TABLE <l_table>.
    ENDDO.
    LOOP AT <l_table> ASSIGNING <l_line>.
    ASSIGN COMPONENT 'field1' OF STRUCTURE <l_line> TO <l_field>.
      WRITE  / <l_line>.
    ENDLOOP.
    regards,
    Aashish Garg

  • How to create internal table dynamically?

    hi all
    I have a particular internal table in memory area( thru EXPORT TO MEMORY ID ....)
    how can i create an internal table of this type in another program at runtime  ?
    this internal table need not be a data dictionary type.
    i.e., i need to create an internal table of type which
    is stored in a particular memory-id.
    Regards,
    Naveen........
    null

    Hi,
    Check this code :
    TYPE-POOLS: slis.
    FIELD-SYMBOLS: <t_dyntable> TYPE STANDARD TABLE, 
                    <fs_dyntable>,                    
                    <fs_fldval> type any.             
    PARAMETERS: p_cols(5) TYPE c.   
    DATA:        t_newtable TYPE REF TO data,
                 t_newline  TYPE REF TO data,
                 t_fldcat   TYPE slis_t_fldcat_alv,
                 t_fldcat   TYPE lvc_t_fcat,
                 wa_it_fldcat TYPE lvc_s_fcat,
                 wa_colno(2) TYPE n,
                 wa_flname(5) TYPE c. 
    * Create fields .
      DO p_cols TIMES.
        CLEAR wa_it_fldcat.
        move sy-index to wa_colno.
        concatenate 'COL'
                    wa_colno
               into wa_flname.
        wa_it_fldcat-fieldname = wa_flname.
        wa_it_fldcat-datatype = 'CHAR'.
        wa_it_fldcat-intlen = 10.
        APPEND wa_it_fldcat TO t_fldcat.
      ENDDO. 
    * Create dynamic internal table and assign to FS
      CALL METHOD cl_alv_table_create=>create_dynamic_table
        EXPORTING
          it_fieldcatalog = t_fldcat
        IMPORTING
          ep_table        = t_newtable. 
      ASSIGN t_newtable->* TO <t_dyntable>. 
    * Create dynamic work area and assign to FS
      CREATE DATA t_newline LIKE LINE OF <t_dyntable>.
      ASSIGN t_newline->* TO <fs_dyntable>.
    DATA it_fieldcatalog TYPE lvc_t_fcat.
    DATA lr_table TYPE REF TO data.
    FIELD-SYMBOLS <lt_table> TYPE table.
    *-- Import the fieldcatalog
    IMPORT it_fieldcatalog TO it_fieldcatalog
           FROM MEMORY ID 'CREATE_DYNAMIC_TABLE'.
    IF sy-subrc <> 0.
      EXIT.
    ENDIF.
    *-- Create the dynamic table with the field catalog as structure
    CALL METHOD cl_alv_table_create=>create_dynamic_table
      EXPORTING
        it_fieldcatalog           = it_fieldcatalog
      IMPORTING
        ep_table                  = lr_table
      EXCEPTIONS
        generate_subpool_dir_full = 1
        OTHERS                    = 2.
    IF sy-subrc <> 0.
      EXIT.
    ENDIF.
    *-- Convert the reference into a table
    ASSIGN lr_table->* TO <lt_table>.
    IF sy-subrc <> 0.
      EXIT.
    ENDIF.
    *-- Export the created table so that the function module can import it
    EXPORT lt_table FROM <lt_table>
           TO MEMORY ID 'CREATE_DYNAMIC_TABLE'.
    Regards
    L Appana

  • How to create internal table dynamically based on a table entry

    hi Experts,
      I have table yprod_cat. It has product categories.
      In my ABAP program I need to create internal table dynamically based on the number of entries in the table.
      For example:
      If the table has 3 entries for product category
      1. Board
      2. Micro
      3. Syst
    Then create three (3) internal tables.
    i_board
    i_micro
    i_syst
    How can we do this? Any sample code will be very usefull
    Thanks & Regards
    Gopal
    Moderator Message: No sample codes can be given. Please search for them or work it!
    Edited by: kishan P on Jan 19, 2011 4:22 PM

    Our APEX version is 4.2We are using below SQL query to display radio groups dynamically..
    SELECT APEX_ITEM.RADIOGROUP (1,deptno,'20',dname) dt
    FROM dept
    ORDER BY 1;
    Created a form using SQL type and given abouve SQL query as source.. But when we run the page, there were no radio groups displayed in the page..
    Below is the output of the query..
    <input type="radio" name="f01" value="10" />ACCOUNTING
    <input type="radio" name="f01" value="20" checked="checked" />RESEARCH
    <input type="radio" name="f01" value="30" />SALES
    <input type="radio" name="f01" value="40" />OPERATIONS
    >
    If Tabular Form:
    Edit Region > Report Attributes > Edit Column > Change the Column type to "Standard Report Column"
    If normal Page Item:
    Edit Page Item > Security > Escape special characters=No.
    Pl read the help on that page item to understand the security risk associated with =NO.
    Cheers,
    Edited by: Prabodh on Dec 3, 2012 5:59 PM

  • Create Fieldcatalog based on internal table (dynamic)

    Hi ,
    Is there a way to create Create Fieldcatalog based on internal table (dynamic).
    while creating fieldcat we usually many give the fields "fieldname" and "tabname".
    is there a way to get the fieldname from the main table ?
    Eg ..
    I have i_tab as the output table. It has 3 fields "a", "b" and "c"
    Now when i created fieldcat manually ( in case i cannot use fieldcat_merge FM) , i have to append 3 throws in fieldcat table.
    These rows would have "a", "b" and "c".
    Now i want to know if there is a way in which i can find "a" "b" and "c" fieldnames from the createdd internal tables.
    i can then append the same to fieldcat.

    Hi Anuj,
    I created a FORM routine for this 4 or 5 years ago and made a couple of refinements. Meanwhile it has prooved as very useful.
    The disadvantag is that it creates the oldfashioned field catalog for the function calls. But I already used it for OO fieldcatalog of LVC type - there is a function module for this but I do not have the name here.
    You need the two forms (second called in first) to build the field catalog from any internal table that can be used for ALV display.
    *&      Form  ALV_FIELDCAT_FOR_ITAB
    *       Feldkatalog from (arbitrary) internal Table (c) Clemens Li
    *       * build field catalog from        type description
    form alv_fieldcat_for_itab                                  "#EC *
      tables   pt_outtab                      type table        "#EC *
      changing pt_alv_fieldcat                type slis_t_fieldcat_alv."#EC *
      data:
        lv_desc                               type sydes_desc,
        ls_alv_fieldcat                       type slis_fieldcat_alv,
        lv_longfield                          type text80."CRM<=R/3 fname.
      field-symbols:
        <typeinfo>                            type sydes_typeinfo,
        <nameinfo>                            type sydes_nameinfo.
      describe field pt_outtab into lv_desc.                    "#EC *
      loop at lv_desc-types
          assigning <typeinfo>
          where not idx_name is initial
            and table_kind is initial "no entries for deep table like color
            and back                          = 1. "top-level-entries only.
        read table lv_desc-names index <typeinfo>-idx_name
          assigning <nameinfo>.
        check <nameinfo>-name                 <> 'INCLUDE'.
        ls_alv_fieldcat-fieldname             = <nameinfo>-name.
        while not <nameinfo>-continue is initial.
          add 1 to <typeinfo>-idx_name.
          read table lv_desc-names index <typeinfo>-idx_name
            assigning <nameinfo>.
          concatenate
            ls_alv_fieldcat-fieldname
            <nameinfo>-name
            into ls_alv_fieldcat-fieldname.
        endwhile." not <nameinfo>-continue IS INITIAL.
        read table lv_desc-names index <typeinfo>-idx_help_id
          assigning <nameinfo>.
        if sy-subrc                           = 0.
    * Caution: Help-ID may be Tablename-Fieldname and thus longer
    * than 30 Chars; ls_alv_fieldcat-rollname is 30 Chars only
          ls_alv_fieldcat-rollname            = <nameinfo>-name.
          lv_longfield                        = <nameinfo>-name.
          while not <nameinfo>-continue is initial.
            add 1 to <typeinfo>-idx_help_id.
            read table lv_desc-names index <typeinfo>-idx_help_id
              assigning <nameinfo>.
            concatenate
              lv_longfield
              <nameinfo>-name
              into lv_longfield.
          endwhile." not lv_desc-continue is initial.
    * help id may be data element or <table>-<field>
          if lv_longfield ca '-'.
    * get data                                type for table field
            perform get_rollname_4_tabfield
              using lv_longfield changing ls_alv_fieldcat.
          endif." lv_longfield ca '-'.
        else.
    * No Help-ID: Use Fieldname as text
          ls_alv_fieldcat-seltext_s           =
          ls_alv_fieldcat-seltext_m           =
          ls_alv_fieldcat-seltext_l           =
          ls_alv_fieldcat-reptext_ddic        =
          <nameinfo>-name.
        endif." sy-subrc                      = 0.
    * Starting 4.7: get edit mask
        if not <typeinfo>-idx_edit_mask is initial.
          read table lv_desc-names index <typeinfo>-idx_edit_mask
            assigning <nameinfo>.
          ls_alv_fieldcat-edit_mask           = <nameinfo>-name.
          if not <nameinfo>-continue is initial.
            add 1 to <typeinfo>-idx_edit_mask.
            read table lv_desc-names index <typeinfo>-idx_edit_mask
              assigning <nameinfo>.
            concatenate
              ls_alv_fieldcat-edit_mask
              <nameinfo>-name
              into ls_alv_fieldcat-edit_mask.
          endif." not <nameinfo>-continue IS INITIAL.
        endif." not <typeinfo>-IDX_EDIT_MASK is initial.
    * assign length, output length and decimals
        ls_alv_fieldcat-intlen                = <typeinfo>-length.
        ls_alv_fieldcat-outputlen             = <typeinfo>-output_length.
        ls_alv_fieldcat-decimals_out          = <typeinfo>-decimals.
        ls_alv_fieldcat-inttype               = <typeinfo>-type.
        append ls_alv_fieldcat to pt_alv_fieldcat.
        clear:  "prevent anything 2 B  taken for subsequent fields
          ls_alv_fieldcat.
      endloop." at lv_desc-types where not IDX_NAME is in initial.
    endform.                    " ALV_FIELDCAT_FOR_ITAB
    *&      Form  get_rollname_4_tabfield
    *       Get Data                          type for Table field
    form get_rollname_4_tabfield
      using    p_fname                        type text80 ""CRM<=R/3 fname
      changing p_alv_fieldcat                 type slis_fieldcat_alv.
      field-symbols:
        <dfies>                               type dfies.
      data:
        lv_tabname                            type tabname,
         lt_dfies                             type table of dfies,
        lv_fieldname                          type fieldname.
      split p_fname at '-'
        into lv_tabname lv_fieldname.
      clear p_alv_fieldcat-rollname.
      call function 'DDIF_FIELDINFO_GET'
        exporting
          tabname                             = lv_tabname
          fieldname                           = lv_fieldname
    *   LANGU                                 = SY-LANGU
    *   LFIELDNAME                            = ' '
    *   ALL_TYPES                             = ' '
    * IMPORTING
    *   X030L_WA                              =
    *   DDOBJTYPE                             =
    *   DFIES_WA                              =
    *   LINES_DESCR                           =
       tables
         dfies_tab                            =  lt_dfies
    *   FIXED_VALUES                          =
       exceptions
         not_found                            = 1
         internal_error                       = 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.
      else.
        read table   lt_dfies assigning <dfies> index 1.
        p_alv_fieldcat-rollname               = <dfies>-rollname.
    * Und wenn keinerlei Twexte gepflegt sind?
        if <dfies>-reptext is initial and
           <dfies>-scrtext_s is initial and
           <dfies>-scrtext_m is initial and
           <dfies>-scrtext_l is initial.
    * No Text: Use Fieldname as text
          p_alv_fieldcat-seltext_s            =
          p_alv_fieldcat-seltext_m            =
          p_alv_fieldcat-seltext_l            =
          p_alv_fieldcat-reptext_ddic         =
          p_alv_fieldcat-fieldname.
        endif." <dfies>-reptext IS INITIAL AND
      endif.
    endform.                    " get_rollname_4_tabfield
    Regards,
    Clemens

  • Dynamicly creating an internal table with header line

    Hi experts,
    I am trying to do a read on an internal table using field symbols of type any table. To be able to read more than one row at once, I'd like to read it into another internal table (instead of just one line and instead of looping through them one by one).
    So far the following line rendered an error that the target internal table doesn't have a header line
    read table <fs_v_tab> WITH KEY (<fs_comp>) = <fs_param>-low INTO <fs_v_tab>.
    (also attempted using "<fs_v_tab>->*" & "<fs_v_tab>[]" to be silly)
    Based on the following article, I was wondering if it were possible to dynamicly create an internal table with header line.
    [http://help-abap.blogspot.com/2008/09/dynamic-internal-table-creation.html|http://help-abap.blogspot.com/2008/09/dynamic-internal-table-creation.html]
    Any help or tips on how to dynamicly filter an internal table field-symbol is greatly appreciated!

    Just read the online help:
    This statement reads a row from internal table itab.
    Or more exact:
    This statement reads one row from internal table itab.
    Therefore you can not read multiple lines into another table. The header line is needed to put the result in. And this is not what you intended, the result will be in the header line, not in the table itself.
    If the row to be read is not uniquely specified, the first suitable row is read. In the case of index tables, this row has the lowest table index of all matching rows.
    At least you have to do what you dont wanna do: looping.

  • Can we create internal table dynamically ? how?

    hi to all experts,
                           can we create internal table dynamically ? how?plz explain me with an example.Anybody with good example  will be rewarded.it was asked in an interview what the answer for it

    HI
    Yes you can create
    see this
    /people/rich.heilman2/blog/2005/07/27/dynamic-internal-tables-and-structures--abap
    JUST USE THIS CODE AND DO THE ESSENTIAL CHANGES ACCORDING TO YOU
    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.

  • How to create New columns for the Internal Table Dynamically?

    HI Guys,
                          In my logic i have to create new columns depending on the logic which i am executing.
    My requirement is .I have to display o/p like this
    Material || Year || Period  ||  Mix ratio || Vendor ||Mix Ratio || Vendor || Mix Ratio Vendor || Mix ratio || Vendor || Mix ratio.............................from table's CKMLMV003 and CKMLMV001.Her i have to display the o/p in the above format and i have to display Vendor and Mix Ratio for 5 columns irrespective of data .If i have more than 5 columns for any record then i have to create a New columns dynamically for Vendor and Mix ratio.If anybody want my code i can Submit But plz tell with example how to do?
                    <b>The O/P must be finally shown in ALV Grid</b>
    Thanks,
    Gopi

    You must create the entire internal table dynamically, you can not add columns to a statically define internal table.  Here is an example of creating a dynamic internal table.
    Creation of internal table dynamically based on the Date Range entered
    Regards,
    Rich Heilman

  • How to create an internal table in a Report from File of FTP Server.

    Hi All,
    I want to create an internal table in a Report program. But the problem is I have to download two latest files from FTP server.
    Now, based in those file I have to design internal tables in current program. The problem is the program from which these files are being generated has options to display some fields in the output. Hence, the columns of these files becomes dynamic due to which I am not able to design the internal table in my current program...Please Help.
    Regards & Thanks.
    Prashant.

    Hi,
    Or you can use the RTTS classes...
    Plenty of examples over here.
    one external link: http://help-abap.zevolving.com/2008/09/dynamic-internal-table-creation/
    Kr,
    Manu.

  • Creation of internal table dynamically based on the Date Range entered

    Hi SAPgurus,
    I have been facing one issue i.e creation of internal table dynamically based on the date range entered in the selection screen. For example the date range I am giving as 06/2006 to 08/2006, it should display the Fieldcatelog dynamically, this part i have completed but the only issue I am facing is to populate the sales data into that fields.
    Right now my program is displaying the ALV like this.
    Ex:
    <b>CSR    District   06/2006  07/2006  08/2006  totals</b>      
    Shiva      New York                             10.00
    Shiva      new york                             30.00
    Shiva      new york                             40.00
    but it should display like this
    <b>CSR    District 06/2006 07/2006 08/2006 totals</b>
    Shiva  New York  10.00   30.00 40.00
    80.00                 
    Please help me in this scenario, how to acheive like this..
    Thanks & Regards,
    Sivaram Kandula

    Hi Sivaram,
                 I also got the same requirement . i saw rich and your code whatever you have uploaded.i have created dynamic internal table but i am facing the issue to populating the data to my dynamic internal table.
    Sivaram, can you please explain your code after this.
    *<dyn_table>
    *tab_item.
      LOOP AT tab_item.
        ASSIGN COMPONENT 1 OF STRUCTURE <dyn_wa> TO <dyn_table>.
        ASSIGN COMPONENT 2 OF STRUCTURE <dyn_wa> TO <dyn_table>.
    *    <dyn_wa> = tab_item-bztxt.
    *    <dyn_wa> = tab_item-total.
    *    APPEND <dyn_wa> TO <dyn_table>.
    **    <dyn_wa> = tab_item-total.
    **    ASSIGN tab_item-bezei  TO <dyn_wa>.
    *  APPEND <dyn_table>.
      ENDLOOP.
    how you are puting the loop at tab_item. but tab_item is already commented.
    can you send me the code after that.
    i am sending some part of my code.
    CALL METHOD cl_alv_table_create=>create_dynamic_table
       EXPORTING
         it_fieldcatalog = gt_fCAT1
       IMPORTING
         ep_table        = new_table.
    ASSIGN new_table->* TO <dyn_table>.
       create data new_line like line of <dyn_table>.
       assign new_line->* to <dyn_wa>.
    select vbeln
            fkart
            vkorg
            vtweg
            fkdat
            spart
            fksto
            from vbrk
            client specified
            into table gt_vbrk
            where mandt = sy-mandt
            and fkart in ('ZF5','ZFR')
            and vkorg = '1100'
            and vtweg = '20'
            and fkdat in s_fkdat
            and spart = '06'
            and fksto = ' '.
       if gt_vbrk[] is not initial.
      select  vbeln
              fkimg
              prsdt
              netwr
              matnr
              arktx
              werks
              mwsbp
              from vbrp
              client specified
              into table gt_vbrp
              for all entries in gt_vbrk
              where vbeln = gt_vbrk-vbeln
              and werks in s_werks
              and matnr in s_matnr.
      endif.
    select mnr ltx spras from t247
    into table it_t247
    where spras = 'E'.
    data: lv_month1 type vbrp-prsdt,
           name1(3) type c,
           s_month type string,
            s_month1 type string,
             s_month2 type string.
    *      lv_netwr1 type vbrp-netwr,
    *          lv_mwsbp1 type vbrp-mwsbp.
          loop at gt_vbrp into gs_vbrp.
            gs_final2-matnr = gs_vbrp-matnr.
            gs_final2-arktx = gs_vbrp-arktx.
            gs_final2-fkimg = gs_vbrp-fkimg.
           lv_month1 = gs_vbrp-prsdt.
            read table it_t247 into wa_t247 with key mnr = lv_month1+4(2).
            if sy-subrc eq 0.
            name1 =  wa_t247-ltx.
            endif.
             concatenate  name1
                       lv_month1(4) into s_month SEPARATED BY '_' .
             CONCATENATE S_MONTH 'QTY' INTO S_MONTH1 SEPARATED BY ''.
              CONCATENATE S_MONTH 'VALUE' INTO S_MONTH2 SEPARATED BY ''.
             gs_final2-month = s_month.
              lv_netwr1 = gs_vbrp-netwr.
            lv_mwsbp1 = gs_vbrp-mwsbp.
            gs_final2-MONTH_QTY = S_MONTH1.
            GS_FINAL2-MONTH_VAL = S_MONTH2.
            gs_final2-value = lv_netwr1 + lv_mwsbp1.
           append gs_final2 to gt_final2.
           clear: gs_final2. "lv_name2.
           endloop.
           if gt_final2[] is not initial.
             sort gt_final2 by matnr month ascending .
             loop at gt_final2 into gs_final2.
            gs_final2_01 = gs_final2.
         collect gs_final2_01 into gt_final2_01.
        endloop.
           endif.
       ENDIF..
    Regards
    Ankur

  • Create an internal table with the rows of another internal table.

    Hi I want to know if posible to create an internal table structure with the  rows of another internal table?
    ex.
    If in i_tab column A has this values: row 1 = first, row 2 = second, row 3 = third.
    Now I want that the structure of my internal table be: first, second, third

    Hi,
    If you do this way then what will be the difference between the two table anyway?? First internal table has the same structure irrespective of which row you select. and you are going to store the data from each row to the rows of the second internal table. In that case, the structure of the internal table is the same as first table. and it would have same rows.
    Am I missing something here? or you want to declare the internal table with each field being the structure of the first table? In this case you'd have to do a dynamic declaration of data as the first table can have any no of rows then the second table would have any no of fields in the structure.
    Now if you know that your first internal table is going to have a fixed no of rows eg 3 rows then it becomes simple. Do the following then
    Data: begin of second_table occurs 0,
    first type <first_table type>,
    second type <first_table type>,
    third type <first_table type>,
    end of second_table.
    Regards
    Prasenjit

  • How to determine structure of an Internal table dynamically ?

    Dear Friends,
    On the selection screen.. I have a parameter to pass a structure (eg. E1MARAM ) in to program . Now the challenge is  to create an internal table with the structure that is passed from the selection screen(here eg.E1MARAM)
    Please help me out..

    Hello,
    I had a similar situation where i did not know what the table name would be or the structure name would and this is how i created it.
    *--Data Declaration.
      FIELD-SYMBOLS : <i_temp> TYPE ANY TABLE,
                      <wa_temp> TYPE ANY,
                      <fs_begru> TYPE ANY.
    **Internal table for getting structure of table obtained at run-time
      DATA: BEGIN OF nametab OCCURS 0.
              INCLUDE STRUCTURE dntab.
      DATA: END OF nametab.
    **Move the Class table name obtained at run-time
      MOVE dynamic-tabname TO tabname.
    **Calling function to get the structure of the table name passed as
    **exporting parameter
      CALL FUNCTION 'NAMETAB_GET'
           EXPORTING
                langu               = sy-langu
                tabname             = tabname
           TABLES
                nametab             = nametab
           EXCEPTIONS
                internal_error      = 1
                table_has_no_fields = 2
                table_not_activ     = 3
                no_texts_found      = 4
                OTHERS              = 5.
      IF sy-subrc <> 0.
    MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
            WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
      ENDIF.
    **Populating fieldcatalog
      LOOP AT nametab .
        ls_alv_cat-fieldname     = nametab-fieldname .
        ls_alv_cat-ref_table     = tabname.
        ls_alv_cat-ref_field     = nametab-fieldname .
        APPEND ls_alv_cat TO lt_alv_cat.
      ENDLOOP.
    **Method for getting the reference for the structure
      CALL METHOD cl_alv_table_create=>create_dynamic_table
          EXPORTING it_fieldcatalog = lt_alv_cat
          IMPORTING ep_table = dref.
    **Passing the reference of the structure to field-symbol of type table
      ASSIGN dref->* TO <i_temp>.
      REFRESH i_field.
    **Getting detailed structure of table
      CALL FUNCTION 'CRS_GET_DDIC_TABLE'
           EXPORTING
                i_tabname           = tabname
           TABLES
                to_nametab          = i_field
           EXCEPTIONS
                internal_error      = 1
                table_has_no_fields = 2
                table_not_active    = 3
                no_texts_found      = 4
                OTHERS              = 5.
      IF sy-subrc <> 0.
    MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
            WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
      ENDIF.
    Once you have done this... remember that the program does not know which table is this... but once you have got the table name you can either get the data from the database or if its a structure then you can fill it on your own
      SELECT *
             FROM (tabname)
             INTO CORRESPONDING FIELDS OF TABLE <i_temp>.
      IF sy-subrc NE 0.
      ENDIF.
      SORT : i_begru,
             i_matnr.
    **Selecting records,extracted from Class table that meet selection
    **creiteria
      LOOP AT <i_temp> ASSIGNING <wa_temp>.
    **Assigning BEGRU field
        ASSIGN COMPONENT pos_begru OF STRUCTURE <wa_temp> TO <fs_begru>.
    or if you know what could be the structure that might get used
    FIELD-SYMBOLS : <fs_bapi_mara>   TYPE bapi_mara,
                     <fs_bapi_marax>  TYPE bapi_marax,
                     <fs_bapi_marc>   TYPE bapi_marc,
                     <fs_bapi_marcx>  TYPE bapi_marcx,
                     <fs_bapi_mpop>   TYPE bapi_mpop,
    DATA : dref TYPE REF TO data.
    declare like this and then
    **BAPI_MARA
      CREATE DATA dref TYPE bapi_mara.
      ASSIGN dref->* TO <fs_bapi_mara>.
    **BAPI_MARAX
      CREATE DATA dref TYPE bapi_marax.
      ASSIGN dref->* TO <fs_bapi_marax>.
    **BAPI_MARC
      CREATE DATA dref TYPE bapi_marc.
      ASSIGN dref->* TO <fs_bapi_marc>.
    Go on creating the required structures on the selection criteria match ... when case
    Regards,
    Shekhar Kulkarni

  • Problem in declaring internal table

    hai experts ,
    i am new to web dynpro abap .. my problem is i want to declare a internal table for a table using the web dynpro code wizard .. i found many threads regarding that .. but for mee its not working .. many of them posted that get_static_attributes_table method will solve the problem .. but i used the method in the wizard but it saying that method does not  exist ..pls solve the problem ..
    say where to enter the method in the wizard ..
    thanks & kind regards
    chinnaiya

    Hi Chinnaiya,
    Your post isnt that clear as to what you intend to do. Do you intend to just create an internal table declaration which would be able to hold your context nodes data or do you wish to use the get_static_attributes method to fetch all your tables data into this internal table?
    If you want to just declare an internal table which can hold the data then you would have to do it manually. You can't generate your internal table declaration using the code wizard. Suppose your context nodes name is SFLIGHT then you can use the below syntax to declare a table & work area respectively.
    DATA: lt_sflight TYPE wd_this->elements_sflight,  " Internal table
                wa_sflight TYPE wd_this->element_sflight.  " Work area
    For each node <node> of a controller context, a structure type element_<node> is implicitly generated in the interface IF_<ctrl>. The structure fields correspond to the attributes a node element consists of. Similarly for each node <node> of a controller context, a standard table type elements_<node> is implicitly generated in the interface IF_<ctrl>. The line type of this table is element_<node>. This constant can be used to
    type an internal table that can hold the attributes of multiple node elements. So as how said here you can even declare the work area and internal table like shown below in your MAIN view:
    DATA: lt_sflight TYPE if_main=>elements_sflight,  " internal table
               wa_sflight TYPE if_main=>element_sflight.  " work area
    But the disadvantage of this approach as how pointed out by Thomas in 1 of this earlier threads is that this coding works fine only for this particular view. If you copy the same code and try to use it in another view say VIEW1 then it wouldn't work as the interface name would have changed from if_main to if_view1. So its suggested to use the earlier approach.
    Regards,
    Uday

  • How to find the number of columns in an internal table DYNAMICALLY ?

    Hi,
    How to find the number of columns in an internal table DYNAMICALLY ?
    Thanks and Regards,
    saleem.

    Hi,
    you can find the number of columns and their order using
    the <b>'REUSE_ALV_FIELDCATALOG_MERGE'</b>
    call function 'REUSE_ALV_FIELDCATALOG_MERGE'
    EXPORTING
       I_PROGRAM_NAME               = sy-repid
       I_INTERNAL_TABNAME           = 'ITAB'
       I_INCLNAME                   = sy-repid
      changing
        ct_fieldcat                  = IT_FIELDCAT
    EXCEPTIONS
       INCONSISTENT_INTERFACE       = 1
       PROGRAM_ERROR                = 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
    now describe your fieldcat . and find no of columns.
    and their order also..
    regards
    vijay

Maybe you are looking for