Application Development and Automation 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: 
Read only

populating an itab

Former Member
0 Likes
1,176

hi all,

i am havin an internal table with some data.i want to populate another internal table based on the data present in the first internal table.Can u plz tell me how to do it?

Thanks ina advance.

Anu

hi all,

i am havin an internal table with some data.i want to populate another internal table based on the data present in the first internal table.Can u plz tell me how to do it?

Thanks ina advance.

Anu

10 REPLIES 10
Read only

Former Member
0 Likes
1,159

APPEND LINES OF itab1 TO itab2.

If you want to use condition...

LOOP AT itab1 WHERE <cond>.

APPEND itab1 TO itab2.

ENDLOOP.

Read only

hymavathi_oruganti
Active Contributor
0 Likes
1,159

let itab1 be ur first internal table. now u want to populate some data into itab2 based on itab1.

1.one way is using for all enties

example:

check not itab1[] is initial.

select * from <dbtab> into itab2

for all entries in itab1 where field1 = itab1-field1.

2.

if u want to move the contents of itab1 to itab2.

move-corresponding itab1 to itab2.

append itab2.

3.

another method is

loop at itab1.

select single <field1> <field2> from <dbtab> into itab2

where <field> = itab1-field.

endloop.

Message was edited by: Hymavathi Oruganti

Read only

Former Member
0 Likes
1,159

hi ,

use..

APPEND LINES OF ITAB TO ITAB1. or
 APPEND LINES OF <itab1> [FROM <n1>] [TO <n2>] TO <itab2>.

itab1[] = itab[].

copy based on a condition..

 LOOP AT ITAB WHERE <cond>.
   move itab to itab1.
    append itab.
 endloop.

regards

satesh

Read only

Former Member
0 Likes
1,159

1st select some mandatory field in itab1.

loop at itab1 .

read table itab2 with key <field> = itab1-<field>.

modify itab1.

endloop.

Read only

Former Member
0 Likes
1,159

hi

you can do that by using forallentries keyword

let me know if u want any other details

Read only

0 Likes
1,159

hi Anuradha,

Kindly close all your posts and reward all the helpful answers..

regards

satesh

Read only

Former Member
0 Likes
1,159

u mean to say

select fields f1,f2,f3

into table itab2

from XXXX

for all entries in itab1 where key = itab1-key .

is this what u r looking for 'POPULATING' the second internal table .

____________________________________

if already second table is populated then i think all the possible hints are sufficient as given the members.

Read only

Former Member
0 Likes
1,159

Hi Anuradha,

based on the first internal table

you can use for all entires if it data base query related.

select *

from <dbtab>

into itab2

for all entries in itab1

where field = itab-field.

or you want to populate the data from itab1 itslef.

"with out any condition..

loop at itab1 .

move-corresponding itab1 to itab2.

append itab2.

endloop.

with some condition..

loop at itab1 where <codition>.

move-corresponding itab1 to itab2.

append itab2.

endloop.

Regards

vijay

Read only

Former Member
0 Likes
1,159

Hi Anuradha,

Assume ITAB1 and ITAB2 are your internal tables.

TABLES: LFA1, LFB1.

DATA: ITAB1 LIKE LFA1 OCCURS 0 WITH HEADER LINE,

ITAB2 LIKE LFB1 OCCURS 0 WITH HEADER LINE.

SELECT * FROM LFA1 INTO TABLE ITAB1 WHERE LAND1 = 'IN'.

LOOP AT ITAB1.

CLEAR ITAB2.

SELECT * FROM LFB1 WHERE LIFNR = ITAB1-LIFNR.

ITAB2-LIFNR = ITAB1-LIFNR.

ITAB2-BUKRS = LFB1-BUKRS.

ITAB2-PERNR = LFB1-PERNR.

APPEND ITAB2.

ENDSELECT.

ENDLOOP.

hope this will help you.

Regards,

Vaitheeswaran

Read only

jayanthi_jayaraman
Active Contributor
0 Likes
1,159

Hi,

Suppose itab1 has fields f1,f2,f3.itab2 has fields f2,f3.

You want to populate itab2 only the records in itab1 in which f1 = 'ABC'(i.e. based on condition).

Here is the way to do that.

wa1 is workarea of itab1.

wa2 is workarea of itab2.

loop at itab1 into wa1 where f1 = 'ABC'.

wa2-f2 = wa1-f2.

wa2-f3 = wa1-f3.

append wa2 to itab2.

endloop.

If you are sure that particular condition occurs in itab1 for only one record,you can use Read statement.

Kindly reward points by clikcing the star on the left of reply,if it helps.

If not,get back for clarifications.