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

Declaring variable dynamically

Hi all,

I want to accept a table name, and declare an internal table which is of type of that accepted table.

Add a comment
10|10000 characters needed characters exceeded

Assigned Tags

Related questions

5 Answers

  • Posted on Mar 31, 2008 at 12:49 PM

    Use type any.Type any is used when the type is unknown.

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Mar 31, 2008 at 12:49 PM

    HI

    Use field symbols

    field-symbols: <fs1>

    you can assign any type to field symbol at run time

    Regards

    Aditya

    Add a comment
    10|10000 characters needed characters exceeded

  • Posted on Mar 31, 2008 at 12:55 PM

    you can use the below syntax.

    field-symbols: <fs> type any.
    
    data: var(9).
    
    var = 'IT_VBAP[]'.
    
    assign (var) to <fs>.

    There are many ways to do this. Above is one such.

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Mar 31, 2008 at 12:56 PM

    Hi

    You can use

    Field-symbols: <fs_tab> type any table.

    This filed symbol then can accept any table dynamically.

    you can process this dynamically filled table by statement

    Loop at <fs_tab> into <wa_tab>.

    loop at <wa_tab> assigning componets of <wa_tab> to <field>

    endloop.

    endloop.

    This way you process any table dynamically.

    Reward points if helpful

    Regards,

    Rahul

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Mar 31, 2008 at 01:07 PM

    Hi,

    Do use the code. I think it will give you some picture.

    &----


    *& Report ZDYNTEST *

    *& *

    &----


    *& *

    *& *

    &----


    report zdyntest.

    type-pools : slis.

    tables : marc,t001w.

    data : begin of itab occurs 0,

    matnr like marc-matnr,

    end of itab.

    data : fieldstab type lvc_t_fcat,

    stab type lvc_s_fcat,

    t_fieldcat type slis_t_fieldcat_alv,

    s_fieldcat type slis_fieldcat_alv,

    new_line type ref to data,

    new_table type ref to data,

    index(3) type c,

    str(70),

    text(6),

    cnt(1),

    text1(16),

    repid like sy-repid.

    field-symbols : <fs> type standard table,

    <wa> type any.

    select-options : s_werks for marc-werks no intervals,

    s_matnr for marc-matnr no intervals.

    initialization.

    repid = sy-repid.

    start-of-selection.

    select * from marc

    into corresponding fields of table itab

    where matnr in s_matnr

    and werks in s_werks.

    sort itab by matnr.

    delete adjacent duplicates from itab comparing matnr.

    stab-fieldname = 'MATNR'.

    stab-datatype = 'CHAR'.

    stab-intlen = '18'.

    append stab to fieldstab.

    clear cnt.

    loop at s_werks.

    clear text.

    cnt = cnt + 1.

    concatenate 'EISLO' cnt into text.

    stab-fieldname = text.

    stab-datatype = 'CHAR'.

    stab-intlen = '16'.

    append stab to fieldstab.

    clear s_werks.

    endloop.

    call method cl_alv_table_create=>create_dynamic_table

    exporting

    it_fieldcatalog = fieldstab

    importing

    ep_table = new_table.

    assign new_table->* to <fs>.

    create data new_line like line of <fs>.

    assign new_line->* to <wa>.

    perform move_data.

    clear s_fieldcat.

    s_fieldcat-fieldname = 'MATNR'.

    s_fieldcat-tabname = itab.

    s_fieldcat-seltext_m = 'Part Number'.

    s_fieldcat-no_zero = 'X'.

    s_fieldcat-ddictxt = 'M'.

    append s_fieldcat to t_fieldcat.

    clear cnt.

    loop at s_werks.

    clear t001w.

    cnt = cnt + 1.

    select single * from t001w where werks = s_werks-low and spras = sy-langu.

    clear text.

    concatenate 'EISLO' cnt into text.

    s_fieldcat-fieldname = text.

    s_fieldcat-seltext_m = t001w-name2.

    • S_FIELDCAT-NO_ZERO = 'X'.

    s_fieldcat-ddictxt = 'M'.

    append s_fieldcat to t_fieldcat.

    clear s_werks.

    endloop.

    call function 'REUSE_ALV_GRID_DISPLAY'

    exporting

    it_fieldcat = t_fieldcat[]

    tables

    t_outtab = <fs>.

    &----


    *& Form MOVE_DATA

    &----


    • text

    ----


    form move_data.

    loop at itab.

    clear str.

    concatenate itab-matnr ' ' into str separated by space.

    loop at s_werks.

    clear marc.

    select single * from marc where matnr = itab-matnr and werks = s_werks-low.

    if sy-subrc eq 0.

    clear text1.

    text1 = marc-eislo.

    concatenate str text1 into str separated by space.

    else.

    concatenate str '0' into str separated by space.

    endif.

    endloop.

    <wa> = str.

    append <wa> to <fs>.

    clear itab.

    endloop.

    endform. "MOVE_DATA

    Regards,

    Sankar.

    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.