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: 

Problem with Move-Corresponding

Former Member
0 Kudos

Hi Experts,

Please go thru and advice me,


  LOOP AT RAW_MAT WHERE MATNR = FG_MAT-MATNR.
    RAW_MAT-MENGE  =  IFG_MAT-MT101 *  RAW_MAT-MENGE.
    MODIFY RAW_MAT.
  ENDLOOP.

Now I have to move both the internal tablesRAW_MAT and FG_MAT to same internal table IT_FINAL.

As per the requirement of my report, inorder to get multiple (records)

IDNRK from RAW_MAT for every single MATNR in FG_MAT and this is what I have

used as per my requirement. But here my all of my values are repeating twice.

Please go thru and advice if my logic is wrong else advice if there is any appropriate step

inorder to get multiple records from FG_MAT.


LOOP AT FG_MAT.
    MOVE-CORRESPONDING FG_MAT TO IT_FINAL.
    LOOP AT RAW_MAT  WHERE MATNR  = FG_MAT-MATNR
    AND WERKS = FG_MAT-WERKS.
      MOVE RAW_MAT-CKGS  TO  IT_FINAL-CKGS.
      MOVE RAW_MAT-IDNRK  TO  IT_FINAL-IDNRK.
      MOVE RAW_MAT-MENGE  TO  IT_FINAL-MENGE.
      MOVE RAW_MAT-CKGS   TO  IT_FINAL-CKGS.
      MOVE RAW_MAT-MEINS  TO  IT_FINAL-MEINS.
      APPEND IT_FINAL.
      CLEAR: IT_FINAL-M101.
    ENDLOOP.
  ENDLOOP.

Thanks

Karthik

1 ACCEPTED SOLUTION

Former Member
0 Kudos

and also one thing

LOOP AT FG_MAT.

  • MOVE-CORRESPONDING FG_MAT TO IT_FINAL.

LOOP AT RAW_MAT WHERE MATNR = FG_MAT-MATNR

MOVE-CORRESPONDING FG_MAT TO IT_FINAL.

AND WERKS = FG_MAT-WERKS.

MOVE RAW_MAT-CKGS TO IT_FINAL-CKGS.

MOVE RAW_MAT-IDNRK TO IT_FINAL-IDNRK.

MOVE RAW_MAT-MENGE TO IT_FINAL-MENGE.

MOVE RAW_MAT-CKGS TO IT_FINAL-CKGS.

MOVE RAW_MAT-MEINS TO IT_FINAL-MEINS.

APPEND IT_FINAL.

CLEAR: IT_FINAL-M101.

ENDLOOP.

ENDLOOP.

put MOVE-CORRESPONDING FG_MAT TO IT_FINAL inside the loop. it works..

11 REPLIES 11

I355602
Advisor
Advisor
0 Kudos

Hi,

For best coding practice we should avoid using MOVE-CORRESPONDING

It has some effect with performance issues.

So we always avoid using this keyword and use:-


MOVE str TO str1.

Regards,

Tarun

Former Member
0 Kudos

Hi,

before nested looping.

first sort the tables and delete adjacent duplicates for those tables.

Then u will get result fine..

Regards,

Kiran

dev_parbutteea
Active Contributor
0 Kudos

Hi,

Clear your variables after append

> LOOP AT FG_MAT.

> MOVE-CORRESPONDING FG_MAT TO IT_FINAL.

> LOOP AT RAW_MAT WHERE MATNR = FG_MAT-MATNR

> AND WERKS = FG_MAT-WERKS.

> MOVE RAW_MAT-CKGS TO IT_FINAL-CKGS. --> moved twice

> MOVE RAW_MAT-IDNRK TO IT_FINAL-IDNRK.

> MOVE RAW_MAT-MENGE TO IT_FINAL-MENGE.

> MOVE RAW_MAT-CKGS TO IT_FINAL-CKGS.

> MOVE RAW_MAT-MEINS TO IT_FINAL-MEINS.

> APPEND IT_FINAL.

> CLEAR: IT_FINAL-M101,

> IT_FINAL-CKGS,IT_FINAL-IDNRK, IT_FINAL-MENGE ,IT_FINAL-MEINS.

> ENDLOOP.

> clear IT_FINAL.

> ENDLOOP.

Former Member
0 Kudos

and also one thing

LOOP AT FG_MAT.

  • MOVE-CORRESPONDING FG_MAT TO IT_FINAL.

LOOP AT RAW_MAT WHERE MATNR = FG_MAT-MATNR

MOVE-CORRESPONDING FG_MAT TO IT_FINAL.

AND WERKS = FG_MAT-WERKS.

MOVE RAW_MAT-CKGS TO IT_FINAL-CKGS.

MOVE RAW_MAT-IDNRK TO IT_FINAL-IDNRK.

