Search This Blog

Friday, April 01, 2011

GUI_UPLOAD ASCII special chars causing problems

If you use GUI_UPLOAD to import an ASCII file and the data has embedded CR or other chars.  Try this using filetype = BIN.


    CALL METHOD cl_gui_frontend_services=>gui_upload
      EXPORTING
        filename                = g_pc_file
        filetype                = 'BIN'
      IMPORTING
        filelength              = filelength
      CHANGING
        data_tab                = lt_bin
      EXCEPTIONS
        OTHERS                  = 19.
    IF sy-subrc <> 0 OR lt_bin[] IS INITIAL.
      RAISE EXCEPTION TYPE lcl_my_exception.
    ENDIF.


    CALL FUNCTION 'SCMS_BINARY_TO_STRING'
      EXPORTING
        input_length = filelength
      IMPORTING
        text_buffer  = ls_string
      TABLES
        binary_tab   = lt_bin
      EXCEPTIONS
        OTHERS       = 2.
    IF sy-subrc <> 0 .
      RAISE EXCEPTION TYPE lcl_my_exception.
    ENDIF.

    SPLIT ls_string AT cl_abap_char_utilities=>cr_lf INTO TABLE ex_raw_tab.

No comments: