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

Appending internal tables

Hi all,

M new to abap and jus need a sample code for the following logic.

I have to fill 20 internal tables with the records present in one single internal table. Suppose if 10 matnr are there in my main ITAB in which 3 are same & 7 are different, then the similar 3 must be filled in itab1 and the next into itab2 similiary till itab7. Each itab is for the details of one unique matnr.

When the looping is done and as a new matnr comes the values must be appended to the next internal table. T

Thank you

Moderator message - No spoon feeding. Requirements dumping is not allowed in the ABAP forums.

Message was edited by: Suhas Saha

Add a comment
10|10000 characters needed characters exceeded

Assigned Tags

Related questions

2 Answers

  • Posted on Dec 29, 2013 at 11:22 AM

    HI Vikash,

    Please append all the unique data and non-unique data in two separate table instead of creating the internal table for each material number.

    Regards.

    Nishant

    Add a comment
    10|10000 characters needed characters exceeded

    • Former Member

      Hi Nishant,

      Thank you for the reply , but my requirement is such . Initially for a matnr the BOM_EXPLOSION is done so a matnr may have more than one bom_component. That bom_component and its corresponding records must be stored in separate internal tables.

  • Posted on Dec 29, 2013 at 11:42 AM

    Are you sure there will be only 20 internal tables?

    If you have all the required internal tables declared, then you can use this logic.

    data : lv_tab_name(6) type c, mat_count(2) type n.
    FIELD-SYMBOLS <cur_tab> type table .

    select * from mch1 into TABLE itab UP TO 100 rows.

    mat_count = 1.
    loop at itab into wa_itab.
    at new matnr.
    SHIFT mat_count LEFT DELETING LEADING '0'.
    concatenate 'itab' mat_count into lv_tab_name.
    mat_count = mat_count + 1.
    ASSIGN (lv_tab_name) to <cur_tab>.
    endat.
    if <cur_tab> is ASSIGNED.
    append wa_itab to <cur_tab>.
    endif.
    clear wa_itab.
    endloop.

    Here itab is the initial table, and itab1, itab2.... itab20 are the other internal tables.

    Add a comment
    10|10000 characters needed characters exceeded


    • * For illustration - getting all data into initial table itab.

      select * from mch1 into TABLE itab UP TO 100 rows.


      *A variable mat_count is declared of type n (length 2) and this will be concatenated with itab to get the name of each internal table that you require.

      * Assuming the name of your internal tables are itab1, itab2, itab3.... itab20.


      mat_count = 1. " Initialize mat_count to 1.


      loop at itab into wa_itab.
      at new matnr. " For every new matnr, the field symbol will point to a new itab.


      SHIFT mat_count LEFT DELETING LEADING '0'. "to change 01 to 1 to give the result itab1 instead of itab01.
      concatenate 'itab' mat_count into lv_tab_name. " Move the internal table name to this variable
      mat_count = mat_count + 1.
      ASSIGN (lv_tab_name) to <cur_tab>. " Assign the field symbol to the table given inside lv_tab_name
      endat.
      if <cur_tab> is ASSIGNED.
      append wa_itab to <cur_tab>.
      endif.
      clear wa_itab.
      endloop.


      Hope its clear. Revert in case of any mor queries.

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.