Skip to Content

Declaring internal table of field-symbol type

Hi,

I want to declare an internal table of type field-symbol.

I have a field-symbol <FS> type standard table.

Now I want to declare an internal table as follows:

type:begin of type,

table type <fs>,

end of type.

data:itab type standard table of type.

How to make this?

Add a comment
10|10000 characters needed characters exceeded

Assigned Tags

Related questions

3 Answers

  • Best Answer
    author's profile photo Former Member
    Former Member
    Posted on Jul 22, 2009 at 09:37 AM

    Hi

    U can't do it in declaration section, the system can know how the table <FS> is runtime only:

    FIELD-SYMBOLS: <FS_T> TYPE TABLE.

    DATA: DYN_TAB TYPE REF TO DATA.

    CREATE DATA DYN_TAB LIKE TABLE OF <FS_T>.

    Max

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Jul 22, 2009 at 09:35 AM

    Hi ,

    Please follow the program code below.

    This is one complete program just analyse u will get to know how to declare.

    Here: <fs_itab> type any table - Is Internal Table

    <fs_wa> type any - Is WorkArea

    data:

    ref_itab type ref to data,

    ref_wa type ref to data.

    field-symbols:

    <fs_itab> type any table,

    <fs_wa> type any,

    <fs_comp> type any.

    parameters:pa_itab type dd02l-tabname default 'SPFLI'.

    start-of-selection.

    create data ref_itab type standard table of (pa_itab)

    with non-unique default key.

    assign ref_itab->* to <fs_itab>.

    select * from (pa_itab)

    into table <fs_itab> up to 100 rows.

    create data ref_wa like line of <fs_itab>.

    assign ref_wa->* to <fs_wa>.

    loop at <fs_itab> into <fs_wa>.

    do .

    assign component sy-index of structure <fs_wa> to <fs_comp>.

    if sy-subrc ne 0.

    new-line.

    exit.

    endif.

    write <fs_comp>.

    enddo.

    endloop.

    • Program

    data: carrid type sbc400focc-carrid,

    it_flightinfo type sbc400_t_sbc400focc,

    lines type i.

    perform p1

    using carrid

    it_flightinfo

    changing

    lines.

    &----


    *& Form p1

    &----


    • text

    ----


    • -->P_CARRID text

    • -->P_IT_FLIGHTINFO text

    • <--P_LINES text

    ----


    form p1 using

    f_carrid type sbc400focc-carrid

    f_itab type sbc400_t_sbc400focc

    changing

    value(f_lines) type i.

    data:l_wa like line of f_itab.

    endform. " p1

    Thanks,

    Pradeep

    Edited by: Pradeep Kumar Reddy on Jul 22, 2009 11:36 AM

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Jul 22, 2009 at 09:44 AM

    Hi ,

    check this code for dynamic internal table.

    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. *********Creates a dyanamic internal table*********

    perform get_data.

    perform write_out.

    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.

    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.

        form get_data.

        • Select Data from table.

        select * into table <dyn_table>

        from (p_table).

        endform.

        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.

        Hope this will work ,

        code in Bold is method to create dynamic internal table.

        Please let me know if you still need any more help.

        Thanks and regards,

        Rajeshwar

        Add a comment
        10|10000 characters needed characters exceeded

      Before answering

      You should only submit an answer when you are proposing a solution to the poster's problem. If you want the poster to clarify the question or provide more information, please leave a comment instead, requesting additional details. When answering, please include specifics, such as step-by-step instructions, context for the solution, and links to useful resources. Also, please make sure that you answer complies with our Rules of Engagement.
      You must be Logged in to submit an answer.

      Up to 10 attachments (including images) can be used with a maximum of 1.0 MB each and 10.5 MB total.