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

Similar Messages

  • 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 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..

  • Uploading Dynamically created Internal table form Flat file

    I am creating dynamic internal table as follows:
    *-create dynamic internal table
      CALL METHOD cl_alv_table_create=>create_dynamic_table
        EXPORTING
          it_fieldcatalog = i_fldcat[]
        IMPORTING
          ep_table        = i_modify.
      ASSIGN i_modify->* TO <fs_tab>.
    The dymamic internal table is created with the given Ztable in the selection screen.
    Now the problem is when I try to upload this table <fs_table> using function module Call function 'UPLOAD'.
    The first column of flat file is getting updated in Mandt of <fs_table>.
    I want to update sy-mandt in MANDT of <fs_table> and the rest of the fields with flat file data.
    e.g.
    Flat file data:
    100 white
    101 black
    <fs_table> structure is getting uploaded as below
    mandt zcode zdesc
    100     white
    101     black
    if the clint is 700
    it has to be uploaded as
    mandt zcode zdesc
    700    100     white
    700    101     black
    Can someone knows what should be the approach or any other function module to be used ?
    Message was edited by:
            Mahesh Sahu

    See the answer in your previous thread and close this thread. why do you want to have many threads for one question.

  • Dynamically create Internal Table

    Hi,
    I have a parameter in the program table name.
    I want to create an Internal Table like the table name entered for this parameter.
    Is this kind of dynamic creation of internal table from a variable possible.
    If yes, can you guys please help me with it.
    Thanks,
    CD

    Sure, its possible. HEre is an example.  And you will find thousands more, when you search this forum. 
    report zrich_0002.
    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>.
    * Select Data from table.
    select * into corresponding fields of table <dyn_table>
               from (p_table).
    * 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

  • Search Help doesn't work with a dynamically created internal table

    Hi Gurus,
    I have a custom report that will display the output through edittable ALV.
    My issue is, even though I've already did the FOREIGN KEY assisgnment to each fields of my custom table,
    when I run my report,some fields F$ functionality aint working.
    In my report, I've declared the table to be passed to ALV display dynamically as below:
    *_Create dynamic internal tables for the Final INTERNAL TABLE
      CALL METHOD cl_alv_table_create=>create_dynamic_table
        EXPORTING
          it_fieldcatalog           = gt_fldcatfin
        IMPORTING
          ep_table                  = gp_fintab
        EXCEPTIONS
          generate_subpool_dir_full = 1
          OTHERS                    = 2.
        ASSIGN gp_fintab->* TO <i_xfintab>.
    Where gt_fldcatfin is a modified fieldcatalog (combination of the cutom table fields and 1 column for CELLCOLOR)
    Please help me with this. Thanks a lot.

    This is one way.
    Import photo into illustrator.
    Draw box around photo, no fill ,no stroke colour and place on top of photo.
    Menu - Object - Envelope Distort - Make with Warp - (warp option will appear)
    Use ‘Direct Selection Tool’ (white arrow)
    Select/click on anchor points to alter, you can also use the rotation tool to turn to required position.
    Hope this info' is of help.

  • 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

  • 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 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

  • Column to row display of internal table values

    Hi guys,
    I have the internal table in the following manner
    MATNR     ADSIZE     PRICE
    220p     15m     100
    220p     16m     120
    220p     17m     230
    230p     16m     200
    230p     17m     120
    230p     18m     220
    240p     17m     120
    250p     18m     560
    And want to change to the below mentioned manner, please note that there can be multiple matnr's and multiple adsizes as well.
    MATNR     15m     16m     17m     18m     ......(dynamic:depends on                                                                               
    user )
    220p     100     120     230
    230p     -     200     120     220...and so on.
    How do i display in the above manner.
    Please help.
    Thanks in advance.
    Regards,
    Santosh Kotra.

    Hi Santosh.
    I work hard in this topic. I will post my solution, try to adequate to your needs.
    If your problem is solved, talk to me about your solution.
    I create 2 dynamics tables to do this. I create a it to save the column position to populate the table for alv.
    Change the select (form select) to see with others filters.
    I hope this help you and others.
    Regards
    *& Report  ZDYNAMIC                                                    *
    REPORT  zdynamic                                .
    Tables
    DATA: lt_data TYPE REF TO data,
          lt_new  TYPE REF TO data.
    DATA: lt_fieldcatalog TYPE lvc_t_fcat.
    Structure
    DATA: ls_fieldcatalog TYPE lvc_s_fcat,
          BEGIN OF mat OCCURS 0,
            name TYPE string,
            pos TYPE i,
          END OF mat.
    Data References
    DATA: new_line TYPE REF TO data,
          tab_line TYPE REF TO data.
    Field Symbols
    FIELD-SYMBOLS: <fs_data> TYPE REF TO data,
                   <fs_data1> TYPE REF TO data,
                   <fs_1> TYPE STANDARD TABLE,
                   <ntab> TYPE STANDARD TABLE,
                   <fs_2>,
                   <tab2>,
                   <fs_3>,
                   <tab3>.
    Vars
    DATA: index LIKE sy-index.
    PERFORM fieldcat.
    ASSIGN lt_data TO <fs_data>.
    ASSIGN lt_new  TO <fs_data1>.
    PERFORM cria_tab USING lt_fieldcatalog 1.
    ASSIGN <fs_data>->* TO <fs_1>.
    CREATE DATA new_line LIKE LINE OF <fs_1>.
    ASSIGN new_line->*  TO <fs_2>.
    And to put the data in the internal table
    PERFORM select.
    preencher fieldcat tabela nova
    CLEAR lt_fieldcatalog[].
    LOOP AT <fs_1> ASSIGNING <fs_2>.
      DO.
        ASSIGN COMPONENT sy-index OF STRUCTURE <fs_2> TO <fs_3>.
        IF sy-subrc <> 0.
          EXIT.
        ENDIF.
        IF sy-index = 1.
          CLEAR ls_fieldcatalog.
          ls_fieldcatalog-coltext   = 'CARRID'.
          ls_fieldcatalog-fieldname = 'CARRID'.
          ls_fieldcatalog-inttype = 'C'.
          APPEND ls_fieldcatalog TO lt_fieldcatalog.
        ENDIF.
        IF sy-index = 2.
          CLEAR ls_fieldcatalog.
          ls_fieldcatalog-coltext   = <fs_3>.
          ls_fieldcatalog-fieldname = <fs_3>.
          ls_fieldcatalog-inttype = 'C'.
          APPEND ls_fieldcatalog TO lt_fieldcatalog.
        ENDIF.
      ENDDO.
    ENDLOOP.
    SORT lt_fieldcatalog DESCENDING BY fieldname.
    DELETE ADJACENT DUPLICATES FROM lt_fieldcatalog.
    LOOP AT lt_fieldcatalog INTO ls_fieldcatalog.
      mat-name = ls_fieldcatalog-coltext.
      mat-pos  = sy-tabix.
      APPEND mat.
    ENDLOOP.
    *create new table
    PERFORM cria_tab USING lt_fieldcatalog 2.
    add data
    ASSIGN <fs_data1>->* TO <ntab>.
    CREATE DATA tab_line LIKE LINE OF <ntab>.
    ASSIGN tab_line->*  TO <tab2>.
    LOOP AT <fs_1> ASSIGNING <fs_2>.
      DO.
        ASSIGN COMPONENT sy-index OF STRUCTURE <fs_2> TO <fs_3>.
        IF sy-subrc <> 0.
          EXIT.
        ENDIF.
        IF sy-index = 1.
          ASSIGN COMPONENT sy-index OF STRUCTURE <tab2> TO <tab3>.
          <tab3> = <fs_3>.
        ELSEIF sy-index = 3.
          ASSIGN COMPONENT 2 OF STRUCTURE <fs_2> TO <fs_3>.
          READ TABLE mat WITH KEY name = <fs_3>.
          index = mat-pos.
          ASSIGN COMPONENT sy-index OF STRUCTURE <fs_2> TO <fs_3>.
          ASSIGN COMPONENT index OF STRUCTURE <tab2> TO <tab3>.
          <tab3> = <fs_3>.
        ENDIF.
      ENDDO.
      APPEND <tab2> TO <ntab>.
      CLEAR <tab2>.
    ENDLOOP.
    PERFORM display.
    FORM display
    FORM display.
      CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY_LVC'
        EXPORTING
          it_fieldcat_lvc = lt_fieldcatalog
        TABLES
         t_outtab        = <fs_1>
          t_outtab        = <ntab>
        EXCEPTIONS
          program_error   = 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.
    ENDFORM.                    "display
    FORM fieldcat
    FORM fieldcat.
      CLEAR ls_fieldcatalog.
      ls_fieldcatalog-coltext   = 'CARRID'.
      ls_fieldcatalog-fieldname = 'CARRID'. "Fieldname
      ls_fieldcatalog-inttype = 'C'. "Internal Type C-> Character
      APPEND ls_fieldcatalog TO lt_fieldcatalog.
      ls_fieldcatalog-coltext   = 'CONNID'.
      ls_fieldcatalog-fieldname = 'CONNID'.
      ls_fieldcatalog-inttype = 'N'.
      APPEND ls_fieldcatalog TO lt_fieldcatalog.
      ls_fieldcatalog-coltext   = 'FLDATE'.
      ls_fieldcatalog-fieldname = 'FLDATE'.
      ls_fieldcatalog-inttype = 'D'.
      APPEND ls_fieldcatalog TO lt_fieldcatalog.
      ls_fieldcatalog-coltext   = 'PRICE'.
      ls_fieldcatalog-fieldname = 'PRICE'.
      ls_fieldcatalog-inttype = 'P'.
      APPEND ls_fieldcatalog TO lt_fieldcatalog.
      ls_fieldcatalog-coltext   = 'CURRENCY'.
      ls_fieldcatalog-fieldname = 'CURRENCY'.
      ls_fieldcatalog-inttype = 'C'.
      APPEND ls_fieldcatalog TO lt_fieldcatalog.
    ENDFORM.                    "fieldcat
    FORM cria_tab
    FORM cria_tab USING catalog TYPE lvc_t_fcat qual TYPE i.
      IF qual = 1.
        CALL METHOD cl_alv_table_create=>create_dynamic_table
          EXPORTING
            it_fieldcatalog           = catalog
          IMPORTING
            ep_table                  = <fs_data>
          EXCEPTIONS
            generate_subpool_dir_full = 1
            OTHERS                    = 2.
      ELSE.
        CALL METHOD cl_alv_table_create=>create_dynamic_table
          EXPORTING
            it_fieldcatalog           = catalog
          IMPORTING
            ep_table                  = <fs_data1>
          EXCEPTIONS
            generate_subpool_dir_full = 1
            OTHERS                    = 2.
      ENDIF.
    ENDFORM.                    "cria_tab
    FORM select
    FORM select.
      SELECT mandt carrid connid fldate price currency
        FROM sflight
        INTO CORRESPONDING FIELDS OF TABLE <fs_1>
        WHERE "carrid = 'AA' AND
        fldate > '20080101'.
    ENDFORM.                    "select

  • 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

  • How to create internal table storing instances of ABAP class

    Hi experts, any one knows how to create internal table storing instances of ABAP class or alternative to implement such function?

    Hi
    Please see below example from ABAPDOCU, this might help you.
    Internal Table cnt_tab is used to store class objects.
    Regards,
    Vishal
    REPORT demo_objects_references.
    CLASS counter DEFINITION.
      PUBLIC SECTION.
        METHODS: set IMPORTING value(set_value) TYPE i,
                 increment,
                 get EXPORTING value(get_value) TYPE i.
      PRIVATE SECTION.
        DATA count TYPE i.
    ENDCLASS.
    CLASS counter IMPLEMENTATION.
      METHOD set.
        count = set_value.
      ENDMETHOD.
      METHOD increment.
        ADD 1 TO count.
      ENDMETHOD.
      METHOD get.
        get_value = count.
      ENDMETHOD.
    ENDCLASS.
    DATA: cnt_1 TYPE REF TO counter,
          cnt_2 TYPE REF TO counter,
          cnt_3 TYPE REF TO counter,
          cnt_tab TYPE TABLE OF REF TO counter.
    DATA number TYPE i.
    START-OF-SELECTION.
      CREATE OBJECT: cnt_1,
                     cnt_2.
      MOVE cnt_2 TO cnt_3.
      CLEAR cnt_2.
      cnt_3 = cnt_1.
      CLEAR cnt_3.
      APPEND cnt_1 TO cnt_tab.
      CREATE OBJECT: cnt_2,
                     cnt_3.
      APPEND: cnt_2 TO cnt_tab,
              cnt_3 TO cnt_tab.
      CALL METHOD cnt_1->set EXPORTING set_value = 1.
      CALL METHOD cnt_2->set EXPORTING set_value = 10.
      CALL METHOD cnt_3->set EXPORTING set_value = 100.
      DO 3 TIMES.
        CALL METHOD: cnt_1->increment,
                     cnt_2->increment,
                     cnt_3->increment.
      ENDDO.
      LOOP AT cnt_tab INTO cnt_1.
        CALL METHOD cnt_1->get IMPORTING get_value = number.
        WRITE / number.
      ENDLOOP.

  • Fill data in table( on view ) dynamically from internal table

    Hi,
    How can I populate a table on view with data from an internal table?
    Thanks,
    Ronita

    Hi,
    if you have an internal table named xyz.
    Then create a structure in se11 for this internal table.
    Then create a node with this structure with cardinality 0:n
    Navigate into method WDDOMODIFYVIEW of view MAIN_VIEW. Insert coding for:
    -     Create a new context node for the table
    Hint: Use method Create_nodeinfo_from_struct of class Cl_wd_dynamic_tool.
    -     Remove “old” dynamic table IE element from view , if one exists. If it exists, it is a child of group GROUP_1 and has the name TESTTAB.
    -     Create a new UI element for a table named TESTTAB
    -     Create an internal table, fill it with the data from the database table and bind it to the newly created dynamic context node.
    METHOD wddomodifyview .
      DATA:
      UI Elements
        group_1       TYPE REF TO cl_wd_uielement_container,
        new_tab       TYPE REF TO cl_wd_table,
      Context Nodes
        dyn_node      TYPE REF TO if_wd_context_node,
        tabname_node  TYPE REF TO if_wd_context_node,
      Node Info
        rootnode_info TYPE REF TO if_wd_context_node_info,
      Data Reference (for internal table)
        stru_tab      TYPE REF TO data,
      String (for table name)
        tablename     TYPE string.
      FIELD-SYMBOLS:
        <tab> TYPE table.
    create context node ***************************************************************
    get node info of context root node
      rootnode_info = wd_context->get_node_info( ).
    Get the name of the table to be created
      tabname_node = wd_context->get_child_node( name = 'TABLE_DATA' ).
      tabname_node->get_attribute( EXPORTING name = 'NAME' IMPORTING value = tablename ).
      translate tablename to upper case.
    create sub node named TEST1 of structure (tablename)
      cl_wd_dynamic_tool=>create_nodeinfo_from_struct(
        parent_info = rootnode_info
        node_name = tablename
        structure_name = tablename
        is_multiple = abap_true ).
    get instance of new node
      dyn_node = wd_context->get_child_node( name = tablename ).
    remove "old" table UI element from view , if necessary ****************************
      group_1 ?= view->get_element( 'GROUP_1' ).
      group_1->remove_child( id = 'TESTTAB' ).
    create new UI element table *******************************************************
      new_tab = cl_wd_dynamic_tool=>create_table_from_node(
    ui_parent = group_1
    table_id  = 'TESTTAB'
    node      = dyn_node ).
    fill context node with data *******************************************************
    create internal table of (tabletype)
      CREATE DATA stru_tab TYPE TABLE OF (tablename).
      ASSIGN stru_tab->* TO <tab>.
    Get table content
      SELECT * FROM (tablename) INTO CORRESPONDING FIELDS OF TABLE <tab>.
    Bind internal table to context node.
      dyn_node->bind_table( <tab> ).
    ENDMETHOD.
    Edited by: Sridevi D on Apr 19, 2008 10:30 AM

  • Create Internal table with fields coming as query result of multiple tables

    Hi
    I want to create internal table with the fileds which come as a result of a select query from multiple tables

    My code is something like this. I need  the data from various fields of diff tables depending on the excel file. This data is then to be put in a internal table
    *& Report  Z_EXTC
    report  z_extc.
    type-pools : abap.
    parameter: objname(25) type c.
    data : idetails type abap_compdescr_tab,
           xdetails type abap_compdescr.
    data : ref_table_des type ref to cl_abap_structdescr.
    data: p_table type string.
    data:l_string type string,
         l_filename(200) type c,
         dy_line  type ref to data,
         xfc type lvc_s_fcat,
         ifc type lvc_t_fcat.
    types:begin of itab,
         tabname type dd03l-tabname,
         fieldname type dd03l-fieldname,
         end of itab.
    types:begin of atab,
          tabname type dd03l-tabname,
          cnt type string,
          end of atab.
    field-symbols: <dyn_table> type table,
                   <dyn_table1> type standard table,
                   <dyn_wa>,
                   <dyn_field>.
    data: dy_table type ref to data,
          dy_table1 type ref to data.
    data: itab1 type itab occurs 0 with header line.
    data atab1 type atab occurs 0 with header line.
    data frstrec type i value 0.
    data lastrec type i value 0.
    l_string = ''.
    call function 'GUI_UPLOAD'
      exporting
        filename                      = 'C:\excel_files\FIELDS_CC.TXT'
       filetype                      = 'TXT'
       has_field_separator           = 'X'       .
    if sy-subrc <> 0.
    MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
            WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
    endif.
    *Refresh itab1.
    loop at itab1.
      on change of: itab1-tabname.
        if lastrec = 1.
          move l_string to atab1-cnt.
       move itab1-tabname to atab1-tabname.
          append atab1.
          l_string = ''.
        endif.
        move itab1-tabname to atab1-tabname.
        frstrec = 1.
      endon.
      if frstrec = 1.
        concatenate l_string itab1-fieldname into l_string separated by
    space.
        lastrec = 1.
      endif.
    *write:/ itab1-tabname,40 itab1-fieldname.
    endloop.
    move l_string to atab1-cnt.
    append atab1.
    loop at atab1.
      write:/ atab1-tabname,5 atab1-cnt.
    endloop.

Maybe you are looking for