Skip to Content
author's profile photo Former Member
Former Member

how to difine unknow table?

hi guys,

now i am trying to define a internal table use the table name which i can get from an input parameter, is that possible? ans if there is any FM about converting the input table into structure or sth like that?

thanks.

Add a comment
10|10000 characters needed characters exceeded

Assigned Tags

Related questions

2 Answers

  • Best Answer
    author's profile photo Former Member
    Former Member
    Posted on Sep 29, 2005 at 04:57 AM

    Hi Adamyam,

    Actualy i did one program in which i used to take the table name from the user as input , create an internal table depending on that.

    I think this is exactly what you want.You will see some alv related functons here,but they make the task easy.

    *---------------------Global Data -------------------------------------
    TYPE-POOLS: slis.
    Parameters: p_table LIKE dd02l-tabname.
    DATA:     new_table TYPE REF TO data,
              new_line TYPE  REF TO data.
    
    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.
    
    FIELD-SYMBOLS: <l_table> TYPE ANY TABLE,
                   <l_line>  TYPE ANY.
    
    start-of-selection.
    
    CALL FUNCTION 'REUSE_ALV_FIELDCATALOG_MERGE'
            EXPORTING
                 i_structure_name = p_table
            CHANGING
                 ct_fieldcat      = it_fcat[].
    
       LOOP AT it_fcat INTO is_fcat.
         MOVE-CORRESPONDING is_fcat TO is_fieldcat.
         is_fieldcat-fieldname = is_fcat-fieldname.
         is_fieldcat-ref_field = is_fcat-fieldname.
         is_fieldcat-ref_table = is_fcat-ref_tabname.
         APPEND is_fieldcat TO it_fieldcat.
       ENDLOOP.
    
    * 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>.
    
    
    
    

    So <l_table> will be he dynamic structure..

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Sep 29, 2005 at 02:47 AM

    look at this link

    /people/subramanian.venkateswaran2/blog/2004/11/19/dynamic-internal-table

    sample codes

    type-pools : abap.

    data: wa_vbak type vbak .(for u its ur structure)

    data : it_details type abap_compdescr_tab,

    wa_comp type abap_compdescr.

    data : ref_descr type ref to cl_abap_structdescr.

    ref_descr ?= cl_abap_typedescr=>describe_by_data( wa_vbak ).

    it_details[] = ref_descr->components[].

    or

    type-pools: slis.

    field-symbols: <dyn_table> type standard table,

    data: alv_fldcat type slis_t_fieldcat_alv,

    it_fldcat type lvc_t_fcat.

    <dyn_wa>.

    selection-screen begin of block b1 with frame title text-001.

    parameters: p_check type c.

    selection-screen end of block b1.

    start-of-selection.

    perform build_dyn_itab.

    perform build_report.

    loop at <dyn_table> into <dyn_wa>.

    write:/ <dyn_wa>.

    endloop.

    Build_dyn_itab************************************************************************

    form build_dyn_itab.

    data: index(3) type c.

    data: new_table type ref to data,

    new_line type ref to data,

    wa_it_fldcat type lvc_s_fcat.

    clear wa_it_fldcat.

    wa_it_fldcat-fieldname = 'AUFNR'.

    wa_it_fldcat-datatype = 'CHAR'.

    wa_it_fldcat-intlen = 12.

    append wa_it_fldcat to it_fldcat .

    clear wa_it_fldcat.

    wa_it_fldcat-fieldname = 'POSNR'.

    wa_it_fldcat-datatype = 'CHAR'.

    wa_it_fldcat-intlen = 6.

    append wa_it_fldcat to it_fldcat .

    • Create fields

    clear index.

    do 2 times.

    index = sy-index.

    clear wa_it_fldcat.

    concatenate 'Field' index into

    wa_it_fldcat-fieldname .

    condense wa_it_fldcat-fieldname no-gaps.

    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.

    Form build_report*********************************************************************

    form build_report.

    data: fieldname(20) type c.

    data: fieldvalue(5) type c.

    data: index(3) type c.

    field-symbols: <fs1>.

    assign component 'AUFNR' of structure <dyn_wa> to <fs1>.

    <fs1> = '123456789'.

    assign component 'POSNR' of structure <dyn_wa> to <fs1>.

    <fs1> = '000001'.

    do 2 times.

    index = sy-index.

    • Set up fieldname

    concatenate 'FIELD' index into fieldname .

    condense fieldname no-gaps.

    • Set up fieldvalue

    concatenate 'FLD' index into fieldvalue.

    condense fieldvalue no-gaps.

    assign component fieldname of structure <dyn_wa> to <fs1>.

    <fs1> = fieldvalue.

    enddo.

    • Append to the dynamic internal table

    append <dyn_wa> to <dyn_table>.

    endform.

    hope this will some idea on how to create ur internal table.

    plz reward point if useful

    regards

    gv

    Message was edited by: Venkat

    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.