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: 

How to insert the record in Internal Table

Former Member
0 Kudos

Hi Guys

I am creating one report . In which i want add record in Internal table from another internal table.

but in my internal table there are only few records but in table in which i want add the records there r more records is it possible to add more records in internal table.

eg

in itab_final there 5 records & i want add records i_source there are 10 records how to fill up data.

9 REPLIES 9

Former Member
0 Kudos

Append lines of itab1 to itab2. if both structures are same....

other wise u have to use

loop at itab1.

append itab2.

endloop.

Former Member
0 Kudos

U can loop thru one internla table and append other internal

table ..

loop at itab_final.

i_source = itab_final.

append i_source.

endloop.

If they have different no. of fields .. use move-corresponding

If they have different field names move field by field ..

loop at itab_final.

i_source-field1 = itab_final-field2.

........

append i_source.

endloop.

Former Member
0 Kudos

Yes u can do that

Loop at i_source INTO wa_source.

wa_final-fld1 = wa_source-fld1

wa_final-fld2 = wa_source-fld2

wa_final-fld3 = wa_source-fld3

wa_final-fld4 = wa_source-fld4

Append wa_final TO I_final.

Endloop.

Regards,

Swarup

Former Member
0 Kudos

Hi nitin,

Try this way,

it_name-fld1 = fld1_value. (or) move fld1_value to it_name-fld1.

it_name-fld2 = fld2_value. (or) move fld2_value to it_name-fld2.

it_name-fld3 = fld3_value. (or) move fld3_value to it_name-fld3.

append it_name.

INSERT wa INTO TABLE itab INDEX idx .

Effect

This variant can only be used for standard tables and sorted tables. Each line line_spec to be inserted into the line before the table index idx and the table index of the following lines is increased by one. A data object of the type i is expected for idx.

If idx contains a value equal to the number of the existing table lines plus one, the new line is appended as the last line in the internal table. If idx contains a greater value, no line is inserted and sy-subrc is set to 4.

An exception that cannot be handled is raised when:

idx contains a value less than or equal to 0

A line to be inserted would cause a duplicate entry in tables with a unique table key

A line to be inserted would disrupt the sort order of sorted tables

Within a LOOP loop, you can omit the addition INDEX. Each line to be inserted is inserted before the current table line of the LOOP loop. However, if the current line is deleted in the same loop pass, the response is undefined.

itab-field = <value1>.

insert itab index 1.

itab-field = <value2>.

insert itab index 2.

or

Have the record which you want in a work area say "wa".

Now say, you want to append the record after you encounter a particular value "V" in a field say F

data: variable type sy-tabix.

Loop at itab.

if F = V.

variable = sy-tabix.

endif.

endloop.

sy-tabix = variable + 1.

insert wa to itab.

Reward if helpful.

Regards.

karthik

happy learning.

Former Member
0 Kudos

hiiii

use following code

LOOP AT i_marc INTO wa_marc.
    wa_output-matnr = wa_marc-matnr.
    wa_output-werks = wa_marc-werks.
    wa_output-prctr = wa_marc-prctr.
    lw_frecid = lw_frecid + 1.
    wa_output-frecid = lw_frecid.

    APPEND wa_output TO i_output.
  ENDLOOP.                             " LOOP AT i_marc

regards

twinkal

Former Member
0 Kudos

Hi Nitn,

Since itab_final will be your final itab for the result, it means i_result have to follow itab_final structure.

You can use move-corresponding syntax or you can map it manually.

Following is one of the way that you can use:

Loop at i_result.

move-corresponding i_result to itab_final.

append itab_final.

EndLoop.

Thanks,

Victor.

Former Member
0 Kudos

If structure for both of these tables are same in that case u can use

statement :

append LINES OF itab_final to i_source.

or

append LINES OF i_source to itab_final.

This statement is not based on data volume.

Regards,

Joy.

former_member195383
Active Contributor
0 Kudos

declare a workarea of type i_source say wa_i_source .

loop at itab_final.

wa_i_source-field1 = itab_final-field1.

wa_i_source-field2 = itab_final-field2.

append wa_i_source to i_source.

endloop.

this will help u out...

Former Member
0 Kudos

Hi,

Its possible to add records.

1. Either use

APPEND LINES OF ITAB1 TO ITAB2.

where the itab2 has more fields than itab1.

2. Else use

LOOP AT ITAB1 INTO WA_ITAB1
MOVE-CORRESPONDING IWA_TAB1 TO WA_ITAB2.
APPEND WA_ITAB2  TO ITAB2.
ENDLOOP.

this will work.

plz reward if useful.

thanks,

dhanashri.