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

Help with respect data transfer between two structures

Former Member
0 Likes
805

Hi,

How can we move data between two structures which are similar using one command without overwriting the data in the target structure?

Example :- Structure A and Structure B are similar in type with 5 fields each. A has data in fields 1 & 2. Where as B has data in 4 & 5. Now I need to transfer the data of fields 1 & 2 of structure A into 1 & 2 of Structure B without disturbing the values in 3,4 & 5 fields of Structure B.

How can we make it? Requesting your suggestions.

Regards,

Sanjeev

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
739

With one command:

_MOVE_CORR structA structB

where _MOVE_CORR is defined as a macro containing the code from Kumar

Cheers,

Manu.

7 REPLIES 7
Read only

Private_Member_49934
Product and Topic Expert
Product and Topic Expert
0 Likes
739

Assuming structure 1 name  = wa_stru1.

structure 2 name = wa_stru2. and both structure have the same type

do the following code

  

FIELD-SYMBOLS : <fs_any1> TYPE ANY,
                 <fs_any2> TYPE ANY.
  DO.
    ASSIGN COMPONENT sy-index OF STRUCTURE wa_stru1
    TO <fs_any1>.
    IF sy-subrc NE 0.
      EXIT.
    ENDIF.
    IF <fs_any1> IS NOT INITIAL.
      ASSIGN COMPONENT sy-index OF STRUCTURE wa_stru2 TO <fs_any2>.
      IF sy-subrc = 0 AND <fs_any2> IS INITIAL.
        <fs_any2> =  <fs_any1>.
      ENDIF.
    ENDIF.
  ENDDO.

Read only

Former Member
0 Likes
739

Hi Sanjeeva,

As far as i know it isn't possible to make that assignation with only one instruction.

You could use an CASE/IF for each substructure or to use field symbols.

Regards.

Read only

ThomasZloch
Active Contributor
0 Likes
739

You could introduce a structure C with just the fields 1 & 2 and then

MOVE-CORRESPONDING structureA to structureC.

MOVE-CORRESPONDING structureC to structureB.

Don't limit yourself to artificial "with one command" restrictions, unless this is an exam or interview-type of question, which are forbidden anyway.

Thomas

Read only

Former Member
0 Likes
740

With one command:

_MOVE_CORR structA structB

where _MOVE_CORR is defined as a macro containing the code from Kumar

Cheers,

Manu.

Read only

0 Likes
739

Good point - that would be the answer to all of these "one command" questions.

Rob

Read only

0 Likes
739

Good one Manu!

Jake.

Read only

0 Likes
739

Hi Sanjeev,

u can try like this.

Assume str1 has structure = wa1.

And structure2 has structure = wa2.

then try this ,

wa2-f1  =  wa1-f1.

wa2-f2  =  wa1-f2.

Please check it and confirm.

regards

sandeep