Application Development Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 

Appending internal tables

Former Member
0 Kudos

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

5 REPLIES 5

nishantbansal91
Active Contributor
0 Kudos

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

0 Kudos

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.

former_member184569
Active Contributor
0 Kudos

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.

0 Kudos

Hi Sushmita,

       Thanks for the reply. Can u just write some explanation comments at the side of your code.

The logic is a matnr undergoes BOM_EXPLOSION and the output would be number of BOM_COMPONENTS for a single matnr . Those BOM_COMPONENTS deatils would be present in the main internal table such as plant,date etc. So A matnr may not have more than 20 BOM_COMPONENTS according to the requirement.

So when i loop the main ITAB . Each unique BOM_COMPONENT and its details should be stored in the unique internal table. If there are two same BOM_COMPONENTS then they must be in the same internal table.

0 Kudos


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