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

move and move-corresponding?

Former Member
0 Likes
2,508

hi friends..

can you tell me difference bt move and move-corresponding with an example program?

thanks in advance

7 REPLIES 7
Read only

Former Member
0 Likes
1,539

hi,

1. Move assigns the value to the specified field.

It is just like a = b.

2. Whereas

3. MOVE-CORRESPONDING STRUCT1 TO STRUCT2

means,

ALL FIELDS HAVING THE SAME NAME,

WILL BECOME EQUAL.

(Rest fields, which do not have same name,

will be ignored)

4. Suppose have a struct1 has 5 fields,

struct 2 has 9 fields,

so instead of giving 5 different lines,

STRUCT2-FIEDL1 = STRUCT1-FIELD1

STRUCT2-FIEDL2 = STRUCT1-FIELD2

STRUCT2-FIEDL3 = STRUCT1-FIELD3

STRUCT2-FIEDL4 = STRUCT1-FIELD4

STRUCT2-FIEDL5 = STRUCT1-FIELD5

We just use MOVE-CORRESPONDING STRUCT1 TO STRUCT2.

Read only

Former Member
0 Likes
1,539

Hi,

move statement is more effienet than move-corresponding.

In case of dialog programming move/movecorresponding stsmt

are used to put internal table workarea data into screen fields.

data: begin of itab occurs 0,

lifnr like lfa1-lifnr,

name1 like lfa1-name1,

ort01 like lfa1-ort01,

end of itab.(here lfa1 is DBtable name)

:

:

  • in case of movecorresponding

Move-Corresponding itab to lfa1.

(here:lfa1 is screen fields name).

  • in case of MOVE stmt.

Move itab-lifnr to lfa1-lifnr.

Move itab-name1 to lfa1-name1.

Move itab-ort01 to lfa1-ort01.

Movecorresponding :

If DBtable having 1000 fields and you are using

movecorresponding, then system has to check all the field in

table to move.

Regards

Sudheer

Read only

Former Member
0 Likes
1,539

Hi

If You have the Same Structure for Both Internal Table you can use simple MOVE statement. Otherwise you have to use MOVE-CORRESPONDING... It will find the corresponding column from the second table and will move to data into that.

For example suppose your itab1 contains 3 columns like

itab-matnr, itab-werks and itab-lgort.

Also your itab2 is

itab2-werks, itab2-lgort,itab2-matnr..

This time if youe are using simple MOVE you will get a type conversion error or something and if you are using MOVE-CORRESPONDING you will get correct movement like

itaab2-matnr = itab1-matnr and

itab2-werks = itab1-werks and

itab2-lgort = itab1-lgort..........

Hope you understood.

Reward All helpfull Answers.........

Read only

Former Member
0 Likes
1,539

Hi,

You use move command to assing data from one variable to another.

Example.

DATA: var1 TYPE c VAULE 'A',

var2 TYPE c.

MOVE var1 to var2.

You use moe-corresponding to move the data from one structure where the definition of both the strucutre are not same.

Example.

DATA: BEGIN OF lst_struct1,

field1,

field2,

field3,

field4,

END OF lst_struct1.

DATA: BEGIN OF lst_struct2,

field2,

field3,

END OF lst_struct2.

MOVE-CORRESPONDING lst_struct1 TO lst_struct2.

Here, you want to populate the data in lst_struct2 from lst_struct1. But both contains the fields in different order. You can not just do lst_struct2 = lst_struct1. Since fields are out of order, you use MOVE-CORRESPONDING.

Check this link for your referece.

http://help.sap.com/saphelp_46c/helpdata/en/34/8e732a6df74873e10000009b38f9b8/frameset.htm

Let me know if you need any other information.

Regards,

Priyanka.

Read only

Former Member
0 Likes
1,539

Hello Selva...

I'll explain it with an example...

if there are two structures stru1 and stru2 with

data: begin of stru1,

a type i,

b type c,

c(2) type c,

end of stru1.

data: begin of stru2,

a1 type i,

b1type c,

c1(2) type c,

end of stru1.

if we use move stru1 to stru2... it workds fine.... Because, te sequence of the fields in both structres are having same type and lengh. Eventhogh if type and lenght are not same it tries for type casting. in case of lenght it may trucate. If type casting is not possible, then it results in DUMP.

Where as MOVE-CORRSPONDING will looks for the same name. If it finds same name it will copy contents of the stru1 to stru2.

Just go through the example bellow.

data: begin of stru1,

a type i,

b type c,

c(2) type c,

end of stru1.

data: begin of stru2,

b type c,

c(2) type c,

a type i,

end of stru1.

MOVE-CORRESPONDING str1 TO str2.

now field contents of str1 will be copied into stru2.

<b>REWARD POINTS IF HELPFUL</b>

Regards

--

Sasidhar Reddy Matli.

Read only

Former Member
0 Likes
1,539

hi,

move statement is used to move a variable or a record from one work area to another. it moves data in a order i.e. field by field the order of fields in in both tables should be same otherwise we will get an error.

move corresponding moves data from one table to another with respect to names of fields. i.e no sequence is maintained . it automatically searches for field names and moves data acoordingly.

generally moves works faster than move-corresponding.

if u move the order in both tables i.e sequence in both tables r same go for move otherwise use move-corresponding.

if helpful reward some points.

with regards,

suresh.

Read only

0 Likes
1,539

good