Application Development and Automation 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: 
Read only

Field symbols - casting error

Former Member
0 Likes
1,044

Hi,

I created a table dynamically and assigned it to field symbol. Now i want to write the contents of the internal table to a flat file in app server. Here is what i am doing.

parameters: p_table(30) type c default 'PA0008',

p_file LIKE RLGRAP-FILENAME default '/usr/sap/tmp/test.txt'. " Path to save files to

FIELD-SYMBOLS: <w_table> type standard table,

<w_wa> TYPE any,

<w_field> type any.

DATA: w_dyn_wa type ref to data,

w_dyn_table type ref to data.

CREATE DATA w_dyn_wa TYPE (p_table). "Suitable work area

ASSIGN w_dyn_wa->* TO <w_wa>.

create data w_dyn_table type standard table of (p_table).

assign w_dyn_table->* to <w_table>.

data w_dyn_data(5000) type c.

SELECT * FROM (p_table) INTO table <w_table> where endda >= sy-datum.

Data: w_temp type string.

OPEN DATASET p_file FOR OUTPUT IN TEXT MODE encoding default.

IF SY-SUBRC = 0.

loop at <w_table> into <w_wa>.

w_temp = ''.

do.

assign component sy-index of structure <w_wa> to <w_field>.

if sy-subrc <> 0.

exit.

endif.

concatenate w_temp <w_field> into w_temp respecting blanks.

if sy-index = 1.

transfer '' to p_file.

endif.

  • transfer <w_field> to p_file no end of line.

enddo.

transfer w_temp to p_file no end of line.

write:/ w_temp.

endloop.

endif.

close dataset p_file.

when i run the program with PA0008 i am getting a casting error "Object not char like". How do i get rid of this error?. I tried moving the contents of field symbol to a string and appending it. It worked, but i lost the exact formatting of data in the file. In other words, it got rid of extra blanks. I need exact structure of internal table in the file.

Thanks,

Sandeep

Thanks,

Sandeep

Hi,

I created a table dynamically and assigned it to field symbol. Now i want to write the contents of the internal table to a flat file in app server. Here is what i am doing.

parameters: p_table(30) type c default 'PA0008',

p_file LIKE RLGRAP-FILENAME default '/usr/sap/tmp/test.txt'. " Path to save files to

FIELD-SYMBOLS: <w_table> type standard table,

<w_wa> TYPE any,

<w_field> type any.

DATA: w_dyn_wa type ref to data,

w_dyn_table type ref to data.

CREATE DATA w_dyn_wa TYPE (p_table). "Suitable work area

ASSIGN w_dyn_wa->* TO <w_wa>.

create data w_dyn_table type standard table of (p_table).

assign w_dyn_table->* to <w_table>.

data w_dyn_data(5000) type c.

SELECT * FROM (p_table) INTO table <w_table> where endda >= sy-datum.

Data: w_temp type string.

OPEN DATASET p_file FOR OUTPUT IN TEXT MODE encoding default.

IF SY-SUBRC = 0.

loop at <w_table> into <w_wa>.

w_temp = ''.

do.

assign component sy-index of structure <w_wa> to <w_field>.

if sy-subrc <> 0.

exit.

endif.

concatenate w_temp <w_field> into w_temp respecting blanks.

if sy-index = 1.

transfer '' to p_file.

endif.

  • transfer <w_field> to p_file no end of line.

enddo.

transfer w_temp to p_file no end of line.

write:/ w_temp.

endloop.

endif.

close dataset p_file.

when i run the program with PA0008 i am getting a casting error "Object not char like". How do i get rid of this error?. I tried moving the contents of field symbol to a string and appending it. It worked, but i lost the exact formatting of data in the file. In other words, it got rid of extra blanks. I need exact structure of internal table in the file.

Thanks,

Sandeep

Thanks,

Sandeep

4 REPLIES 4
Read only

Former Member
0 Likes
663

Hi

Have u tried to use MOVE statament instead of CONCATENATE?

do.

assign component sy-index of structure <w_wa> to <w_field>.

if sy-subrc <> 0.

exit.

endif.

DESCRIBE FIELD <W_FIELD> LENGTH V_LEN.

MOVE <W_FIELD> TO w_temp+V_OFFSET(V_LEN).

V_OFFSERT = V_OFFSET + V_LEN.

Max

Read only

0 Likes
663

It threw the same error "Objects not char like" at

DESCRIBE FIELD <W_FIELD> LENGTH V_LEN in byte mode.

I tried both byte mode and char mode.

Read only

0 Likes
663

I think your concatenate statement dumping when the program reaches the first non char like field in PA0008.

use DESCRIBE field <W_FIELD> type v_type, if it's not char like, move the field into a char field and concatenate or try to concatenate in byte mode.

Regards

Sridhar

Read only

0 Likes
663

Hi

Try to define w_temp as char instead of string

DATA W_TEMP(10000).

Max