MOVE-CORRESPONDING
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
1. 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.
2. With deep structures, the complete (path) names of the corresponding field pairs must be textually identical.
3. 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.
DATA: BEGIN OF INT_TABLE OCCURS 10,
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
WRITE ... TO
WRITE - Output to a variable
Variants:
1.
WRITE f TO g[+off][(len)].
2.
WRITE f TO itab[+off][(len)] INDEX idx.
Variant 1
WRITE f TO g[+off][(len)].
Addition:
... option
Effect
Assigns the contents of the source field f to the target field g as a new value.
In contrast to MOVE, the format of the target field g is the same as when
outputting to a list with WRITE. The field type C is always used, regardless of the actual data type.
As with list output, the settings in the user's master record for decimal point (period or comma) and date format are taken into account.
Other formatting options are also possible with list output.
Instead of specifying a static source field f, you can also specify a source field (name) dynamically. In this case, the content of the field name is interpreted as the source field name at runtime. The content of this named field is then formatted accordingly.
You can identify the target field g more precisely by specifying the offset and/or length in the form g+off(len). Both the offset and the length specifications off and len can also be dynamic.
In the WRITE name TO g variant, the return code is set as follows:
SY-SUBRC = 0:
Contents of name are valid, statement executed.
SY-SUBRC = 4:
Contents of name are invalid, statement could not be executed, and contents of g remain unchanged.
In other cases, the return code is undefined.
Example
WRITE ... TO with dynamic source field specification and dynamic offset and length specification for the target field:
DATA: NAME(5) VALUE 'FIELD', FIELD(5) VALUE 'Harry',
DEST(18) VALUE 'Robert James Smith', OFF TYPE I,
LEN TYPE I.
OFF = 7.
LEN = 8.
WRITE (NAME) TO DEST+OFF(LEN).
The field DEST now contains the value "Robert Harry ith".
Notes
1. Only values between 0 and the length of the target field g are allowed as offset specifications. Any other offset specifications result in a runtime error.
2. Only values >= 0 are allowed as length specifications. Negative length specifications result in a runtime error. Excessive length specifications are automatically truncated.
3. If you specify the field length as the offset or the value 0 as the length, the target field is blank. In this case, the statement has no effect.
Addition ... option Effect
Modifies the output format with the aid of special formatting options.
Variant 2
WRITE f TO itab[+off][(len)] INDEX idx.
Additions like variant 1.
This variant is not allowed in an ABAP Objects context. See WRITE TO not allowed with internal tables.
Effect
Like variant 1, except that output is to the idx-th line of the internal table itab.
Any offset and/or length specifications refer to the table line used for output.
The Return Code is set as follows:
SY-SUBRC = 0:
Valid index specification, i.e. the internal table itab contains a line with the index idx.
SY-SUBRC = 4:
Index specification is too large, i.e. the internal table itab contains fewer than idx entries.
Note
Invalid index specifications, i.e. idx <= 0, result in a runtime error.
Note
The runtime of WRITE ... TO corresponds with that of the WRITE statement.
However, considerable extra runtime is required if you specify the source field dynamically.
Specifying the target field using offset and length increases the runtime slightly.
WRITE ... TO with a dynamically-specified source field takes around 40 msn (standard microseconds). If you specify the source field statically, the runtime is around 6 msn, or 8 msn if you specify offset and length.
Exceptions
Non-Catchable Exceptions
• Cause: Invalid index specification <= 0 in idx (only in variant 2).
Runtime Error: TABLE_INVALID_INDEX
• Cause: Negative length specification in len.
Runtime Error: WRITE_TO_LENGTH_NEGATIVE
• Cause: Negative offset specification in off.
Runtime Error: WRITE_TO_OFFSET_NEGATIVE
• Cause: Offset specification in off is greater than field length.
Runtime Error: WRITE_TO_OFFSET_TOOLARGE
Related
MOVE, WRITE
Additional help
Assigning Values Using WRITE TO
PACK
PACK
Basic form PACK f TO g.
This statement is not allowed in an ABAP Objects context. See Cannot Use PACK.
Effect
Places the character field f in packed format in the field g. Reverse of the UNPACK statement.
Example
DATA C_FIELD(4) TYPE C VALUE '0103', P_FIELD(2) TYPE P.
PACK C_FIELD TO P_FIELD.
C_FIELD: C'0103' --> P_FIELD: P'103C' Note
The field f can contain up to 16 characters.
Exceptions
Catchable Exceptions
CX_SY_ASSIGN_OUT_OF_RANGE
• Cause: Overflow at conversion (type P)
Runtime Error: BCD_FIELD_OVERFLOW (catchable) CX_SY_CODEPAGE_CONVERTER_INIT
• Cause: Source field cannot be interpreted as a number Runtime Error: CONVT_NO_NUMBER (catchable) CX_SY_CONVERSION_NO_NUMBER
• Cause: Overflow at conversion (all types, but not type P) Runtime Error: CONVT_OVERFLOW (catchable) CX_SY_CONVERSION_OVERFLOW
• Cause: Overflow at conversion (type P)
Runtime Error: BCD_OVERFLOW (catchable)
Non-Catchable Exceptions
• Cause: Source field (type P) does not contain a correct BCD format Runtime Error: BCD_BADDATA
UNPACK
UNPACK
Basic form
UNPACK f TO g.
Effect
Unpacks the packed field f and places it in the field g with leading zeros. If g is too short, it is truncated on the left.
Example
DATA: P_FIELD(2) TYPE P VALUE 103, C_FIELD(4) TYPE C.
UNPACK P_FIELD TO C_FIELD.
P_FIELD: P'103C' --> C_FIELD: C'0103' Notes
1. If f is not type P, it is converted to type P (see MOVE).
2. g should always be type C. Otherwise, unwanted side effects may occur.
3. The sign in the packed number is ignored.
Exceptions
Catchable Exceptions
CX_SY_ASSIGN_OUT_OF_RANGE
• Cause: Overflow during conversion (type P)
Runtime Error: BCD_FIELD_OVERFLOW (catchable) CX_SY_CODEPAGE_CONVERTER_INIT
• Cause: Source field cannot be interpreted as a number Runtime Error: CONVT_NO_NUMBER (catchable) CX_SY_CONVERSION_NO_NUMBER
• Cause: Overflow during conversion (all types except type P) Runtime Error: CONVT_OVERFLOW (catchable)
CX_SY_CONVERSION_OVERFLOW
• Cause: Overflow during conversion (type P) Runtime Error: BCD_OVERFLOW (catchable)
Non-Catchable Exceptions
• Cause: Source field (type P) does not contain a valid BCD format Runtime Error: BCD_BADDATA