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

GUI_UPLOAD for excel file

Former Member
0 Likes
36,367

Hi abapers,

I have to change a code which uses GUI_UPLOAD and a .txt file.

but now the requirment is changed to a .XLS file.

Is it possible to get the data into internal table using GUI_UPLOAD with an excel file.

If yes what changes do i have to make to the parameters.

Also i have to read the header title for each column.

I used FM 'TEXT_CONVERT_XLS_TO_SAP' its also uploading correctly.

But the problem is that the header text gets truncated beacuse i cannot specify more width for the columns as i am later using them for fetching data using 'FOR ALL ENRIES'. ( so i have to specify the same data type ).

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
16,430

Hi Aditya,

Please Find the sample code below.

data:
  t_alsmex_tabline like
          standard table
                of alsmex_tabline
             with header line.

data:
  begin of test occurs 1,
  char1(20) type c,
  char2(20) type c,
  char3(20) type c,
  end of test.


data:
  w_row        type i,
  w_line(50)  type c,
  w_values type i,
  w_type       type c,
  w_times      type i.

describe field test type w_type components w_values.

call function 'ALSM_EXCEL_TO_INTERNAL_TABLE'
  exporting
    filename                = 'c:\temp\test.xls'
    i_begin_col             = 1
    i_begin_row             = 1
    i_end_col               = w_values
    i_end_row               = 10
  tables
    intern                  = t_alsmex_tabline
  exceptions
    inconsistent_parameters = 1
    upload_ole              = 2
    others                  = 3.

if sy-subrc <> 0.
*  MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
*          WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
endif.


describe table t_alsmex_tabline.

w_times = sy-tfill div w_values.

w_row = 0.

do w_times times.
  w_row = w_row + 1.

  loop at t_alsmex_tabline where row = w_row .
    concatenate w_line t_alsmex_tabline-value
           into w_line separated by space.

  endloop.

  shift w_line left.

  split w_line at space into test-char1
                             test-char2
                             test-char3  .

  append test.
  write:
  /  test-char1,
     test-char2,
     test-char3.
  clear: test,
      w_line.
enddo.

Hope this is helpfull.

Thanks

kalyan

10 REPLIES 10
Read only

Former Member
0 Likes
16,430

Hi,

You can use function module GUI_UPLOAD

CALL FUNCTION 'GUI_UPLOAD'

EXPORTING

filename =

FILETYPE = 'ASC'

HAS_FIELD_SEPARATOR = ' '

HEADER_LENGTH = 0

READ_BY_LINE = 'X'

DAT_MODE = ' '

CODEPAGE = ' '

IGNORE_CERR = ABAP_TRUE

REPLACEMENT = '#'

CHECK_BOM = ' '

VIRUS_SCAN_PROFILE =

NO_AUTH_CHECK = ' '

IMPORTING

FILELENGTH =

HEADER =

tables

data_tab =

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.

MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO

WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.

ENDIF.

Here by mentioning file type as 'ASC', you can upload Excel format file into you abap program.

Thanks,

Asit Purbey.

Read only

0 Likes
16,430

I tried it using file type "ASC'.

But all the data is now visible as #######

Read only

Former Member
0 Likes
16,430

Hi Aditya,

I would suggest to go with FM 'ALSM_EXCEL_TO_INTERNAL_TABLE'.

Regards,

Nitin.

Read only

Former Member
0 Likes
16,430

Hi,

Try with this FM SAP_CONVERT_TO_XLS_FORMAT.

Thanks & Regards,

Anagha Deshmukh

Read only

Former Member
0 Likes
16,430

Hello Aditya,

Just try out, declare an internal table with all the fields including header and items, as Characters.

Then move imported internal table to the internal table with correct datatypes. And then upload that internal table to excel sheet, using function module TEXT_CONVERT_XLS_TO_SAP.

Hope it helps you,

Zahack

Read only

Former Member
0 Likes
16,430

Hi,

For uploading the excel file through make sure the source file extension is .xls not .xlsx.

Thanks,

Asit Purbey.

Read only

Former Member
0 Likes
16,430

Hi Aditya,

U can use below FM:

----


  • Function Module for from EXCEL to itab

----


call function 'ALSM_EXCEL_TO_INTERNAL_TABLE'

exporting

filename = 'C:\DATE.XLS'

i_begin_col = 1

i_begin_row = 1

i_end_col = 1

i_end_row = 1

tables

intern = itab_date

exceptions

inconsistent_parameters = 1

upload_ole = 2

others = 3.

if sy-subrc <> 0.

message id sy-msgid type sy-msgty number sy-msgno

with sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.

endif.

begin col, row are for data starts on row 1 and col 1 and

end col, row are for data ends at row 1 and col 1 only.

change the values as per ur requirement.

Read only

Former Member
0 Likes
16,430

Hi,

use this FM ''ALSM_EXCEL_TO_INTERNAL_TABLE''

Regards,

Jyothi CH.

Read only

Former Member
0 Likes
16,430

Hi,

You may also have a look at this FM:

KCD_EXCEL_OLE_TO_INT_CONVERT.

Regards.

Read only

Former Member
0 Likes
16,431

Hi Aditya,

Please Find the sample code below.

data:
  t_alsmex_tabline like
          standard table
                of alsmex_tabline
             with header line.

data:
  begin of test occurs 1,
  char1(20) type c,
  char2(20) type c,
  char3(20) type c,
  end of test.


data:
  w_row        type i,
  w_line(50)  type c,
  w_values type i,
  w_type       type c,
  w_times      type i.

describe field test type w_type components w_values.

call function 'ALSM_EXCEL_TO_INTERNAL_TABLE'
  exporting
    filename                = 'c:\temp\test.xls'
    i_begin_col             = 1
    i_begin_row             = 1
    i_end_col               = w_values
    i_end_row               = 10
  tables
    intern                  = t_alsmex_tabline
  exceptions
    inconsistent_parameters = 1
    upload_ole              = 2
    others                  = 3.

if sy-subrc <> 0.
*  MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
*          WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
endif.


describe table t_alsmex_tabline.

w_times = sy-tfill div w_values.

w_row = 0.

do w_times times.
  w_row = w_row + 1.

  loop at t_alsmex_tabline where row = w_row .
    concatenate w_line t_alsmex_tabline-value
           into w_line separated by space.

  endloop.

  shift w_line left.

  split w_line at space into test-char1
                             test-char2
                             test-char3  .

  append test.
  write:
  /  test-char1,
     test-char2,
     test-char3.
  clear: test,
      w_line.
enddo.

Hope this is helpfull.

Thanks

kalyan