Application Development 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: 

Regarding Uploading the files in Internal Table

Former Member
0 Kudos
109

Hi everyone ,

I am facing problem while uplaoding the file from presentation server to SAP internal table because of Delimiter (|) , as i am using GUI_UPLOAD FM , but i think it can be used for only TAB delimiter . Please suggest the logic so that i can proceed my coding .

Thanks ,

Sachin Singh

5 REPLIES 5

Former Member
0 Kudos
71

Hi Sachin,

First upload the file into internal table using GUI_UPLOAD but keet the field separater parameter as blank. As result of this , you will get data in internal table with character field only.

Now pass the above internal table to FM : TEXT_CONVERT_TEX_TO_SAP and here give the delimeter as (|) and now you will get the data in the required internal table .

Please give feedbacks if any and come back if some more help is required.

Thanks and Regards

Gurpreet Singh

Former Member
0 Kudos
71

Hi Sachin,

Refer sample code:

CALL FUNCTION 'GUI_UPLOAD'

EXPORTING

filename = lcl_filename

filetype = 'ASC'

<b> has_field_separator = 'X'</b>

TABLES

data_tab = upload_table

OR

You can read the data in Character field(1000) and then use <b>SPLIT</b> to populate to corresponding fields.

Reward points if this Help.

Manish

Former Member
0 Kudos
71

Hi sachin,

You can upload the data into a string and then split the same at '|'.

Check this code-

data: begin of it_data occurs 0,

field1(10),

field2(10),

field3(10),

end of it_data.

data: begin of it_string occurs 0,

data(1000),

end of it_string.

data: p_filename type string value

'C:\text.txt'.

start-of-selection.

CALL FUNCTION 'GUI_UPLOAD'

EXPORTING

filename = p_filename

FILETYPE = 'ASC'

  • HAS_FIELD_SEPARATOR = ' '

tables

data_tab = it_string

.

loop at it_string.

split it_string-data at '|' into

it_data-field1

it_data-field2

it_data-field3.

append it_data.

endloop.

-sookshma

anversha_s
Active Contributor
0 Kudos
71

Hi,

try this.

types: begin of ttab,
       rec(1000) type c,
       end of ttab.
 
types: begin of tdat,
       fld1(10) type c,
       fld2(10) type c,
       fld3(10) type c,
       end of tdat.
 
data: itab type table of ttab with header line.
data: idat type table of tdat with header line.
 
data: file_str type string.
 
parameters: p_file type localfile.
 
at selection-screen on value-request for p_file.
  call function 'KD_GET_FILENAME_ON_F4'
       exporting
            static    = 'X'
       changing
            file_name = p_file.
 
start-of-selection.
 
  file_str = p_file.
 
  call function 'GUI_UPLOAD'
       exporting
            filename                = file_str
            filetype                  = 'ASC'
            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.
 
 
delete itab index 1.
 
  loop at itab.
    clear idat.
    split itab-rec at cl_abap_char_utilities=>horizontal_tab
                          into idat-fld1
                               idat-fld2
                               idat-fld3.
    append idat.
 
  endloop.
 
 
  loop at idat.
    write:/ idat-fld1, idat-fld2, idat-fld3.
  endloop.

rgds

Anver

if hlped pls mark points

roberto_tagliento
Active Contributor
0 Kudos
71

Really don't understand why have a file into a iTable.

You can UPLOAD all files you wish, and into iTable put only the full PATH of relative file.