2006 Jun 15 10:05 PM
I have a structure called 'Struct1', with 27 fields with various lengths in it . I have another structure, called 'Struct2' with 4 fields 'value1' 'value2' 'value3' 'value4' of length 240 char each. I want to move the contents of struct1 in struct2 in such a way that after value1 is filled up, value2 starts getting filled up from that point on and so on. Can you please let me know how to go about this, Thanks.
2006 Jun 15 10:09 PM
If that is the scenario, then why do you need 4 fields. Create a structure with only one field of length 240 * 4 right.
Hope I didnt get your question wrongly.
Sorry...I got your question worngly.
In that you have to count the length of the fields in structure one.
The you have to concatenate all the fields which may come up to 240, then move that value to value1 in struct 2.
Next set of 240 characters from struct1 should be moved to value 2 in struct2 using same method.
Hope I made this point clear. If you need sample code, then let the forum know....we will try to put some sample code in place for you.
Thanks,
Message was edited by: Naren Somen
2006 Jun 15 10:09 PM
hi
you can use MOVE-CORRESPONDING STRUCT1 TO STRUCT2 if both structures have fields with identical name.
else you can use MOVE STRUCT1 TO STRUCT2.
Cheers,
Abdul
2006 Jun 15 10:09 PM
If that is the scenario, then why do you need 4 fields. Create a structure with only one field of length 240 * 4 right.
Hope I didnt get your question wrongly.
Sorry...I got your question worngly.
In that you have to count the length of the fields in structure one.
The you have to concatenate all the fields which may come up to 240, then move that value to value1 in struct 2.
Next set of 240 characters from struct1 should be moved to value 2 in struct2 using same method.
Hope I made this point clear. If you need sample code, then let the forum know....we will try to put some sample code in place for you.
Thanks,
Message was edited by: Naren Somen
2006 Jun 15 10:29 PM
Thank you for all your quick responses. Naren, your answer was very helpful. Just one more question, if all the fields in the struc1 are not char how do i concatenate them. Do i first convert that field to char and then concatenate with the rest. Please let me know. Thanks.
2006 Jun 15 10:34 PM
Hi Sherry,
Yes first You need to convert it to char type and then concatenate..
Reward if it helps
Regards,
Santosh
2006 Jun 15 10:36 PM
hi
you should first convert it to char type field and then use CONCATENATE statement as it only supports Char data type field...
Cheers,
Abdul Hakim
2006 Jun 15 10:10 PM
If both structure have the same fields ..you can use
<b>
MOVE-CORRESPONDING struc1 TO struc2.</b>
<b>FYI</b>
Basic form
MOVE-CORRESPONDING struc1 TO struc2.
Effect
struc1 and struc2 must be structures.
Searches for all names of subfields that occur both in struc1 and struc2. Generates for all relevant field pairs which correspond to the subfields ni, statements of the form
MOVE struc1-ni TO struc2-ni.
The other fields remain unchanged.
Notes
If untyped field symbols or parameters are used for struc1 or struc2 in procedures, the corresponding type is determined at runtime. If struc1 or struc2 are no structures then, a runtime error occurs. If you use untyped operands, in particular, with large structures, the statement executes much more slowly than if you use structures that can be recognized statically.
With deep structures, the complete (path) names of the corresponding field pairs must be textually identical.
The command performs the assignments based on the name identity of the fields. To avoid unintended assignments, you should consider all fields of the source and the target structure. If the source or the target structure has been defined with reference to a type from the ABAP Dictionary (for example, a database table), new fields are subsequently added to that structure by enhancing the ABAPDictionary type. Besides the intended name identities, accidental identies may occur which may result in a wrong program logic.
Example
DATA: BEGIN OF INT_TABLE OCCURS 10,
WORD(10),
NUMBER TYPE I,
INDEX LIKE SY-INDEX,
END OF INT_TABLE,
BEGIN OF RECORD,
NAME(10) VALUE 'not WORD',
NUMBER TYPE I,
INDEX(20),
END OF RECORD.
...
MOVE-CORRESPONDING INT_TABLE TO RECORD.
This MOVE-CORRESPONDING statement is equivalent to both the following statements:
MOVE INT_TABLE-NUMBER TO RECORD-NUMBER.
MOVE INT_TABLE-INDEX TO RECORD-INDEX.
Example
TYPES: BEGIN OF ROW1_3,
CO1 TYPE I,
CO2 TYPE I,
CO3 TYPE I,
END OF ROW1_3.
TYPES: BEGIN OF ROW2_4,
CO2 TYPE I,
CO3 TYPE I,
CO4 TYPE I,
END OF ROW2_4.
TYPES: BEGIN OF MATRIX1,
R1 TYPE ROW1_3,
R2 TYPE ROW1_3,
R3 TYPE ROW1_3,
END OF MATRIX1.
TYPES: BEGIN OF MATRIX2,
R2 TYPE ROW2_4,
R3 TYPE ROW2_4,
R4 TYPE ROW2_4,
END OF MATRIX2.
DATA: ROW TYPE ROW1_3,
M1 TYPE MATRIX1,
M2 TYPE MATRIX2.
ROW-CO1 = 1. ROW-CO2 = 2. ROW-CO3 = 3.
MOVE: ROW TO M1-R1, ROW TO M1-R2, ROW TO M1-R3.
MOVE-CORRESPONDING M1 TO M2.
The last MOVE-CORRESPONDING statement is equivalent to the statements:
MOVE: M1-R2-CO2 TO M2-R2-CO2,
M1-R2-CO3 TO M2-R2-CO3,
M1-R3-CO2 TO M2-R3-CO2,
M1-R3-CO3 TO M2-R3-CO3.
Non-Catchable Exceptions
OBJECT_NOT_STRUCTURED: One of the operands is no structure.
The same runtime errors may occur as with MOVE.
Related
MOVE, ADD-CORRESPONDING, SUBTRACT-CORRESPONDING, MULTIPLY-CORRESPONDING, DIVIDE-CORRESPONDING
Additional help
Assigning Values Using MOVE
Hope thisll give you idea!!
<b>Pl... award the points.</b>
Good luck
Thanks
Saquib Khan
"Some are wise and some are otherwise"