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 do i transfer all records in one table to another similar table?

Former Member
0 Kudos

Hi All.

I have two internal tables: ITAB1 and ITAB2.

ITAB1 has columns F3, F4, F5. (filled with records)

ITAB2 has columns F1, F2, F3, F4, F5. (empty internal table)

How do I transfer all the records from ITAB1 to ITAB2, and then assign values to F1 and F2? Will the following codes work? Are there more efficient ways of doing it? Thanks.

*************************************

LOOP AT ITAB1.

APPEND ITAB1 TO ITAB2.

ENDLOOP.

LOOP AT ITAB2.

ITAB2-F1 = 'ABC'.

ITAB2-F2 = SY-TABIX.

ENDLOOP.

1 ACCEPTED SOLUTION

Former Member
0 Kudos

try like tis

LOOP AT ITAB1.

move-corresponding itab1 to itab2.

APPEND ITAB2.

ENDLOOP.

LOOP AT ITAB2.

ITAB2-F1 = 'ABC'.

ITAB2-F2 = SY-TABIX.

modify itab2.

ENDLOOP.

regards

shiba dutta

9 REPLIES 9

Former Member
0 Kudos

try like tis

LOOP AT ITAB1.

move-corresponding itab1 to itab2.

APPEND ITAB2.

ENDLOOP.

LOOP AT ITAB2.

ITAB2-F1 = 'ABC'.

ITAB2-F2 = SY-TABIX.

modify itab2.

ENDLOOP.

regards

shiba dutta

Former Member
0 Kudos

write like this ...

LOOP AT ITAB1.

move corresponding itab1 to itab2.

ITAB2-F1 = 'ABC'.

ITAB2-F2 = SY-TABIX.

append itab2.

clear itab2.

ENDLOOP.

Former Member
0 Kudos

Hi Kian,

Use the below code,

Loop at itab1.

itab2-f3 = itab1-f3. itab2-f4 = itab1-f4. itab2-f5 = itab1-f5.

append itab2.

Endloop.

the above step shall update all records of itab1 to itab2, later you can update itab2 table with f1 and f2 with whatever values you like in whatever manner.

This is the most efficient way of achieving ur requirement.

<b>

Reward points if this helps,

Kiran</b>

Former Member
0 Kudos

Try this,

loop at itab1.

move-corresponding itab1 to itab2.

move 'ABC' to itab2-f1.

move sy-tabix to itab2-f1.

append itab2.

endloop.

Reward points if useful

Regards,

Vimal

Former Member
0 Kudos

see if you can adjust the columns then make the starting fields similar of both the tables and use statement

<b>append lines of</b> itab1 to itab2.

this will move all the records from itab1 to itab2

the append statement is useful performance wise.

then to fill in the other fields you will have to loop.

reward if helpful,

taher

Former Member
0 Kudos

Hi,

Move-Corresponding ITAB1 to ITAB2.

Loop at ITAB1.

Read table ITAB2 with key F3 = ITAB1-F3 F4 = ITAB1-F4 F5 = ITAB1-F5.

If sy-subrc = 0.

ITAB2-F1 = 'ABC'.

ITAB2-F2 = SY-TABIX.

Modify ITAB2.

endif.

Try this,

KC

Former Member
0 Kudos

Hi All, thanks for the reply.

What if my itab has no header line? How should I loop?

Thanks.

*****************************************************

LOOP AT <FS_DYNTAB_TEMP>.

MOVE-CORRESPONDING <FS_DYNTAB_TEMP> TO <FS_DYNTAB_FINAL>.

<FS_DYNTAB_FINAL>-LOAD_ID = TXT_LOAD_ID.

<FS_DYNTAB_FINAL>-RECORD_ID = SY-TABIX.

APPEND <FS_DYNTAB_FINAL>.

ENDLOOP.

*****************************************************

Error: The internal table has no Header line .....

Former Member
0 Kudos

Hi

It can be done by command MOVE CORRESPONDING..

For more info check the F1 help for Move Corresponding Into .

