2004 Dec 17 6:36 AM
Hi All ,
I want to know if casting of data types is possible in ABAP. I mean if I have declared a datatype as
data : x type char5.
and Now I want to make x as char10.
Is there any method to achieve this?
Thanks and regards
Sujeet
2004 Dec 17 8:41 AM
Hi Sujeet
If your requirement suits, you can use dynamic programming which is a nice feature of ABAP.
You can use field-symbols (think them of as aliases for fields) or generic variables.
For more information I recommend the e-class <a href="https://www.sdn.sap.com/sdn/elearning.sdn?class=/public/eclasses/teched04/ABAP351.htm">"Advanced and Generic Programming in ABAP"</a>.
As a last thing, let me introduce you the SDN forums pointing system: You can assign points to posts which help you solving your problem. You can reward points by clicking the yellow star icon at header of each post. You can assign:
- one 10 points (solved)
- two 6 points (very helpful answer)
- many 2 points (helpful answer)
Kind regards...
*--Serdar
2004 Dec 17 6:47 AM
Why don't you use Field-Symbols, you can use it for any type, not just characters and of any length ?
data: x type char5,
y type char10.
FIELD-SYMBOLS : <FS> TYPE ANY.
assign x to <FS>.
write : <FS>.
assign y to <FS>.
write: <FS>.
Secondly, I don't think it would be possible to cast from a lower length character type to a higher length character type.
You can do casting in <b>ASSIGN</b>.
Regards,
Subramanian V.
2004 Dec 17 6:59 AM
Hello Sujeet,
Once you have declared the variable x with the type CHAR5, you cannot change the type of this variable.
However, you have the option of using a field-symbol. You can declare a generic field symbol and assign to it any data object of any length (or type). Consider this example.
field-symbols <fs> type any.
data : char1(5) type c value 'SAPAG',
char2(8) type c value 'SAPINDIA'.
assign char1 to <fs>.
write <fs>.
assign char2 to <fs>.
write <fs>.
Get back if you still have any doubts.
Regards,
Anand Mandalika.
2004 Dec 17 8:32 AM
Casting is possible using field-symbols. There are various options around the ASSIGN command. However casting char5 to char10 is problematic, since the original is smaller than the target representation.
Kind Regards
Klaus
2004 Dec 17 8:41 AM
Hi Sujeet
If your requirement suits, you can use dynamic programming which is a nice feature of ABAP.
You can use field-symbols (think them of as aliases for fields) or generic variables.
For more information I recommend the e-class <a href="https://www.sdn.sap.com/sdn/elearning.sdn?class=/public/eclasses/teched04/ABAP351.htm">"Advanced and Generic Programming in ABAP"</a>.
As a last thing, let me introduce you the SDN forums pointing system: You can assign points to posts which help you solving your problem. You can reward points by clicking the yellow star icon at header of each post. You can assign:
- one 10 points (solved)
- two 6 points (very helpful answer)
- many 2 points (helpful answer)
Kind regards...
*--Serdar