‎2012 Apr 23 1:25 PM
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
‎2012 Apr 23 4:24 PM
With one command:
_MOVE_CORR structA structB
where _MOVE_CORR is defined as a macro containing the code from Kumar
Cheers,
Manu.
‎2012 Apr 23 1:39 PM
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.
‎2012 Apr 23 1:54 PM
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.
‎2012 Apr 23 2:19 PM
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
‎2012 Apr 23 4:24 PM
With one command:
_MOVE_CORR structA structB
where _MOVE_CORR is defined as a macro containing the code from Kumar
Cheers,
Manu.
‎2012 Apr 23 4:40 PM
Good point - that would be the answer to all of these "one command" questions.
Rob
‎2012 Apr 24 4:38 AM
‎2012 Apr 23 4:36 PM
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