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

Unicode type not convertible

Former Member
0 Likes
1,423

Hi,

Need some help in modifying the code ... I am working on a mass download of data into a texr file from the tables. Few of these tables have fields in decimal or currency and I need to read them into character string. I know the structure of the internal table I read the data into has to exactly match the table structure in Unicode environment. How to add that in the code when I am pulling the tables dynamically and reading their data in a sequential manner. Hence I am getting the above error.

Data: begin of i_list occurs 0,

i_tabledata(2550) type c,

end of i_list.

select * from (v_tabname) into i_list. -


> Unicode type not convertible error...

append i_list.

clear i_list.

endselect.

The value of 'v_tabname' comes from the table DD02l dynamically.

Any thoughts?

Thanks,

VG

10 REPLIES 10
Read only

Former Member
0 Likes
1,136

Hi VG,

It takes a lot of code but it works:


  DATA: lo_structtype type ref to cl_abap_structdescr,
        lo_tabletype  type ref to cl_abap_tabledescr,
        lr_structdata type ref to data,
        lr_tabledata   type ref to data.

field-symbols: <ls> type any,
               <lt> type standard table.

* get the type for the structure
lo_structtype ?= cl_abap_structdescr=>describe_by_name( v_tabname ).
* get the type of the table
lo_tabletype = cl_abap_tabledescr=>create( p_line_type = lo_structtype ).

* create the data
create data: lr_structdata type handle lo_structtype,
                    lr_tabledata type handle lo_tabletype.

* assign the field symbols
assign lr_structdata->* to <ls>.
assign lr_tabledata->* to <lt>.

* select the data
select * from (v_tabname) into <ls>.
append <ls> to <lt>.
endselect.

Thanks,

Erik

Read only

SuhaSaha
Product and Topic Expert
Product and Topic Expert
0 Likes
1,136

Hello Erik,

Doesn't take so much coding you know Check this out:

PARAMETERS: p_tab TYPE tablename OBLIGATORY.

DATA: dref TYPE REF TO data.

FIELD-SYMBOLS: <itab> TYPE STANDARD TABLE.

CREATE DATA dref TYPE STANDARD TABLE OF (p_tab).
ASSIGN dref->* TO <itab>.

SELECT * FROM (p_tab) INTO TABLE <itab> UP TO 10 ROWS.
IF sy-subrc = 0.
  WRITE: / `I've created a dynamic internal table. Yipeee!!!!`.
ENDIF.

BR,

Suhas

Read only

0 Likes
1,136

Thanks. That's much better!

Read only

0 Likes
1,136

Hi,

Thanks I got that part. I am having the problem in reading the entire data into a internal table 'List' from the field symbol. My internal table is a single field of type character. I need to read the data into this internal table for downloading the data into a text file.

Data: begin of i_list occurs 0,

i_tabledata(2550) type c,

  • table_rec(255) type c,

end of i_list.

FIELD-symbols: <fs_table2> type standard table,

<fs_string> type c.

CREATE DATA v_dref Type table of (v_tabname).

assign v_dref->* TO <fs_table2>.

select * from (v_tabname) into table <fs_table2>.

assign <fs_table2> to <fs_string> CASTING. -


> error

i_list-i_tabledata = <fs_string>.

append i_list.

clear i_list.

Any thoughts?

Thanks again,

VG

Read only

0 Likes
1,136

PARAMETERS: p_tab TYPE tablename OBLIGATORY.

give a try


DATA: dref TYPE REF TO data.
Data: begin of i_list occurs 0,
i_tabledata(2550) type c,
end of i_list.
 
FIELD-SYMBOLS: <fs> TYPE any
 
CREATE DATA dref like line of  (p_tab). 
ASSIGN dref->* TO <fs>.
 
SELECT * FROM (p_tab) INTO <fs>  UP TO 10 ROWS.
IF sy-subrc = 0.
call method cl_abap_container_utilities=>fill_container_c
exporting
im_value = <fs>
importing
ex_container = itab.
exceptions
illegal_parameter_type = 1
others = 2. 
append itab.
endif.
endselect.

Read only

0 Likes
1,136

Thanks for the response. It did not work..

VG

Read only

0 Likes
1,136

Hi,

My task is to download the data from a series of tables into the text file and then upload the same file into different set of same tables in a different name space. My code works fine when we are downloading and uploading all 'CHAR' data because I am reading into a string and using field symbols assigning the structure at the run time it inserts the data perfectly fine.

However if any table contains a field with decimal, currency, it throws an Unicode not convertible error rightly results in run time error. It is here I am facing the problem to downloading the data and uplaoding the data.

Uploading the data...

data: v_tabledata(2575) type c,

field-symbols: <fs_table> type any.

