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: 

Corresponding

Former Member
0 Kudos

Hi all,

What is the exact use of corresponding?

Identical structure in the sense same fields or same structure?

What will happen if not same name and also not same fields while using corresponding???

Message was edited by:

arunshori ganesan

1 ACCEPTED SOLUTION

former_member186143
Active Contributor
0 Kudos

that you don't have to declare all the fields individually.

so when you say into corresponding fields of table alle fields with the same name from the source are transported to fields with the same fieldname in the target area.

kind regards

arthur

11 REPLIES 11

former_member186143
Active Contributor
0 Kudos

that you don't have to declare all the fields individually.

so when you say into corresponding fields of table alle fields with the same name from the source are transported to fields with the same fieldname in the target area.

kind regards

arthur

former_member196280
Active Contributor
0 Kudos

We have

SUBTRACT-CORRESPONDING

ADD-CORRESPONDING

MULTIPLY-CORRESPONDING

DIVIDE-CORRESPONDING

MOVE-CORRESPONDING

Ex:

MOVE-CORRESPONDING struc1 TO struc2.

Effect

<b>Interprets struc1 and struc2 as structures. If, for example, struc1 and struc2 are tables, it executes the statement for their header lines.

Searches for the sub-fields which occur both in struc1 and struc2 and then generates, for all relevant field pairs which correspond to the sub-fields ni, statements of the form</b>

MOVE struc1-ni TO struc2-ni.

The other fields remain unchanged.

With complex structures, the full names of the corresponding <b>field pairs must be identical</b>.

Example

TYPES: BEGIN OF ROW1_3,

CO1 TYPE I,

CO2 TYPE I,

CO3 TYPE I,

END OF ROW1_3.

TYPES: BEGIN OF ROW2_4,

CO2 TYPE I,

CO3 TYPE I,

CO4 TYPE I,

END OF ROW2_4.

TYPES: BEGIN OF MATRIX1,

R1 TYPE ROW1_3,

R2 TYPE ROW1_3,

R3 TYPE ROW1_3,

END OF MATRIX1.

TYPES: BEGIN OF MATRIX2,

R2 TYPE ROW2_4,

R3 TYPE ROW2_4,

R4 TYPE ROW2_4,

END OF MATRIX2.

DATA: ROW TYPE ROW1_3,

M1 TYPE MATRIX1,

M2 TYPE MATRIX2.

ROW-CO1 = 1. ROW-CO2 = 2. ROW-CO3 = 3.

MOVE: ROW TO M1-R1, ROW TO M1-R2, ROW TO M1-R3.

MOVE-CORRESPONDING M1 TO M2.

The last MOVE-CORRESPONDING statement is equivalent to the statements:

MOVE: M1-R2-CO2 TO M2-R2-CO2,

M1-R2-CO3 TO M2-R2-CO3,

M1-R3-CO2 TO M2-R3-CO2,

M1-R3-CO3 TO M2-R3-CO3.

Regards,

SaiRam

Former Member
0 Kudos

if you two internal tables of not identical structure ie some fields in common.

move-corresponding itab1 to itab2.

this will copy the fields that have identical names in itab1 to itab2, other fields which does not match will be left blank

Former Member
0 Kudos

Hi

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

INTO CORRESPONDING FIELDS OF TABLE is transferring the value from select clause to itab where the field names are same.

suppose you have

data : begin of itab occurs 0,

matnr like mara-matnr,

menge like mseg-menge,

lgort like mard-lgort,

end of itab.

select matnr lgort into table from mard where....

it may give an error because you are not filling menge here or it may fetch the value in matnr and menge field.

but if you use INTO CORRESPONDING FIELDS OF TABLE then it will fetch the data to matnr and lgort field only.

INTO CORRESPONDING FIELDS OF TABLE is only matching by name not by datatype be careful.

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

ADD-CORRESPONDING rec1 TO rec2.

Effect

