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-corresponding is not working

Former Member
0 Likes
3,613

Hi All,

I have 2 structures like this.

DATA: BEGIN OF ITAB1 OCCURS 0,

zuonr(18) TYPE c,

group(10) TYPE c,

s_amt type invfo-WRBTR,

END OF ITAB1.

DATA : BEGIN OF TABC OCCURS 0,

ZUONR LIKE ITAB1-ZUONR,

GROUP LIKE ITAB1-GROUP,

SALE_AMT LIKE ITAB1-S_AMT,

END OF TABC.

LOOP AT ITAB1.

move-corresponding ITAB1 TO TABC.

APPEND TABC.

CLEAR TABC.

ENDLOOP.

I am getting zuonr and group values into TABC. But I am not getting values into Sale_Amt field.

What is wrong in the above code??

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
2,238

The field names must be same

S_AMT <> SALE_AMT

Hi All,

I have 2 structures like this.

DATA: BEGIN OF ITAB1 OCCURS 0,

zuonr(18) TYPE c,

group(10) TYPE c,

s_amt type invfo-WRBTR,

END OF ITAB1.

DATA : BEGIN OF TABC OCCURS 0,

ZUONR LIKE ITAB1-ZUONR,

GROUP LIKE ITAB1-GROUP,

SALE_AMT LIKE ITAB1-S_AMT,

END OF TABC.

LOOP AT ITAB1.

move-corresponding ITAB1 TO TABC.

APPEND TABC.

CLEAR TABC.

ENDLOOP.

I am getting zuonr and group values into TABC. But I am not getting values into Sale_Amt field.

What is wrong in the above code??

8 REPLIES 8
Read only

Former Member
0 Likes
2,239

The field names must be same

S_AMT <> SALE_AMT

Read only

Former Member
0 Likes
2,238

Hi,

you have to set same name for S_AMT field, like this:

DATA: BEGIN OF ITAB1 OCCURS 0,

zuonr(18) TYPE c,

group(10) TYPE c,

s_amt type invfo-WRBTR,

END OF ITAB1.

DATA : BEGIN OF TABC OCCURS 0,

ZUONR LIKE ITAB1-ZUONR,

GROUP LIKE ITAB1-GROUP,

<b>S_AMT</b> LIKE ITAB1-S_AMT,

END OF TABC.

reward

Read only

Former Member
0 Likes
2,238

The fields need to have the same name, but here one is call s_amt and one sale_amt. If your tables have the same structure (as they appear to have here) you don't need to use MOVE-CORRESPONDING, just MOVE.

Regards,

Nick

Read only

Former Member
0 Likes
2,238

DATA: BEGIN OF ITAB1 OCCURS 0,

zuonr(18) TYPE c,

group(10) TYPE c,

s_amt type invfo-WRBTR,

END OF ITAB1.

DATA : BEGIN OF TABC OCCURS 0,

ZUONR LIKE ITAB1-ZUONR,

GROUP LIKE ITAB1-GROUP,

<b>SALE_AMT</b> LIKE ITAB1-S_AMT, <u>"Change SALE_AMT to s_amt - Fields should be matchable.</u>END OF TABC.

LOOP AT ITAB1.

move-corresponding ITAB1 TO TABC.

APPEND TABC.

CLEAR TABC.

ENDLOOP.

Read only

varma_narayana
Active Contributor
0 Likes
2,238

Hi ..

MOVE-Corresponding <WA1> to <wa2>.

This statement will assign the fields from WA1 to WA2 based on the Field names matching.

So it is only copying where the Field names are same.

Then you can change the code like this.

DATA: BEGIN OF ITAB1 OCCURS 0,

zuonr(18) TYPE c,

group(10) TYPE c,

s_amt type invfo-WRBTR,

END OF ITAB1.

DATA : BEGIN OF TABC OCCURS 0,

ZUONR LIKE ITAB1-ZUONR,

GROUP LIKE ITAB1-GROUP,

SALE_AMT LIKE ITAB1-S_AMT,

END OF TABC.

LOOP AT ITAB1.

<b>move ITAB1 TO TABC.</b>

APPEND TABC.

CLEAR TABC.

ENDLOOP.

<b>Reward if Helpful.</b>

Read only

former_member404244
Active Contributor
0 Likes
2,238

Hi,

do like this

DATA: BEGIN OF ITAB1 OCCURS 0,

zuonr(18) TYPE c,

group(10) TYPE c,

s_amt type invfo-WRBTR,

END OF ITAB1.

DATA : BEGIN OF TABC OCCURS 0,

ZUONR LIKE ITAB1-ZUONR,

GROUP LIKE ITAB1-GROUP,

s_amt type invfo-WRBTR,

END OF TABC.

Regards,

Nagaraj

Read only

Former Member
0 Likes
2,238

Two approaches,,,

1> change the 3rd component name of either WA to match the other one.. and the code will work,,,

2> instead of move corrosponding use. simply move.. it will move data byte by byte irrespective of file name and size.. (note atlease the secquence , datatype , length should be same). in this approach the file name match is nt required and is quite faster then the move corrosonding

happy coding..

Read only

Former Member
0 Likes
2,238

Hi Priya,

DATA: BEGIN OF ITAB1 OCCURS 0,

zuonr(18) TYPE c,

group(10) TYPE c,

s_amt type invfo-WRBTR,

END OF ITAB1.

DATA : BEGIN OF TABC OCCURS 0,

ZUONR LIKE ITAB1-ZUONR,

GROUP LIKE ITAB1-GROUP,

SALE_AMT LIKE ITAB1-S_AMT,

END OF TABC.

LOOP AT ITAB1.

move-corresponding ITAB1 TO TABC.

<b>TABC-SALE_AMT = ITAB1-s_amt.</b>

APPEND TABC.

CLEAR TABC.

ENDLOOP.