I read the data from the flat file into this string. From here, I need to upload into a table that has a decimal field...

I tried some thing like this...

assign v_tabledata to <fs_table>. (tried with standard table declaration too it did not work)

move <fs_table> to i_crword_temp. -


> runtime error...

modify (v_tabname) from i_crword_temp.

v_tabname is a database table

Hvae been trying few different things nothing seems to work.. Any thoughts or leads will be helpful.

Thanks in advance,

VG

Read only

SuhaSaha
Product and Topic Expert
Product and Topic Expert
0 Likes
1,136

As per your requirement, i developed this code snippet.

I download the data from ZTESTVBAK & upload the data to YTESTVBAK. Not sure why you're transferring the data to string & trying to read the string ?

Check this code snippet:

PARAMETERS: p_tab TYPE tabname OBLIGATORY DEFAULT 'ZTESTVBAK',
            p_dwld RADIOBUTTON GROUP grp1 DEFAULT 'X',
            p_upld RADIOBUTTON GROUP grp1.

DATA: dref TYPE REF TO data,
      v_tab TYPE tabname,
      lcx_sql_err TYPE REF TO cx_sy_sql_error,
      v_errtxt TYPE string.

FIELD-SYMBOLS: <itab> TYPE STANDARD TABLE,
               <wa> TYPE ANY.

CREATE DATA dref TYPE STANDARD TABLE OF (p_tab).
ASSIGN dref->* TO <itab>.

IF p_dwld = 'X'.
  SELECT * FROM (p_tab) INTO TABLE <itab> UP TO 100 ROWS.
  IF sy-subrc = 0.
    CALL FUNCTION 'GUI_DOWNLOAD'
      EXPORTING
        filename                = 'C:\dyntab.txt'
        write_field_separator   = 'X'
        confirm_overwrite       = 'X'
      TABLES
        data_tab                = <itab>
      EXCEPTIONS
        file_write_error        = 1
        no_batch                = 2
        gui_refuse_filetransfer = 3
        invalid_type            = 4
        no_authority            = 5
        unknown_error           = 6
        header_not_allowed      = 7
        separator_not_allowed   = 8
        filesize_not_allowed    = 9
        header_too_long         = 10
        dp_error_create         = 11
        dp_error_send           = 12
        dp_error_write          = 13
        unknown_dp_error        = 14
        access_denied           = 15
        dp_out_of_memory        = 16
        disk_full               = 17
        dp_timeout              = 18
        file_not_found          = 19
        dataprovider_exception  = 20
        control_flush_error     = 21
        OTHERS                  = 22.
    IF sy-subrc = 0.
      WRITE: / 'File download successful.'.
    ENDIF.

  ENDIF.
ELSEIF p_upld = 'X'.
  CALL FUNCTION 'GUI_UPLOAD'
    EXPORTING
      filename                = 'C:\dyntab.txt'
      has_field_separator     = 'X'
    TABLES
      data_tab                = <itab>
    EXCEPTIONS
      file_open_error         = 1
      file_read_error         = 2
      no_batch                = 3
      gui_refuse_filetransfer = 4
      invalid_type            = 5
      no_authority            = 6
      unknown_error           = 7
      bad_data_format         = 8
      header_not_allowed      = 9
      separator_not_allowed   = 10
      header_too_long         = 11
      unknown_dp_error        = 12
      access_denied           = 13
      dp_out_of_memory        = 14
      disk_full               = 15
      dp_timeout              = 16
      OTHERS                  = 17.
  IF sy-subrc = 0.
    v_tab = p_tab.
*   Lock the table records
    CALL FUNCTION 'ENQUEUE_E_TABLEE'
      EXPORTING
        tabname        = v_tab
      EXCEPTIONS
        foreign_lock   = 1
        system_failure = 2
        OTHERS         = 3.
    IF sy-subrc = 0.
      TRY .
          MODIFY (p_tab) FROM TABLE <itab>.
        CATCH cx_sy_sql_error INTO lcx_sql_err.
          v_errtxt = lcx_sql_err->get_text( ).
      ENDTRY.
    ENDIF.

*   Unlock the table records
    CALL FUNCTION 'DEQUEUE_E_TABLE'
      EXPORTING
        tabname = v_tab.

    COMMIT WORK.
  ENDIF.

ENDIF.

Hope this helps.

BR,

Suhas

Read only

0 Likes
1,136

Hi Suhas,

Thanks for the info. I had to read them into a string because I had to download the data and upload the same data into different tables in a different client under a different name space. I shall try this and definitely get back...

Thanks once again,

VG

Read only

0 Likes
1,136

Hi Suhas,

the file donwloaded successfully, whreas during upload it gave an error with sy-subrc = 8. Bad data format. Any thoughts as to why?

Thanks,

VG