2006 Jul 14 4:01 PM
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
2006 Jul 14 4:13 PM
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
2006 Jul 14 4:46 PM
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.
2006 Jul 14 5:24 PM
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
2006 Jul 14 6:26 PM
Hi
Try to define w_temp as char instead of string
DATA W_TEMP(10000).
Max
| User | Count |
|---|---|
| 4 | |
| 2 | |
| 2 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 |