06-21-2007 7:49 AM
can anyone explain me how to pack or unpack a field inside a method which is inside a class.
06-21-2007 7:54 AM
Cannot Use PACK
You cannot use the PACK statement to pack character fields in ABAP Objects.
In ABAP Objects, the following statements cause an error message:
DATA: c1(...) TYPE c,
p1(...) TYPE p.
PACK c1 TO p1.
Correct syntax:
DATA: c1(...) TYPE c,
p1(...) TYPE p.
MOVE c1 TO p1.
Cause:
The PACK statement is superfluous, since it works just like the MOVE statement when you assign a character field to a packed number.
press F1 help on PACK and UNPACK statament to know more abt it
06-21-2007 7:54 AM
Hi
See the doc of PACK and UNPACK
PACK source TO destination.
This statement, <b>which is forbidden in classes</b>, converts the content of the data object source to the data type p of length 16 without decimal places. In contrast to the conversion rules for elementary data types, a decimal separator in source is ignored. This assigns the converted content to the data object destination.
The data type of source must be character-type, flat, and its content must be interpretable as a numeric value. The data type of destination must be flat. If destination has the data type p, the interim result is assigned to it from left to right. Surplus characters are cut off on the left, and the decimal places are determined by the data type of destination. If destination does not have the data type p, the interim result is converted to the data type of destination according to the rules in the conversion table for source field type p.
UNPACK source TO destination.
This statement converts the content of the data object source according to a specific rule and assigns the converted content to data object destination. For source, the data type p of length 16 without decimal places is expected. The data type of destination must be character-type and flat.
The conversion is performed according to the following rules:
If the data type of source is not of the type p with length 16 and without decimal places, then the content of source is converted to this data type. Contrary to the rules described in conversion rules for elementary data types, any decimal separator in source is completely ignored.
The digits of the interim result are assigned to data object destination right-aligned and without +/- sign. Any additional places in destination are filled with leading zeros. If the length of destination is not sufficient, the assigned variable is truncated from the left.
Reward points for useful Answers
Regards
Anji