01-20-2006 8:29 PM
What is wrong with this code? I'm on ECC 5.0 Unicode system.
data: begin of itab occurs 0,
line(255),
end of itab.
data: begin of xtab occurs 0.
data: include structure BAPICONTENT255,
end of xtab.
field-symbols: <fs> type BAPICONTENT255.
Assuming that itab has data, we now move contents from itab to xtab.
loop at itab.
ASSIGN itab-line TO <fs> CASTING.
xtab = <fs>.
append xtab.
endloop.
01-20-2006 8:42 PM
May be i got it wrong...
why do you need 'casting'...that is when you want to cast it to some other type...
try this....
loop at itab.
ASSIGN itab-line TO <fs>.
xtab = <fs>.
append xtab.
endloop.
check the help foe <b>assign</b>
ASSIGN
Syntax
ASSIGN mem_area TO <fs> casting_spec range_spec.
Effect
This statement assigns the memory area specified using mem_area to the field symbol <fs>. You can assign a data object or a memory area calculated from the address of a data object. After the assignment, the field symbol refers to the assigned memory area and can be used in operand positions. When used in a statement, it behaves like a dereferenced data reference, meaning that the statement works with the content of the memory area.
The data type with which the assgigned memory area is treated, depends on the specifications in casting_spec . <u><b>You can either execute an explicit casting or the field symbol takes on the data type of the data object specified in the assignment.</b></u> A field symbol to which a memory area is assigned, has this data type after the assignment and behaves like a data object of this type.
The assigned memory area mem_area must be at least as long as the data type specified in casting_spec and must have the same alignment. If the data type determined in casting_spec is deep, the deep components with their type and position must appear in the assigned memory area exactly like this.
01-20-2006 8:47 PM
Hi
Are you facing a problem with casting?? Bcoz I can see a syntax error while declaring itself.
data: begin of xtab occurs 0.
data: include structure BAPICONTENT255,
end of xtab.
this code has to be
data: begin of xtab occurs 0.
include structure BAPICONTENT255.
data: end of xtab.
chek that out.
Regards
Santosh
01-20-2006 9:02 PM
Please disregard any syntax errors. What I'm more concerned about is the output of xtab. Is that the raw format of itab? Or does it only contain the reference to the content of itab?
01-20-2006 9:05 PM
I used
ASSIGN itab-line TO <fs> casting.
instead of
ASSIGN itab-line TO <fs>.
because if I use the latter, I get an incompatibility error.
01-20-2006 9:11 PM
hi,
i am not getting any error with ur code.
why cant u declare the field symbol as type any
Message was edited by: chandrasekhar jagarlamudi
01-20-2006 9:22 PM
May be I don't know the full picture here, but why do you even need a field-symbol in this case, if you know that you are moving itab to xtab. Why not do it directly like below?
data: begin of itab occurs 0,
line(255).
data: end of itab.
data: begin of xtab occurs 0.
include structure BAPICONTENT255.
data: end of xtab.
loop at itab.
xtab = itab-line.
append xtab.
endloop.
May be I am missing something in your requirement.
Srinivas
01-20-2006 9:29 PM
Because Unicode will not allow you to just transfer data from itab to xtab. Itab is an internal table of characters while xtab has a raw datatype.
01-20-2006 10:06 PM
My mistake for not checking that, but I checked the structure. Why not do this way then?
DATA: BEGIN OF itab OCCURS 0,
line(255).
DATA: END OF itab.
DATA: BEGIN OF xtab OCCURS 0.
INCLUDE STRUCTURE bapicontent255.
DATA: END OF xtab.
LOOP AT itab.
xtab-line = itab-line.
APPEND xtab.
ENDLOOP.
This has no syntax errors in unicode.
01-21-2006 12:02 AM
Hi JB L same old story?
SAP Help says
The length and alignment of the data object must be compatible with the field symbol type. Otherwise the system returns a runtime error.
try
types:
x510(510) type x.
field-symbols:
<x510> type x510.
..
ASSIGN itab-line TO <x510> CASTING.
xtab = <x510>. "Only 127 characters moved.
...
*Let me know if this works or not, TNX.
regards,
Clemens
01-22-2006 1:15 PM
Hi Clemens,
I tried your code unfortunately, I'm getting this error
"ITAB-LINE" must be long enough for the type of "<X510>", regardless of the size of a Unicode character.
Thanks!
01-22-2006 4:32 PM
Hello JB,
if the assign without casting issues a syntax error than most likely its simply not possible to do this conversion. I assume bapicontent contains components other than characters, e.g. an integer or packed number.
You can bypass this only if you first declare a similiar structure containing c-Fields only than you can use a move-corresponding and finally a move to your structure.
Best Regards
Klaus