Reference comp in dynamic internal table using CL_ALV_TABLE_CREATE

Hi,
I am using CL_ALV_TABLE_CREATE to create a dynamic internal table. Everything works fine, but there is one problem with it. How can i create a component in the internal table that is actually a REF TO a certain data type. i.e. later i would like to store a reference to some dataobj in this component of the internal table.
I cannot use cl_abap_*descr classes to create internal table because of some other reasons, otherwise it would have been easy to do it.
Any kind of help would be highly appreciated.
Thanks and best regards,
Ghufran

Hi Ghufran,
I do have an idea about the class <b>CL_ALV_TABLE_CREATE</b> , but i have writen an exmaple code to create a Dynamic Iternal table, please have a look, it may help you
*& Report  Z_DYNAMIC_INTERNALTABLE                                 *
report  z_dynamic_internaltable             .
data: d_ref type ref to data,
d_ref2 type ref to data ,
i_alv_cat type table of lvc_s_fcat,
ls_alv_cat like line of i_alv_cat.
types tabname like dcobjdef-name .
parameter: p_tablen type tabname.
data: begin of itab occurs 0.
include structure dntab.
data: end of itab.
field-symbols : <f_fs> type table,
<f_fs1> type table,
<f_fs2> type any,
<f_fs3> type table,
<f_fs4> type any.
refresh itab.
call function 'NAMETAB_GET'
exporting
langu = sy-langu
tabname = p_tablen
tables
nametab = itab
exceptions
no_texts_found = 1.
loop at itab .
ls_alv_cat-fieldname = itab-fieldname.
ls_alv_cat-ref_table = p_tablen.
ls_alv_cat-ref_field = itab-fieldname.
append ls_alv_cat to i_alv_cat.
endloop.
internal table build
call method cl_alv_table_create=>create_dynamic_table
exporting it_fieldcatalog = i_alv_cat
importing ep_table = d_ref .
assign d_ref->* to <f_fs>.
select * from (p_tablen) into corresponding fields of table <f_fs>.
loop at <f_fs> assigning <f_fs2>.
assign itab-fieldname to <f_fs4>.
loop at itab.
write: / <f_fs4>.
endloop.
endloop.
Thanks
Sudheer

