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 use Move-corresponding in two internal tables with different order

former_member401443
Participant
0 Kudos

If i have two internal table with same fields but in different order and if i have to move body of one internal table to another without using the loop and values to should move

to appropriate fields.

How to use Move-corresponding

10 REPLIES 10

vinod_vemuru2
Active Contributor
0 Kudos

Hi,

It is not possible with body. You have to LOOP and then use MOVE-CORRESPONDING.


LOOP at itab1 to wa1.
CLEAR wa2.
MOVE-CORRESPONDING FIELDS OF wa1 TO wa2.
APPEND wa2 TO itab2.
ENDLOOP.

Thanks,

Vinod.

Sm1tje
Active Contributor
0 Kudos

why are they in two different tables in the first place. Isn't it possible to have it in one (directly from the select statement for example)?

Former Member
0 Kudos

Hi

lets say we have two internal tables ITAB1 and ITAB2

use the below statement :

MOVE-CORRESPONDING ITAB1 TO ITAB2.

Regards

Krishna D

The purpose is to move the whole content of the first table into the second so this doesn't work, as this is only valid for structures. Like someone already said it isn't possible to do this with a single instruction.

_IvanFemia_
Active Contributor
0 Kudos

Hi,

not possible with a single instruction like move corresponding or direct table assignment. The only way is to LOOP across one table a READ in the second one and then MOVE CORRESPONDING.

Regards,

Ivan

Former Member
0 Kudos

Hi,

why dont you declare the 2nd internal table also in the same order as the first one.

and then directly you can move content.

itab2[] = itab1[]

hope it helps.

Former Member
0 Kudos

Hi

There is one more option to do this. You can make use of MOVE without the corresponding addition. For Eg


MOVE: itab1-field1   TO itab2-field2.

Regards

Gaurav

Former Member
0 Kudos

Hi Mukesh,

If you have two internal tables,

say itab1 is i_scarr and

itab2 is i_spfli then the code mentioned shall work fine.

LOOP at i_scar to wa_scar.

CLEAR wa_spfli.

MOVE-CORRESPONDING FIELDS OF wa_scarr TO wa_spfli.

APPEND wa_spfli TO i_spfli.

ENDLOOP.

If it is the case with structures,

Structures must be specified for struc1 and struc2. All components with the same name are searched for in struc1 and struc2 and the content of components in struc1 is assigned to the components with the same name in struc2. All other components are not affected.

The names of the components are compared to the lowest common level. For each comp component pair with the same name, the statement is executed, and - if necessary - the corresponding conversions are performed.

Syntax: MOVE struc1-comp TO struc2-comp.

eg: DATA: BEGIN OF struc1,

comp TYPE c LENGTH 1 VALUE 'U',

comp1 TYPE c LENGTH 1 VALUE 'V',

col1 TYPE c LENGTH 1 VALUE 'X',

col2 TYPE c LENGTH 1 VALUE 'Y',

END OF struc1.

DATA: BEGIN OF struc2,

comp1 TYPE string,

comp2 TYPE string,

comp3 TYPE string,

END OF struc2.

MOVE-CORRESPONDING struc1 TO struc2.

Regards,

Soundarya.

Former Member
0 Kudos

Hello Mukesh,

With the current release, we can direct use Move corresponding from one internal table to another.

For example:

MOVE CORRESPONDING iTab[] to iTab[].

with some options.

Thanks and regards,

Poonam Chandra.

ray_mannion
Participant
0 Kudos

With 7.4, you can do this:

email_data = CORRESPONDING #( report_data ).

In my program, report_data contains objects and alv attributes and stuff not needed for the spreadsheet. So, I move-corresponding the data into the email_data and send it.

This similar to vinod's post above.