Hope it helps.

Praveen

Former Member
0 Kudos

LOOP AT <FS_DYNTAB_TEMP> INTO <FS_DYNTAB_TEMP_LINE>.

MOVE-CORRESPONDING <FS_DYNTAB_TEMP_LINE> TO <FS_DYNTAB_FINAL_LINE>.

ASSIGN COMPONENT 'LOAD_ID' OF STRUCTURE <FS_DYNTAB_FINAL_LINE> TO <FS_DYNTAB_LOAD_ID>.

ASSIGN COMPONENT 'RECORD_ID' OF STRUCTURE <FS_DYNTAB_FINAL_LINE> TO <FS_DYNTAB_RECORD_ID>.

ASSIGN COMPONENT 'CREATED_BY' OF STRUCTURE <FS_DYNTAB_FINAL_LINE> TO <FS_DYNTAB_CREATED_BY>.

ASSIGN COMPONENT 'CREATED_DATE' OF STRUCTURE <FS_DYNTAB_FINAL_LINE> TO <FS_DYNTAB_CREATED_DATE>.

ASSIGN COMPONENT 'CREATED_TIME' OF STRUCTURE <FS_DYNTAB_FINAL_LINE> TO <FS_DYNTAB_CREATED_TIME>.

ASSIGN COMPONENT 'LAST_CHGED_BY' OF STRUCTURE <FS_DYNTAB_FINAL_LINE> TO <FS_DYNTAB_LAST_CHGED_BY>.

ASSIGN COMPONENT 'LAST_CHGED_DAT' OF STRUCTURE <FS_DYNTAB_FINAL_LINE> TO <FS_DYNTAB_LAST_CHGED_DAT>.

ASSIGN COMPONENT 'LAST_CHGED_TIM' OF STRUCTURE <FS_DYNTAB_FINAL_LINE> TO <FS_DYNTAB_LAST_CHGED_TIM>.

ASSIGN COMPONENT 'USER_STATUS' OF STRUCTURE <FS_DYNTAB_FINAL_LINE> TO <FS_DYNTAB_USER_STATUS>.

ASSIGN COMPONENT 'RECORD_STATUS' OF STRUCTURE <FS_DYNTAB_FINAL_LINE> TO <FS_DYNTAB_RECORD_STATUS>.

<FS_DYNTAB_LOAD_ID> = TXT_LOAD_ID.

<FS_DYNTAB_RECORD_ID> = SY-TABIX.

<FS_DYNTAB_CREATED_BY> = SY-UNAME.

<FS_DYNTAB_CREATED_DATE> = SY-DATUM.

<FS_DYNTAB_CREATED_TIME> = SY-UZEIT.

<FS_DYNTAB_LAST_CHGED_BY> = SY-UNAME.

<FS_DYNTAB_LAST_CHGED_DAT> = SY-DATUM.

<FS_DYNTAB_LAST_CHGED_TIM> = SY-UZEIT.

<FS_DYNTAB_USER_STATUS> = ' '.

<FS_DYNTAB_RECORD_STATUS> = 'L'.

APPEND <FS_DYNTAB_FINAL_LINE> TO <FS_DYNTAB_FINAL>.

CLEAR <FS_DYNTAB_TEMP_LINE>.

CLEAR <FS_DYNTAB_FINAL_LINE>.

CLEAR <FS_DYNTAB_LOAD_ID>.

CLEAR <FS_DYNTAB_RECORD_ID>.

CLEAR <FS_DYNTAB_CREATED_BY>.

CLEAR <FS_DYNTAB_CREATED_DATE>.

CLEAR <FS_DYNTAB_CREATED_TIME>.

CLEAR <FS_DYNTAB_LAST_CHGED_BY>.

CLEAR <FS_DYNTAB_LAST_CHGED_DAT>.

CLEAR <FS_DYNTAB_LAST_CHGED_TIM>.

CLEAR <FS_DYNTAB_USER_STATUS>.

CLEAR <FS_DYNTAB_RECORD_STATUS>.

ENDLOOP.