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: 

move corresponding question

Former Member
0 Kudos

I would like to do the following in abap:

move-corresponding ls_a TO ls_b where ls_b-components are initial.

Do anybody know a good way to do that?

12 REPLIES 12

Former Member
0 Kudos

hi,

hope both ls_a and ls_b are structure.

syntax will be

If ls_b-(component1) is initial

and ls_b-(component2) is initial

and ls_b-(component3) is initial

.............

move corresponding ls_a to ls_b.

endif.

for further detail check

http://help.sap.com/saphelp_nw70/helpdata/en/fc/eb3260358411d1829f0000e829fbfe/content.htm

regards,

anirban

Former Member
0 Kudos

if both are having the same structure ..

U can write.

ls_b[] = ls_a[] .

Former Member
0 Kudos

if ls-b is initial.

move-corresponding ls_a TO ls_b .

endif.

these two structure must have the same structure

former_member404244
Active Contributor
0 Kudos

Hi,

U can move field by field........from lc_a to lc_b...

Regards,

Nagaraj

Former Member
0 Kudos

Hi,

Check each individual component for value.If it is initial then move components to ls_a TO ls_b.

IF ls_b-component1 is initial.

MOVE ls_a-component1 to ls_b-component1.

ENDIF.

Former Member
0 Kudos

Hi Eza ,

You can use Move Corresponding for tranferring the data from fields from structure Ls_a to same fields in structure Ls_b .

It will work perfectly fine and data tranfer will take place for common fields from Ls_a structure to Ls_b .

regards

Hitesh

Former Member
0 Kudos

Hi,

Move-corresponding will move all the fields from one internal table to another having similar fields.

So to transfer all entries into another internal table we can have move-corresponding itab1 to itab2.

or u can use itab1[ ] = itab2[ ].

If they have same structure.

If we take into account the performance the itab1[ ] = itab2[ ] is much faster than move-corresponding, as move-corresponding has the bottle neck to search all fields of similar name.

Ur code could be :

IF NOT ls_b[] IS INITIAL.
ls_a[] = ls_b[]
ENDIF.

Hope this helps you.

thanx.

dhanashri.

Edited by: Dhanashri Pawar on Jul 31, 2008 12:20 PM

Edited by: Dhanashri Pawar on Jul 31, 2008 12:22 PM

Former Member
0 Kudos

Use Like that

Loop at ls_a where components are initial.

move-corresponding ls_a TO ls_b .

Endloop.

Regards

rajesh

Edited by: RAJESH KUMAR on Jul 31, 2008 3:53 PM

0 Kudos

Thanks.

Not excactly what I was looking for, but thanks..

Wnat to have something that checks for every field if it is initial.

not for the hole structure.

mapping of those fields which are initial in the goal structure.

0 Kudos

do like this ..

loop at ls_b .

case : field1 .

when space .

ls_a = ls_b.

endcase .

endloop.

Former Member
0 Kudos

when U try to move for the first time every field would be initial.

Instead loop at ls_a .. and read ls_b with the key field ..

Loop at ls_a.

read table ls_b with key feild1 = ls_a-field1.

if sy-subrc = 0.

if ls_b-field2 is initial.

ls_b-field2 = ls_a-field2.

endif.

Similarly write for others ....

endif.

endloop.

matt
Active Contributor
0 Kudos

>

> I would like to do the following in abap:

>

> move-corresponding ls_a TO ls_b where ls_b-components are initial.

>

> Do anybody know a good way to do that?

If you know the structures, then you should code it separately for each component of the structures.

i.e.

IF ls_b-comp1 IS INITIAL.
  ls_b-comp1 = ls_a_comp1.
ENDIF.
IF ls_b-comp2 IS INITIAL.
  ls_b-comp2 = ls_a_comp2.
ENDIF.
etc.

If you don't know the structures, and assuming they have the same structure, then use field-symbols. This isn't as fast as when you do, but still not too bad.

DATA: l_count TYPE i.
FIELD-SYMBOLS: <src> TYPE ANY,
              <dst> TYPE ANY.

DO.
  ADD 1 TO l_count.
  ASSIGN COMPONENT l_count OF STRUCTURE ls_a TO <src>.
  IF sy-subrc IS NOT INITIAL.
    EXIT.
  ENDIF.
  ASSIGN COMPONENT l_count OF STRUCTURE ls_b TO <dst>.
  IF sy-subrc IS NOT INITIAL.
    EXIT.
  ENDIF.
  IF <dst> IS INITIAL.
    <dst> = <src>.
  ENDIF.
ENDDO.

matt