Interprets rec1 and rec2 as field strings. If, for example, rec1 and rec2 are tables, executes the statement for their header lines.

Searches for all sub-fields which occur both in rec1 and rec2 and then, for all relevant field pairs corresponding to the sub-fields ni , generates statements of the form

ADD rec1-ni TO rec2-ni.

The other fields remain unchanged.

With complex structures, the complete names of the corresponding field

pairs must be textually identical.

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

MOVE-CORRESPONDING rec1 TO rec2.

Effect

Interprets rec1 and rec2 as field strings. If, for example, rec1 and rec2 are tables, executes the statement for their header lines.

Searches for the sub-fields which occur both in rec1 and rec2 and then generates, for all relevant field pairs which correspond to the sub-fields ni , statements of the form

MOVE rec1-ni TO rec2-ni.

The other fields remain unchanged.

With complex structures, the full names of the corresponding field pairs must be identical.

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

SUBTRACT-CORRESPONDING rec1 FROM rec2.

Effect

Interprets rec1 and rec2 as field strings. If, for example, rec1 and rec2 are tables, executes the statement for their header lines.

Searches for all sub-fields which occur both in rec1 and rec2 and then generates, for all relevant field pairs corresponding to the component fields ni , statements of the form

SUBTRACT rec1-ni FROM rec2-ni.

The other fields remain unchanged.

With complex structures, the full names of the field pairs must be identical.

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

MULTIPLY-CORRESPONDING rec1 BY rec2.

Effect

Interprets rec1 and rec2 as field strings. If, for example, rec1 and rec2 are tables, executes the statement for their header lines.

Searches for all sub-fields which occur both in rec1 and rec2 and then generates, for all field pairs corresponding to the sub-fields ni , statements of the form

MULTIPLY rec1-ni BY rec2-ni.

The other fields remain unchanged.

With complex structures, the full names of the corresponding field pairs must be identical.

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

DIVIDE-CORRESPONDING rec1 BY rec2.

Effect

Interprets rec1 and rec2 as field strings, i.e. if rec1 and rec2 are tables with header lines, the statement is executed for their header lines.

Searches for all sub-fields that occur both in rec1 and rec2 and then generates, for all field pairs corresponding to the sub-fields ni , statements similar in the following form:

DIVIDE rec1-ni BY rec2-ni.

The other fields remain unchanged.

With more complex structures, the complete names of the field pairs must be identical.

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

Please go through this link.

http://www.sts.tu-harburg.de/teaching/sap_r3/ABAP4/add_corr.htm

Regards

Vasu

varma_narayana
Active Contributor
0 Kudos

Hi

CORRESPONDING option is used to Copy the fields based on their name (matching fields) instead of their Position.

So only when the Field names are same it will copy the data.

It is used in 2 cases:

1)

MOVE-CORRESPONDING WA1 TO WA2.

"To copy identical fields from one wa to anothter

2) SELECT <FIELDS> FROM <DBTABLE> INTO CORRESPONDING FIELDS OF TABLE <ITAB>

reward if Helpful.

Former Member
0 Kudos

Hello,

We use CORRESPONDING with following options

SUBTRACT-CORRESPONDING

ADD-CORRESPONDING

MULTIPLY-CORRESPONDING

DIVIDE-CORRESPONDING

MOVE-CORRESPONDING

Generally we use <b>CORRESPONDING</b>, if we have two different internal tables/structures with some common fields(and order of the common fields in those internal tables/structures also different) in them.

Ex: MOVE-CORRESPONDING source to destination.

In this case values of common fields with the same name will be moved from source to destination.

<b>Reward Points If Useful</b>

Regards, Srikanth

Former Member
0 Kudos

hi,

please see below declaration..

data: begin of itab occurs 0,

matnr type mara-matnr,

ersda type mara-ersda,

ernam type mara-ernam,

end of itab.

select matnr

ernam

from mara

into table itab.

if u see aboveinternal table declaration ernam is the third place. if u write the select qurey (please see below) ernam will sit in second plzce of internal table some times type mismatch may occur in that case program give dump.

