cancel
Showing results for 
Search instead for 
Did you mean: 

how to Upload Excel document into internal table

Former Member
0 Kudos

pls lemme know........

Accepted Solutions (0)

Answers (6)

Answers (6)

Former Member
0 Kudos

Hi,

Try this code

TYPE-POOLS: truxs.

PARAMETERS: p_file TYPE rlgrap-filename.

TYPES: BEGIN OF t_datatab,

col1(2) TYPE c,

col2(30) TYPE c,

col3(2) TYPE c,

col4(2) type c,

END OF t_datatab.

DATA: it_datatab type standard table of t_datatab,

wa_datatab type t_datatab.

DATA: it_raw TYPE truxs_t_text_data.

AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_file.

CALL FUNCTION 'F4_FILENAME'

EXPORTING

field_name = 'P_FILE'

IMPORTING

file_name = p_file.

***********************************************************************

*START-OF-SELECTION.

START-OF-SELECTION.

CALL FUNCTION 'TEXT_CONVERT_XLS_TO_SAP'

EXPORTING

i_line_header = 'X'

i_tab_raw_data = it_raw " WORK TABLE

i_filename = p_file

TABLES

i_tab_converted_data = it_datatab[] "ACTUAL DATA

EXCEPTIONS

conversion_failed = 1

OTHERS = 2.

IF sy-subrc <> 0.

  • MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno

  • WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.

ENDIF.

***********************************************************************

  • END-OF-SELECTION.

END-OF-SELECTION.

LOOP AT it_datatab INTO wa_datatab.

WRITE:/ wa_datatab-col1,

wa_datatab-col2,

wa_datatab-col3,

wa_datatab-col4.

ENDLOOP.

Former Member
0 Kudos

HI

You can upload data from presentation server to an internal table using gui_upload. Use gui_download to download from internal table to flat file.

Use fm ALSM_EXCEL_TO_INTERNAL_TABLE to upload data frm excel.

Use function module GUI_UPLOAD

The FILETYPE refer to the type of file format you need: For e.g 'WK1' - Excel format , 'ASC' - Text Format etc.


CALL FUNCTION 'GUI_UPLOAD'
  EXPORTING
    FILENAME                      = 'C:test.csv'
   FILETYPE                      = 'ASC'
  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.

Check this link

Regards

Pavan

Former Member
0 Kudos

FMs

ALSM_EXCEL_TO_INTERNAL_TABLE

GUI_UPLOAD

WS_UPLOAD

Reward all helpful queries

Former Member
0 Kudos

Akshat,

This may be of some help to you.........

File manuplations...............................

1. At the presentation level:

->GUI_UPLOAD

->GUI_DOWNLOAD

->CL_GUI_FRONTEND

2. At the application server level:

->OPEN DATASET : open a file in the application server for reading or writing.

->READ DATASET : used to read from a file on the application server that has been opened for reading

-> TRANSFER DATASET : writing data to a file.

-> CLOSE DATASET : closes the file

-> DELETE DATASET : delete file

************************************************************************************************

If file is on the local PC,use the function module GUI_UPLOAD to upload it into an internal table by passing the given parameters......

call function 'GUI_UPLOAD'

exporting

filename = p_file

filetype = 'ASC'

has_field_separator = '#'

tables

data_tab = t_data

******************************************************************************

p_file : excel file path.

t_data : internal table

*******************************************************************************

<b>reward points if useful......</b>

regards,

Vinod Samuel.

Former Member
0 Kudos

HI,

FIRST YOU NEED TO COPY ALL DATA EXCEPT HEADER ROW TO NOTEPAD IN .TXT FORMAT.

THEN YOUR INTERNAL TABLE HAS TO HAVE STRUCTUR LIKE YOUR NOTEPAD FILE.

EG:

FILE CONTAINS:

VENDOR CODE VENDOR NAME.

1000000 XYZ

THEN STRUCTURE HAS TO HAVE THESE FIELDS IN ORDER.

NOW YOU HAVE TO USE FM GUI_UPLOAD.AND PASS THIS TXT FILE TO INTERNAL TABLE.

CALL FUNCTION 'GUI_UPLOAD'

EXPORTING

filename = 'C:\TEST.TXT'

has_field_separator = 'X'

TABLES

data_tab = it_input

EXCEPTIONS

OTHERS = 1.

Former Member
0 Kudos

oh,,, thnx sonali ,........it is helpful.....where r u working at

gopi_narendra
Active Contributor
0 Kudos

Use the FM ALSM_EXCEL_TO_INTERNAL_TABLE

Check the sample code below and use it in the similar manner.


* Flatfile internal table.
types : begin of ty_tab,
          kunnr type bsid-kunnr, " added on 31-07-2007
          zuonr type bsid-zuonr,
        end of ty_tab.

data : it_tab type table of ty_tab initial size 0,
       is_tab type ty_tab.

data : it_data type table of alsmex_tabline initial size 0,
       is_data type alsmex_tabline.
parameters : p_ifname type rlgrap-filename obligatory.
* If Input file name is not initial.
  if not p_ifname is initial.
* Upload EXCEL data into internal table
    call function 'ALSM_EXCEL_TO_INTERNAL_TABLE'
         exporting
              filename                = p_ifname
              i_begin_col             = 1
              i_begin_row             = 1
              i_end_col               = 256
              i_end_row               = 65356
         tables
              intern                  = it_data
         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.
  endif.

* Append EXCEL Data into a internal table
  loop at it_data into is_data.
    at new row.
      clear is_tab.
    endat.
    if is_data-col = '001'.
      move is_data-value to is_tab-kunnr.
    endif.
    if is_data-col = '002'.
      move is_data-value to is_tab-zuonr.
    endif.
    at end of row.
      append is_tab to it_tab.
    endat.
    clear : is_data.
  endloop.

Regards

Gopi

<i>Message was edited by: Gopi Narendra</i>

former_member187452
Contributor
0 Kudos

Hi,

You will have to use FM ' GUI_UPLOAD ' for that.

Regards,

Bharat.

***Reward points if helpful.