03-08-2010 3:51 PM
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
03-08-2010 3:58 PM
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.
03-08-2010 4:04 PM
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)?
03-08-2010 5:23 PM
Hi
lets say we have two internal tables ITAB1 and ITAB2
use the below statement :
MOVE-CORRESPONDING ITAB1 TO ITAB2.
Regards
Krishna D
03-08-2010 5:26 PM
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.
03-08-2010 6:46 PM
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
03-09-2010 4:36 AM
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.
03-09-2010 4:51 AM
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
03-09-2010 5:14 AM
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.
09-23-2016 8:30 AM
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.
03-02-2022 8:18 PM
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.