if u use into corresponding fields of table itab selected field will sit in writght place of internal table.

thsi is the difference between corresponding and normal select query...

thanks,

maheedhar

Former Member
0 Kudos

Hi Ganesh,

report zsubfield.

data : f1 type i value 1,

  • field string

begin of s1,

c1 type i value 10,

c2 type i value 20,

c3 type i value 30,

end of s1.

data : f2 type i value 5,

  • field string

begin of s2,

c1 type i value 40,

c2 type i value 50,

c3 type i value 60,

end of s2.

write : / f1.

add-corresponding s1 to s2.

write : / s2-c1,

s2-c2,

s2-c3.

subtract-corresponding s1 from s2.

write : / s2-c1,

s2-c2,

s2-c3.

multiply-corresponding s2 by s1.

write : / s2-c1,

s2-c2,

s2-c3.

Try to understand this program. You will come to know the usage of Corresponding..

Regards,

Sai

Former Member
0 Kudos

hi,

Corresponding keyword is used in two cases.

1. INTO CORRESPONDING

2. MOVE-CORRESPONDING

corresponding generally used when we don't know the order of fields that are declared in internal tables and to move data into that table with out bothering for order we go for it.

generally the order in which we declare in internal tables should be used in populating data otherwise it displays a error for us.

in order to skip this procedure we go for corresponding and if we use corresponding then the field names are taken into consideration rather than index and data is placed into corresponding fields by comparing manes of fields.

if helpful reward some points.

with regards,

Suresh Aluri.

Former Member
0 Kudos

move corresponding in select query that means its moves the feild data to the declared itab from header to the body correspondingly , if we r not using it inthe select statement, it generals moves the data directly into the body.

but it always better to use move corresponding in the select stament

regards

prasanth kumar

Former Member
0 Kudos

Hi,

MOVE-CORRESPONDING struc1 TO struc2.

Effect

Structures have to be specified for struc1 and struc2.<b> All components with the same name are searched for in struc1 und struc2 and the content of components in struc1 is assigned to the components with the same name in struc2M.</b> All other components are not affected.

Nested structures are fully expanded. <b>The names of the components are compared to the lowest common level. For each comp component pair with the same name, the</b>

<b>MOVE struc1-comp TO struc2-comp.

statement is executed, and - if necessary - the corresponding conversions are performed.</b>

Before Release 6.10, specified field symbols or formal parameters had to be structured and typed for struc1 and struc2. Since Release 6.10, untyped field symbols or formal parameters can be used for struc1 and struc2. These have to be structures when the statement is executed, otherwise this triggers an untreatable exception.

Note

<b>If structures are specified for struc1 and struc2, the name is compared once when the program is generated by the ABAP Compiler. If untyped field symbols or formal parameters are used, the names must be compared each time the statement is executed</b>.

Example

In the struc1 and struc2 structures there are the components struci-comp1 and struci-comp2. These are asssigned from struc1 to struc2. In struc1, struci-comp2 is self-structured, in struc2, struci-comp is elementary. For the assignment of struc1-struci-comp1 to struc2-struci-comp1 , the source field is interpreted as an elementary field of type c according to the conversion rules for structures. The struc1-comp1 and struc2-struci-comp3 components do not have any equivalents with the same name and are not considered for the assignment.

DATA: BEGIN OF struc1,

comp(1) TYPE c VALUE 'X',

BEGIN OF struci,

comp1(1) TYPE c VALUE 'Y',

BEGIN OF comp2,

comp(1) TYPE c VALUE 'Z',

END OF comp2,

END OF struci,

END OF struc1.

DATA: BEGIN OF struc2,

BEGIN OF struci,

comp1(1) TYPE c,

comp2(1) TYPE c,

comp3(1) TYPE c,

END OF struci,

END OF struc2.

MOVE-CORRESPONDING struc1 TO struc2.

Regards,