Application Development Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 

Casting Problem

Former Member
0 Kudos

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.

11 REPLIES 11

Former Member
0 Kudos

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.

0 Kudos

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

0 Kudos

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?

0 Kudos

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.

0 Kudos

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

Former Member
0 Kudos

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

0 Kudos

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.

0 Kudos

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.

Clemenss
Active Contributor
0 Kudos

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

Former Member
0 Kudos

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!

former_member183804
Active Contributor
0 Kudos

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