Similar Messages

  • Dynamic internal  tables using field symbols

    Hello,
    Is it possible to create a dynamic table where the no of fields in the internal table can be created dynamically(using field symbols).
    Say sometimes internal tables with 10 fields and depending upon the requirement the fields can be dynamically increased or decreased in runtime.
    Thanks.

    Hi,
    Go through the following code....
    *Data definitions
    *** Tables
    data: lt_data type ref to data.
    data: lt_fieldcatalog type lvc_t_fcat.
    *** Structure
    data: ls_fieldcatalog type lvc_s_fcat.
    *** Data References
    data: new_line type ref to data,
          fs_data type ref to data.
    *** Field Symbols
    field-symbols: <fs_data> type ref to data,
                   <fs_1> type any table,
                   <fs_2>,
                   <fs_3>.
    *Populating the internal table with fieldnames required for our dynamic
    *internal table
    ls_fieldcatalog-fieldname = 'MANDT'.
    append ls_fieldcatalog to lt_fieldcatalog.
    ls_fieldcatalog-fieldname = 'CARRID'. "Fieldname
    ls_fieldcatalog-inttype = 'C'. "Internal Type C-> Character
    append ls_fieldcatalog to lt_fieldcatalog.
    ls_fieldcatalog-fieldname = 'CONNID'.
    ls_fieldcatalog-inttype = 'N'.
    append ls_fieldcatalog to lt_fieldcatalog.
    ls_fieldcatalog-fieldname = 'FLDATE'.
    ls_fieldcatalog-inttype = 'D'.
    append ls_fieldcatalog to lt_fieldcatalog.
    ls_fieldcatalog-fieldname = 'PRICE'.
    ls_fieldcatalog-inttype = 'P'.
    append ls_fieldcatalog to lt_fieldcatalog.
    ls_fieldcatalog-fieldname = 'CURRENCY'.
    ls_fieldcatalog-inttype = 'C'.
    append ls_fieldcatalog to lt_fieldcatalog.
    *Calling the method CREATE_DYNAMIC_TABLE
    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.
    *Assigning Field-Symbol to our dynamic internal table
    assign lt_data to <fs_data>.
    *Internal Table is ready, now to put data in that table
    *** So <FS_1> now points to our dynamic internal table.
    assign fs_data->* to <fs_1>.
    *** Next step is to create a work area for our dynamic internal table.
    create data new_line like line of <fs_1>.
    *** A field-symbol to access that work area
    assign new_line->*  to <fs_2>.
    *** And to put the data in the internal table
    select
          mandt
          carrid
          connid
          fldate
          price
          currency
                  from sflight
                  into corresponding fields of table <fs_1>.
    *** Access contents of internal table
    loop at <fs_1> assigning <fs_2>.
    do 5 times.
    assign component sy-index of structure <fs_2> to <fs_3>.
    write:  <fs_3>.
    enddo.
    skip 1.
    endloop.
    top-of-page.
    write:/5 'FUJITSU CONSULTING COMPANY' inverse color 6,
           50 sy-datum inverse color 6,
           70 sy-pagno inverse color 6.
    uline.
    <REMOVED BY MODERATOR>
    Vijay C
    Code Formatted by: Alvaro Tejada Galindo on Apr 14, 2008 1:47 PM

  • Subtotals in dynamic internal table using alv grid

    hi experts i have created one dynamic table.  The requirement is to display the subtotals in the output using reuse_alv_grid.
    Dynamic itab (field-symbols) and ALV event BEFORE_LINE_OUTPUT
    the above is the thread related and could any one please provide the sample code for this task.
    can any one post the solution for that.
    rewards points will be awarded.
    khazi

    * ASSINING STRUCTURE FOR FILD CATLOGS
    DATA: DYN_TABLE    TYPE REF TO DATA,
          DYN_LINE     TYPE REF TO DATA,
          LS_FIELDCAT TYPE LVC_S_FCAT,
          LT_FIELDCAT TYPE LVC_T_FCAT.
      LOOP AT LT_DMTAB INTO LS_DMTAB.
        CLEAR LS_FIELDCAT.
        LS_FIELDCAT-FIELDNAME = LS_DMTAB-SDATE .
        LS_FIELDCAT-DATATYPE  = 'DEC'.
        LS_FIELDCAT-INTTYPE   = 'P'.
        LS_FIELDCAT-INTLEN    = '16' .
        LS_FIELDCAT-DECIMALS  = '03'.
        LS_FIELDCAT-JUST      = 'C'.
        APPEND LS_FIELDCAT TO LT_FIELDCAT.
      ENDLOOP.
    *& For grouping the table rows for Under Line
      LS_FIELDCAT-FIELDNAME = 'ULFIELD' .
      LS_FIELDCAT-DATATYPE  = 'INT'.
      LS_FIELDCAT-INTTYPE   = 'P'.
      LS_FIELDCAT-INTLEN    = '2' .
      LS_FIELDCAT-DECIMALS  = ''.
      APPEND LS_FIELDCAT TO LT_FIELDCAT.
      "* Create dynamic internal table and assign to Field-Symbol
      CALL METHOD CL_ALV_TABLE_CREATE=>CREATE_DYNAMIC_TABLE
        EXPORTING
          IT_FIELDCATALOG = LT_FIELDCAT
        IMPORTING
          EP_TABLE        = DYN_TABLE.
      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 DYN_TABLE->* TO <LT_AREA_F>.
      "* Create dynamic work area and assign to Field Symbol
      CREATE DATA DYN_LINE LIKE LINE OF <LT_AREA_F>.
      ASSIGN DYN_LINE->* TO <LS_AREA_F>.
    You check in Field cat level you will get  Check Sub total field will exist
    Thanks and regards
    Jogu

  • Dynamic Internal table using another internal table values

    Hello All,
    I have an internal table ITAB1, which will get populated inside the program. This ITAB1 will have only one field.
    I want to create an internal table dynamically with the values of ITAB1( single field internal table ) as fields.
    Thanks in advance.
    Best Regards,
    Sasidhar Reddy Matli.

    at this wiki
    https://www.sdn.sap.com/irj/sdn/wiki?path=/display/abap/individualcellcoloringindynamic+alv
    you can find an example where I build an internal table
    you can look at the coding where I loop though the internal table and at the value to the fieldname.
    * dynamic fields
    LOOP AT ta_pernrs INTO wa_pernrs.
    WRITE wa_pernrs-pernr TO h_ri_pernr.
    is_lvc_cat-fieldname = wa_pernrs-pernr.
    is_lvc_cat-ref_field = 'massn'.
    is_lvc_cat-ref_table = 'PERNR'.
    is_lvc_cat-just = 'C'.
    CONCATENATE it_0002-inits it_0002-nachn(1) INTO is_lvc_cat-scrtext_s SEPARATED BY space.
    CONCATENATE it_0002-inits it_0002-nachn INTO is_lvc_cat-scrtext_m SEPARATED BY space.
    CONCATENATE it_0002-inits it_0002-nachn INTO is_lvc_cat-scrtext_l SEPARATED BY space.
    APPEND is_lvc_cat TO it_lvc_cat.
    and then ofcourse the creation of the table which is also mentioned in the earlier reply
    CALL METHOD cl_alv_table_create=>create_dynamic_table
    EXPORTING
    it_fieldcatalog = it_lvc_cat
    IMPORTING
    *ep_table = ta_output.*** Create a new Line with the same structure of the table.
    ASSIGN ta_output->* TO <ta_output>.*
    CREATE DATA new_line LIKE LINE OF <ta_output>.
    ASSIGN new_line->* TO <l_line>.
    kind regards
    arthur de smidt

  • To create a deep structure for dynamic internal table.

    Hello
    My ALV has fields which are defined dynamically during execution.
    so, i did it in the following way,
    Declared Field symbolds, DREF and fieldcatalog as,
    FIELD-SYMBOLS: <t_dyntable> TYPE STANDARD TABLE,
                  <fs_dyntable>.
    DATA:   dref_dyntab    TYPE REF TO data,
            dref_dynwa     TYPE REF TO data.
    DATA: ts_fieldcatalog TYPE lvc_t_fcat.
    DATA: wa_fieldcatalog TYPE lvc_s_fcat.
    Updated Fieldcatalog dynamically as,
    *function module to read segment structure
        CALL FUNCTION 'SEGMENT_READ'
          EXPORTING
            segmenttyp           = v_segment_name
          TABLES
            segmentstructure     = ts_seg_structure
          EXCEPTIONS
            no_authority         = 1
            segment_not_existing = 2
            OTHERS               = 3.
        IF sy-subrc <> 0.
          CASE sy-subrc.
            WHEN '1'.
              MESSAGE e024.
              STOP.
            WHEN '2'.
              MESSAGE e025 WITH v_segment_name.
              STOP.
            WHEN OTHERS.
              MESSAGE e023.
          ENDCASE.
        ENDIF.
    *FETCH FIELDS FROM STRUCTURE OF SEGMENT AND CREATE FIELDCATALOG FOR
    EACH FIELD OF SEGMENT (DYNAMIC FIELD CATALOG)
        LOOP AT ts_seg_structure INTO wa_seg_structure.
          ADD 1 TO v_counter.
          wa_fieldcatalog-fieldname = wa_seg_structure-fieldname.
          wa_fieldcatalog-col_pos   = v_counter.
          wa_fieldcatalog-ref_table = wa_seg_structure-segtyp.
          APPEND wa_fieldcatalog TO ts_fieldcatalog.
          CLEAR wa_fieldcatalog.
        ENDLOOP.
    and generated dynamic internal table using fieldcatalog as,
    *--Method to get the structure of table using fieldcatalog.
      CALL METHOD cl_alv_table_create=>create_dynamic_table
        EXPORTING
          it_fieldcatalog = ts_fieldcatalog
        IMPORTING
    *--Variable of type REF TO DATA.
          ep_table        = dref_dyntab.
      IF sy-subrc <> 0.
        MESSAGE e023.
      ENDIF.
    *--Dynamic internal tables required when show segments selected
      IF p_selseg IS NOT INITIAL.
        ASSIGN dref_dyntab->* TO <t_dyntable>.
    *--Create dynamic work area and assign to FS
      CREATE DATA dref_dynwa LIKE LINE OF <t_dyntable>.
        ASSIGN dref_dynwa->* TO <fs_dyntable>.
    And then i populated this <t_dyntable> which is being passed as data-table to method
    CL_GUI_ALV_GRID => SET_TABLE_FOR_FIRST_DISPLAY
    for ALV grid Display along with above used filedcatalog ts_fieldcatalog.
    Things are fine till here, but now i have the requirement to edit selected rows of the ALV display..
    As you might be aware, we need a field
            TS_STYLEROW  TYPE lvc_t_styl, (i.e, a field of type 'h' and we can say as an internal table inside an internal table or else as a deep structure)
    in the output internal table <t_dyntable> to meet our requirement.
    My issue is about declaring one such field of type 'h' in this dynamically created internal table ''<t_dyntable>".
    I tried in the following way by adding one such field to fieldcatalog :
    *Field for Styling
      ADD 1 TO v_counter.
      wa_fieldcatalog-fieldname   = 'TS_STYLEROW'.
      wa_fieldcatalog-tabname     = 'TS_STYLE'.
      wa_fieldcatalog-col_pos     = v_counter.
      wa_fieldcatalog-no_out      = 'X'.
      wa_fieldcatalog-inttype     = 'h'.      " I even mentioned this
      APPEND wa_fieldcatalog TO ts_fieldcatalog.
      CLEAR  wa_fieldcatalog.
    But this is creating a field of type 'C' in the table <t_dyntable> instead of what i was expecting
    Guyz and respected,
    Please advice me with the solution or ur ideas....
    Note : The overall requirement is create a deep structure for dynamically generated internal table.
    Your help is highly appreciated and unforgettable..!!!!!!!

    hi,
    Dynamic append
    Dynamic internal table
    Dynamic internal table
    dynamic columns in ALV
    Variant for dynamic selection
    thanks

  • Accessing Dynamic Internal table fields

    Hello All,
    I have one internal table ep_tabx having 138 columns whose data is getting displayed
    by using function module reuse_alv_grid_display.
    Now my query is, i have created one custom button on the appl toolbar to download ep_tabx data.
    IF the user changes the the layout of the output at runtime and then presses that custom button
    then i have created one dynamic internal table using call method cl_alv_table_create=>create_dynamic_table suppose <dyn_table> whose struc will be that of
    dynamic fieldcatalog returned by using FM REUSE_ALV_GRID_LAYOUT_INFO_GET.
    And then I have put a loop on the int table ep_tabx and move corresponding to the int table
    <dyn_table>. But when i download the <dyn_table> data through GUI_DOWNLOAD the
    date fields data is not getting downloaded correctly. I have 4 date fields in my ep_tabx.
    In the alv grid output the date is getting displayed like 08/30/2004(ie mon/date/yr) but in download
    file it comes like 20040830(ie yr/mon/date and that too without /).How to access the dynamic
    internal tables fields separately so asto convert them in the pgm before the download.
    Kindly Help.
    Thanks in advance.
    Mansi

    Hi,
    Search in SDN you would get loads of info on accessing dynamic itab's .
    in order to convert your date format use WRITE stmt to convert the value in your itab before passing it to download FM.
    Regards,
    Raghavendra

  • Create dynamic internal table with deep structure;cell coloring dynamic ALV

    Hi,
    My requirement is to do cell colouring for a dynamic ALV.
    So I am creating a dynamic internal table using the following method.
      CALL METHOD cl_alv_table_create=>create_dynamic_table
        EXPORTING
          it_fieldcatalog = i_fieldcatalog[]
        IMPORTING
          ep_table        = i_output.
    But how do I define field COLORS which should be again an internal table ?
    Is there any other way for cell colouring?
    Putting my problem in another way:
    How do I create a dynamic internal table with one field as another internal table.
    Quick replies are highly appreciated.
    Thanks,
    Nisha Vengal.

    halo Nisha
    Before building the display table . you can add the field in the feild catalog right . This display table gets generated from the field catalog right
    1 Create a global structute say ZEXTEND_FIELDCAT
    2 Have fields like STYLE type lvc_t_styl
                             COLOR type LVC_T_SCOL.
    3 Now you have to extend ur fieldcatalog
      l_fieldcat-fieldname = COLOR'.
      l_fieldcat-ref_field = 'COLOR'.
      l_fieldcat-ref_table = 'ZEXTEND_FIELDCAT'.
      APPEND l_fieldcat TO lt_field_catalog.
      CLEAR l_fieldcat.

  • Smartforms - pass dynamic internal tables

    Hello experts,
    In my smartform print program, I have created a dynamic internal table using method CL_ALV_TABLE_CREATE=>CREATE_DYNAMIC_TABLE where in my dynamic internal table <DYN_TABLE> is declared as
    FIELD-SYMBOLS: <DYN_TABLE> TYPE STANDARD TABLE,
                   <DYN_WA>.
    I am populating <DYN_TABLE> and passing it on to my smartform. Now my question is, inside my smartform, how can I declare this dynamic table <DYN_TABLE> in form interface? Please let me know. Thanks.

    This could be one of the solution.
    1. Create table type using data element EDI_SDATA (char 1000) , say ZTTDYN .
    2. Use this as importing paramter your smarform.
    3. In print program transfer the content from dynamic internal table to internal table define using ZTTDYN. You can comma seperate then fields.
    4. Pass this comma separated internal table to smartform.
    5. And finally proces this data in smartform.

  • Copying Dynamic Internal Table

    Hi All,
            I have created a Dynamic internal table using field symbols.  Now i need to copy that dynamic itab to another internal table, because I am not familiar with field symbols. Can anybody tell me how can i copy that dyn_itab to another itab.
    code which I used to create dyn_table:
    LS_FIELDCATALOG-FIELDNAME = 'CHINA_TOT'.
    LS_FIELDCATALOG-INTTYPE = 'I'.
    append LS_FIELDCATALOG to LT_FIELDCATALOG.
    assign LT_DATA to <FS_DATA>.
    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.
    So <FS_1> now points to our dynamic internal table.
    assign <FS_DATA>->* to <FS_1>.
    HERE <FS_1> is a dynamic itab.

    First you need to create another table with the structure that you have.
    call method cl_alv_table_create=>create_dynamic_table
         exporting
           it_fieldcatalog = LT_FIELDCATALOG
         importing
           ep_table = <FS_DATA2>
         exceptions
           generate_subpool_dir_full = 1
           others = 2
    field-symbols  : <fs_line1>, <fs_line2>, <fs_tmp1>, <fs_tmp2>.
    assign <FS_DATA2->* to <FS_2>.
    Now FS_1 and FS_2 are the tables.
    Also create work areas for the tables.
    CREATE DATA gw_line1 LIKE LINE OF <fs_1>
    CREATE DATA gw_line2 LIKE LINE OF <fs_2>.
    ASSIGN gw_line1->* TO <fs_line1>.
    assign gw_line2->* to <fs_line2>.
    With field symbols, you cannot move the rows directly, you will have to move it field by field.
    Once all the values are populated in the first table, copy it with the following logic.
    loop at <fs_1> into <fs_line1>
    Loop at   LT_FIELDCATALOG into LS_FIELDCATALOG.
    ASSIGN COMPONENT ls_fieldcatalog-fieldname OF STRUCTURE <fs_line1> TO <fs_tmp1>.
    ASSIGN COMPONENT ls_fieldcatalog-fieldname OF STRUCTURE <fs_line2> TO <fs_tmp2>.
    <fs_tmp2> = <fs_tmp1>
    endloop.
    append <fs_line2> to <fs_2>
    endloop.

  • Creating Dynamic internal table

    Hi,
    Can we create a dynamic internal table using data of an existing internal table.
    i.e. if itab1 is have data like :
    row                  col                     value
    1                      1                        ab
    1                      2                        cd
    1                      3                        ef
    2                      1                        gh
    2                      2                        ij
    2                      3                        kl
    and I want to create itab2 dynamically like this :
    row                  col1                     col2                    col3
    1                       ab                        cd                       ef
    2                       gh                          ij                        kl
    The issue lies only while creating internal table using non DDIC structure i.e. internal table of program.
    Thanks
    Vipin

    Hi,
    This is the sample report for DYNAMIC ALV report.
    REPORT  YMS_DYNAMICALV.
    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.
    SELECTION-SCREEN BEGIN OF BLOCK B1 WITH FRAME TITLE TEXT-001.
    PARAMETERS: P_FLDS(5) TYPE C.
    SELECTION-SCREEN END OF BLOCK B1.
    START-OF-SELECTION.
    build the dynamic internal table
      PERFORM BUILD_DYN_ITAB.
    write 5 records to the alv grid
      DO 5 TIMES.
        PERFORM BUILD_REPORT.
      ENDDO.
    call the alv grid.
      PERFORM CALL_ALV.
    Build_dyn_itab
    FORM BUILD_DYN_ITAB.
      DATA: NEW_TABLE TYPE REF TO DATA,
            NEW_LINE  TYPE REF TO DATA,
            WA_IT_FLDCAT TYPE LVC_S_FCAT.
    Create fields .
      DO P_FLDS TIMES.
        CLEAR WA_IT_FLDCAT.
        WA_IT_FLDCAT-FIELDNAME = SY-INDEX.
        WA_IT_FLDCAT-DATATYPE = 'CHAR'.
        WA_IT_FLDCAT-INTLEN = 5.
        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>.
    ENDFORM.                    "build_dyn_itab
         Form  build_report
    FORM BUILD_REPORT.
      DATA: FIELDNAME(20) TYPE C.
      DATA: FIELDVALUE(5) TYPE C.
      DATA: INDEX(3) TYPE C.
      FIELD-SYMBOLS: <FS1>.
      DO P_FLDS TIMES.
        INDEX = SY-INDEX.
    Set up fieldvalue
        CONCATENATE 'FLD' INDEX INTO
                 FIELDVALUE.
        CONDENSE   FIELDVALUE NO-GAPS.
      <b> assign component  index  of structure <dyn_wa> to <fs1>.
       <fs1> =  fieldvalue.</b>
      ENDDO.
    Append to the dynamic internal table
      APPEND <DYN_WA> TO <DYN_TABLE>.
    ENDFORM.                    "build_report
    CALL_ALV
    FORM CALL_ALV.
      DATA: WA_CAT LIKE LINE OF ALV_FLDCAT.
      DO P_FLDS TIMES.
        CLEAR WA_CAT.
        WA_CAT-FIELDNAME = SY-INDEX.
        WA_CAT-SELTEXT_S = SY-INDEX.
        WA_CAT-OUTPUTLEN = '5'.
        APPEND WA_CAT TO ALV_FLDCAT.
      ENDDO.
    Call ABAP List Viewer (ALV)
      CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
        EXPORTING
          IT_FIELDCAT = ALV_FLDCAT
        TABLES
          T_OUTTAB    = <DYN_TABLE>.
    ENDFORM.                    "call_alv
    Thanks,
    Sankar M

  • How to add new field into dynamic internal table

    Hello Expert.
    how to add new field into dynamic internal table.
    PARAMETERS: P_TABLE(30).    "table name
    DATA: I_TAB TYPE REF TO DATA.
    FIELD-SYMBOLS: <TAB> TYPE standard TABLE.
    *Create dynamic FS
    create DATA I_TAB TYPE TABLE OF (p_table).
      ASSIGN I_TAB->* TO <TAB>.
    SELECT * FROM (p_table) INTO TABLE <TAB>.
       here i want to add one more field into <TAB> at LAST position and my 
       Field name  =  field_stype     and
       Field type    =  'LVC_T_STYL'
    could you please helpme out .

    Hi,
    Please find the code below.You can add the field acc to your requirement.
    Creating Dynamic internal table
    TYPE-POOLS: slis.
    FIELD-SYMBOLS: <t_dyntable> TYPE STANDARD TABLE,  u201C Dynamic internal table name
                   <fs_dyntable>,                     u201C Field symbol to create work area
                   <fs_fldval> type any.              u201C Field symbol to assign values 
    PARAMETERS: p_cols(5) TYPE c.                     u201C Input number of columns
    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>.
    Populating Dynamic internal table 
      DATA: fieldname(20) TYPE c.
      DATA: fieldvalue(10) TYPE c.
      DATA: index(3) TYPE c. 
      DO p_cols TIMES. 
        index = sy-index.
        MOVE sy-index TO wa_colno.
        CONCATENATE 'COL'
                    wa_colno
               INTO wa_flname. 
    Set up fieldvalue
        CONCATENATE 'VALUE' index INTO
                    fieldvalue.
        CONDENSE    fieldvalue NO-GAPS. 
        ASSIGN COMPONENT  wa_flname
            OF STRUCTURE <fs_dyntable> TO <fs_fldval>.
        <fs_fldval> =  fieldvalue. 
      ENDDO. 
    Append to the dynamic internal table
      APPEND <fs_dyntable> TO <t_dyntable>.
    Displaying dynamic internal table using Grid. 
    DATA: wa_cat LIKE LINE OF fs_fldcat. 
      DO p_cols TIMES.
        CLEAR wa_cat.
        MOVE sy-index TO wa_colno.
        CONCATENATE 'COL'
                    wa_colno
               INTO wa_flname. 
        wa_cat-fieldname = wa_flname.
        wa_cat-seltext_s = wa_flname.
        wa_cat-outputlen = '10'.
        APPEND wa_cat TO fs_fldcat.
      ENDDO. 
    Call ABAP List Viewer (ALV)
      CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
        EXPORTING
          it_fieldcat = fs_fldcat
        TABLES
          t_outtab    = <t_dyntable>.

  • Error while creating a dynamic internal table refers to custom field

    Hi all,
    I am getting the exception TYPE_NOT_FOUND when I try to create a dynamic internal table using:-
    DATA: gr_desc TYPE REF TO cl_abap_typedescr.
    gr_desc = cl_abap_typedescr=>describe_by_name( p_field ).
    The field p_field is a Z-field inside a DB table, (e.g. a user added field in MARA). The statement fails at that point and gives a runtime exception. Any suggestions to how I may solve this problem? Or any alternatives for the same? I guess we face this issue for all custom fields..has SAP released a note for this??
    Thanks..

    that's just the wrong method, you should use DESCRIBE_BY_DATA
    gr_desc = cl_abap_typedescr=>describe_by_data( p_field ).
    Note: DESCRIBE_BY_NAME is to be used for referencing a DDIC type by its name. Example:
    gr_desc = cl_abap_typedescr=>describe_by_name( 'MARA-ZZFIELD' ).

  • Delete row from internal table using field symbol.

    Hi friends,
      I created dynamic internal table using field symbol. I want to delete some data using where clause.
    for example. i want to use like,
        DELETE <FS> WHERE KUNNR = WA_KNA1-KUNNR.
    Like the above statment it won't work. How i can use delete with where clause in field symbols.
    Hope any one can help me.
    Thanks and regards
    Srikanth. S

    hi Srikanth,
    I think you have to LOOP through the whole internal table and check each line and decide to delete or not:
    LOOP at <itab> INTO <wa>.
    ASSIGN COMPONENT 'KUNNR' OF STRUCTURE <wa> TO <field>.
    CHECK <field> IS ASSIGNED.
    IF <field> EQ WA_KNA1-KUNNR.
    DELETE ...
    ENDIF.
    UNASSIGN <field>.
    ENDLOOP.
    hope this helps
    ec

  • Need urgent help on dynamic internal table.

    Hi experts,
    I got an editable dynamic internal table. When the value in 1 of the editable field has been changed, I will fire the the DATA_CHANGED event. In this event, I can get the row ID where the changes occur, but the problem is, how can I select back the data from the dynamic internal table using the row ID since index is not permitted to be used? I need to get the rest of the records form the ROW and then perform a database update accordingly. How can I select from the dynamic internal table given the row ID? THanks in advance.

    Hi
    I suppose it depends on the kind of internal table assigned to fieldsymbol, this sample works fine:
    FIELD-SYMBOLS: <FS> TYPE TABLE,
                   <WA> TYPE ANY.
    DATA: BEGIN OF ITAB OCCURS 0,
            FIELD,
          END   OF ITAB.
    DO 10 TIMES.
      ITAB-FIELD = 'a'.
      APPEND ITAB.
    ENDDO.
    ASSIGN ITAB[] TO <FS>.
    READ TABLE <FS> ASSIGNING <WA> INDEX 1.
    WRITE <WA>.
    It can't use the index with internal table of kind HASHED.
    Max

  • How To Read Field Values Form Dynamic Internal Table

    Hi,
    I Created a dynamic internal table using.
    FIELD-SYMBOLS: <gt_table> TYPE STANDARD TABLE,
                   <wa_gt_table>,
                   <l_fvalue> TYPE ANY.
    This Interanl table is working well, and all values are populated to an ALV.
    Now I try to set a link
    for that I am using below code
          READ TABLE <gt_table> ASSIGNING <l_fvalue> index rs_selfield-tabindex.
          IF sy-subrc EQ 0.
            insplot = <l_fvalue>-prueflos.
    Now it is showing a syntax error :
    the data object <l_fvalue> has no structure and there for no component called prueflos
    Regards
    Nausal

    Hi,
    Refere following code
    Local Field Symbol
      FIELD-SYMBOLS: <lf_any> TYPE ANY.                     "Changed data
      LOOP AT <gf_dyna_table> ASSIGNING <gf_dyna>.
        DO.
          ASSIGN COMPONENT sy-index OF STRUCTURE <gf_dyna> TO <lf_any>.
          IF sy-subrc NE 0.
            EXIT.
          ENDIF.
          IF ls_attach-line IS INITIAL.
            ls_attach-line = <lf_any>.
          ELSE.
            CONCATENATE ls_attach-line <lf_any> INTO ls_attach-line
                                                SEPARATED BY lc_tab.
          ENDIF.
        ENDDO.
        CONCATENATE lc_cret ls_attach-line  INTO ls_attach-line.
      Append Changed Data to attachement table
        APPEND ls_attach TO gt_attach.
      Clear
        CLEAR : ls_attach.
      ENDLOOP.
    Regards,
    Prashant

Maybe you are looking for