I'm trying to save a SAP internal table to SAP Directory as .CSV file. I've learned that I should convert the contents to character type but i get an illegal casting error. This is my code:
FORM f_opendata TABLES p_tab TYPE STANDARD TABLE USING
p_work TYPE any.
FIELD-SYMBOLS: <lfs_wa>.
CONCATENATE c_headerfile c_initials sy-datum c_ext INTO v_dtasetfile.
OPEN DATASET v_dtasetfile FOR OUTPUT IN TEXT MODE ENCODING UTF-8.
IF sy-subrc EQ 0.
LOOP AT p_tab INTO p_work.
ASSIGN p_work TO <lfs_wa> CASTING TYPE c.
TRANSFER <lfs_wa> TO v_dtasetfile.
ENDLOOP.
CLOSE DATASET v_dtasetfile.
MESSAGE i899(f2) WITH 'SUCCESS' v_dtasetfile.
ENDIF.
ENDFORM.
This is the error:
An exception occurred that is explained in detail below.
The exception, which is assigned to class CX_SY_ASSIGN_CAST_ILLEGAL_CAST, was
not caught in procedure F_OPENDATA, nor was it propagated by a RAISING clause.
Since the caller of the procedure could not have anticipated that the
exception would occur, the current program is terminated.
The reason for the exception is:
The error occurred at a statement of the form ASSIGN f TO CASTING.
ASSIGN f TO CASTING TYPE t.
or
ASSIGN f TO CASTING LIKE f1.
or
at table statements with the addition
ASSIGNING CASTING.The following error causes are possible:
1. The type of field f or the target type determined by , t or f1 contains data references, object references, strings or internal tables as components.
These components must match exactly as far as their position (offset) and their type are concerned.
2. The specified type t or the type of f1 are not suited for the type of the field symbol .
3. The row type of the related table is not suited for the target type specified by according to the rules described in 1).