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

dynamic change of internal table

Hi ,

I am retrieving data from database table into main_internal_table and i need to divide this main_internal_table into 15 internal . i am writting this code but it is not working ,

DATA:

l_tab_name TYPE string,

lv_tab_no TYPE string.

FIELD-SYMBOLS : <matnr> TYPE matnr,

<fs1> TYPE table .

CONCATENATE 'IT_QT_MIC_K' lv_tab_no INTO l_tab_name.

ASSIGN (l_tab_name) to <fs1>. "on this line i am getting

You attempted to assign a field to a typed field symbol,

but the field does not have the required type.

IF <fs1> IS ASSIGNED.

APPEND wa_zqm_cto_arr_9024 TO <fs1> .

ENDIF.

UNASSIGN <fs1>.

i am getting this error.

Category ABAP Programming Error

Runtime Errors ASSIGN_TYPE_CONFLICT

ABAP Program SAPLZQM_REVIEW_PER_FG

Application Component PP

please correct me how to do it.

Regards,

Durga.

Add a comment
10|10000 characters needed characters exceeded

Assigned Tags

Related questions

5 Answers

  • Best Answer
    author's profile photo Former Member
    Former Member
    Posted on Jan 03, 2014 at 08:48 AM

    Hi Durga,

    You can create internal table dynamically as follows:

    PARAMETERS : p_table(10) TYPE C.

    DATA: w_tabname TYPE w_tabname,

    w_dref TYPE REF TO data,

    w_grid TYPE REF TO cl_gui_alv_grid.

    FIELD-SYMBOLS: <t_itab> TYPE ANY TABLE.

    w_tabname = p_table.

    CREATE DATA w_dref TYPE TABLE OF (w_tabname).

    ASSIGN w_dref->* TO <t_itab>.


    Thanks and regards,

    Ashish Kumar

    Add a comment
    10|10000 characters needed characters exceeded

    • Hi Durja Gupta,

      CREATE DATA w_dref TYPE TABLE OF (w_tabname).


      only works if w_tabname is the name of a data dictionary structure. Just use


      CREATE DATA w_dref LIKE TABLE OF IT_QT_MIC_K for an existing internal table with headerline. If you declared your internal table without header line, then you don't need the TABLE OF addition, i.e.

      CREATE DATA w_dref LIKE IT_QT_MIC_K or

      CREATE DATA w_dref LIKE IT_QT_MIC_K[].

      IF you need many internal tables, declare a table of references:

      FIELD-SYMBOLS:

      <tabref> TYPE REF TO DATA,

      <table> TYPE TABLE

      DATA lt_tabref TYPE TABLE OF REF TO data.

      DO 1000 TIMES.

      APPEND INITIAL LINE TO lt_tabref ASSIGNING <tabref>.

      CREATE DATA <tabref> TYPE TABLE OF mseg. "just an example, create MSEG tables

      ASSIGN <tabref>->* ro <table>.

      * WORK with <table> number SY-INDEX

      ENDDO.


      Hope it helps!


      Regards


      Clemens

      .

  • author's profile photo Former Member
    Former Member
    Posted on Jan 03, 2014 at 08:54 AM

    Hi Durga,

    Declare <fs1> as

    FIELD SYMBOLS: <fs1> TYPE ANY TABLE.

    * or like <fs1> TYPE STANDARD TABLE.

    and assign l_tab_name like

    * Assign variable to field symbols

    ASSIGN l_tab_name->* to <fs1>.

    Regards,

    Sheetal.

    Add a comment
    10|10000 characters needed characters exceeded

    • Former Member

      REPORT zpwtest .

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

      *** Field Symbols

      FIELD-SYMBOLS: <fs_data> TYPE REF TO data,

      <fs_1> TYPE ANY TABLE,

      <fs_2>,

      <fs_3>.

      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.

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

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

      ASSIGN COMPONENT 1 OF STRUCTURE <fs_2> TO <fs_3>.

      WRITE: / <fs_3>.

      ENDLOOP.

  • Posted on Jan 03, 2014 at 07:37 AM

    Hi Durga,

    Please assign below like this.

    ASSIGN l_tab_name->* to <fs1>.

    Arivazhagan S

    Add a comment
    10|10000 characters needed characters exceeded

  • Posted on Jan 03, 2014 at 07:40 AM

    Hi Durga,

    please change your code as your needs, by seeing this code snippet,

    It will work for you.

    FIELD-SYMBOLS: <fs_itab> TYPE ANY TABLE.

    DATA: wa TYPE REF TO data.

    FIELD-SYMBOLS: <fs_wa> TYPE any.

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Jan 06, 2014 at 06:57 AM

    Hi Durga,

    You can create dynamic internal tables using RTTC ( Runtime Type Creation ). Below is sample code.

    DATA: lo_line TYPE REF TO cl_abap_structdescr,

    lo_table TYPE REF TO cl_abap_tabledescr,

    ref_itab TYPE REF TO data,

    ref_wa TYPE REF TO data.

    FIELD-SYMBOLS: <fs_tab> TYPE STANDARD TABLE,
    <fs_wa> TYPE any.

    *I have created for table SFLIGHT

    lo_line ?= cl_abap_typedescr=>describe_by_name('SFLIGHT').

    lo_table = cl_abap_tabledescr=>create(
    p_line_type = lo_line
    p_table_kind = cl_abap_tabledescr=>tablekind_sorted
    p_unique = cl_abap_typedescr=>true ).


    CREATE DATA ref_itab TYPE HANDLE lo_table.

    ASSIGN ref_itab->* TO <fs_tab>.

    CREATE DATA ref_wa TYPE HANDLE lo_line.

    ASSIGN ref_wa->* TO <fs_wa>.


    Hope this helps.

    Regards,

    Shibin






    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.