MOVE RAW_MAT-MENGE TO IT_FINAL-MENGE.

MOVE RAW_MAT-CKGS TO IT_FINAL-CKGS.

MOVE RAW_MAT-MEINS TO IT_FINAL-MEINS.

APPEND IT_FINAL.

CLEAR: IT_FINAL-M101.

ENDLOOP.

ENDLOOP.

put MOVE-CORRESPONDING FG_MAT TO IT_FINAL inside the loop. it works..

Former Member
0 Kudos

Use At New MATNR to loop on each MATNR only once.

LOOP AT FG_MAT.

AT NEW MATNR.

MOVE-CORRESPONDING FG_MAT TO IT_FINAL.

LOOP AT RAW_MAT WHERE MATNR = FG_MAT-MATNR

AND WERKS = FG_MAT-WERKS.

MOVE RAW_MAT-CKGS TO IT_FINAL-CKGS.

MOVE RAW_MAT-IDNRK TO IT_FINAL-IDNRK.

MOVE RAW_MAT-MENGE TO IT_FINAL-MENGE.

MOVE RAW_MAT-CKGS TO IT_FINAL-CKGS.

MOVE RAW_MAT-MEINS TO IT_FINAL-MEINS.

APPEND IT_FINAL.

CLEAR: IT_FINAL-M101.

ENDLOOP.

ENDAT.

ENDLOOP.

Regards,

Anil

Former Member
0 Kudos

Move-corresponding fg_mat[] to it_final[].           "--------->Get all Data of Fg_mat inot table IT_final

Loop at raw_mat.
Read table it_final with key matnr = raw_mat-matnr.     "----------> Read matching materials.
If sy-sunrc = 0.
Modify it_final from raw_mat transproting CKGS IDNRK MENGE  CKGS   MEINS . "--->If the material matches modify It_final
endif.
endloop.

Regards,

Gurpreet

Former Member
0 Kudos

Before going to loop you have to sort the internal table and delete the adjacent duplicates.

It is better to avoid Move-Corresponding because of performance issue. After appending the internal table you want to clear the header.

You check the data while debugging.

Regards,

Joan

former_member222860
Active Contributor
0 Kudos

Chek this:

LOOP AT FG_MAT.
READ TABLE RAW_MAT WITH KEY MATNR = FG_MAT-MATNR
                            WERKS = FG_MAT-WERKS.
      MOVE RAW_MAT-CKGS  TO  IT_FINAL-CKGS.
      MOVE RAW_MAT-IDNRK  TO  IT_FINAL-IDNRK.
      MOVE RAW_MAT-MENGE  TO  IT_FINAL-MENGE.
      MOVE RAW_MAT-CKGS   TO  IT_FINAL-CKGS.
      MOVE RAW_MAT-MEINS  TO  IT_FINAL-MEINS.
      APPEND IT_FINAL.
      CLEAR: IT_FINAL-M101.
 ENDLOOP.

Former Member
0 Kudos

Hi Experts,

Non of the above said logic is working for me,

My output is correct if lifnr, werks and budat is obligatory in selection screen but I am worried if there won't be any problem in future.

Also if write like the below, my output is correct in development as there are only few records in it

Please advice me.


SORT RAW_MAT BY IDNRK WERKS.
DELETE ADJACENT DUPLICATES FROM RAW_MAT  COMPARING ALL FIELDS.

0 Kudos

Hi,

Generally we dnt use MOVE-CORRESPONDING due to some performance issues

If we use:-

MOVE-CORRESPONDING it_header TO it_final.

Then this statement will match all the fields from it_header to it_final till it finds the same column and then transfer the values from one to other table.

So, this is considered to be time taking and a lot of resources can be used in this process.

However if we use:-


LOOP AT it_header.
  MOVE : it_header-field1 TO it_final-field1,
         it_header-field2 TO it_final-field2,
         it_header-field3 TO it_final-field3.
         " and so on.....
  APPEND it_final.
  CLEAR it_final.
  CLEAR it_header.
ENDLOOP.

Using this approcah we already mae sure the field type match.

So no extra time is taken to find the appropiate field type.

And thus eliminates performance issues.

For reference reading on Performance Issues you can refer link:-

https://www.sdn.sap.com/irj/scn/wiki?path=/display/abap/performance

Hope this helps you.

Regards,

Tarun

Former Member
0 Kudos

Karthik-

Have you solved you issue yet? I was away on vacation, so I was unable to respond.

If you are still looking for help - I would be curious as to the contents of the IT_RAW and the FG_MAT tables before you begin the process of totaling. I am wondering if some of the results are causing the double rows.

Regards,

Mark

Edited by: Mark Schwendinger on Mar 16, 2009 7:19 PM