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

upload excel file from application server

Former Member
0 Likes
1,894

hi,

i need to create a program to upload excel file from application server(SAP UNIX server) into SAP for batch upload. can any one please advice how am i going to read the excel file and provide me the code?

thanks

13 REPLIES 13
Read only

Former Member
0 Likes
1,240

Hi ben,

You can use gui_upload Function module .

Here is the code to upload excel file:

DATA:
   w_file TYPE string.                  " File name

DATA:
  * Internal table to hold input file data
 i_upload TYPE TABLE OF sflight.

*Uploading the file
  CALL FUNCTION 'GUI_UPLOAD'
    EXPORTING
      filename                = w_file
      filetype                = 'DAT'
      has_field_separator     = 'X'
    TABLES
      data_tab                = i_upload
    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 s001(zs) WITH space sy-subrc.
  ENDIF.                               " IF sy-subrc ne 0

And For Batch Upload you can use LSMW or BDC.

Thanks and regards

Read only

0 Likes
1,240

hi,

i try to use GUI_UPLOAD but i keep getting error message.

i try to use the below function to call, but it does not work for getting from application server. can you please advice.


  CALL FUNCTION 'ALSM_EXCEL_TO_INTERNAL_TABLE'
    EXPORTING
      filename                = p_file
      i_begin_col             = 1
      i_begin_row             = p_ex_r0
      i_end_col               = 13
      i_end_row               = p_ex_r1
    TABLES
      intern                  = it_ex_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.

Read only

Former Member
0 Likes
1,240

Hi U can use GUI_UPLOAD with the FIELD SEPERATOR = 'X'

Hope It Helps ,,,

Read only

Former Member
0 Likes
1,240

You can use CG3Z and CG3Y tcode to upload/download from application server.

Read only

Former Member
0 Likes
1,240

try these links

Read only

Former Member
0 Likes
1,240

Hi Ben,

Refer to following code:

data: gi_raw_data TYPE truxs_t_text_data,

parameter : gv_file type rlgrap-filename.

CALL FUNCTION 'KD_GET_FILENAME_ON_F4'

EXPORTING

program_name = sy-repid

dynpro_number = syst-dynnr

field_name = gv_file

CHANGING

file_name = gv_file

EXCEPTIONS

mask_too_long = 1

OTHERS = 2.

IF sy-subrc <> 0.

MESSAGE ID gv_msgid TYPE 'I' NUMBER 000.

ENDIF.

FIND '.xls' IN gv_file IGNORING CASE.

IF sy-subrc NE 0.

Concatenate gv_file '.XLS' into gv_file.

ENDIF.

CALL FUNCTION 'TEXT_CONVERT_XLS_TO_SAP'

EXPORTING

i_line_header = '1'

i_tab_raw_data = gi_raw_data

i_filename = gv_file

TABLES

i_tab_converted_data = gi_datatab

EXCEPTIONS

conversion_failed = 1

OTHERS = 2.

IF sy-subrc <> 0.

MESSAGE ID gv_msgid TYPE 'I' NUMBER 001.

ENDIF.

I am assuming you know the BDC method to upload data. If not, I can provide the code for that as well.

Hope it helps

Regards

Natasha Garg

Read only

0 Likes
1,240

hi, can you explain how the code works? i still get error message for this.

Read only

Mohamed_Mukhtar
Active Contributor
0 Likes
1,240

hi ,

Check this Standard Program in SE38 : RC1TCG3Z

Thanks

Always Learner

Read only

SujeetMishra
Active Contributor
0 Likes
1,240

Hi,

You can also use Open Dataset to read your files from application Server instead calling function GUI_UPLOAD

TYPES : begin of ty_filetab,

Declare fields of excel file for input

END OF ty_filetab.

TYPES: BEGIN OF ty_outtab ,

Declare your fields name for output .

END OF ty_outtab .

DATA:it_outtab TYPE STANDARD TABLE OF ty_outtab,

wa_outtab TYPE ty_outtab,

it_filetab type standard table of ty_filetab,

wa_filetab type ty_filetab.

DATA :cdata(500) type C.

open dataset p_file for output in legacy text mode.

Loop at it_outtab into wa_outtab.

move-corresponding wa_outtab to wa_filetab.

whatever you want to move you can move here and cancatenate into cdata

endloop.

close dataset p_file.

Hope it will work.

Read only

0 Likes
1,240

hi,

i still get error message by using "OPEN DATASET".

the file i upload will be EXCEL format. can any one please able to provide me the actual coding for this. togehter of how to pass the excel file into internal table. thanks

Read only

0 Likes
1,240

Hi Lee,

is your issue resolved? if so can you provide solution .

sastry.

Read only

Former Member
0 Likes
1,240

hi,

just use function module: GUI_UPLOAD.

HOPE IT WILL HELP U

RAHUL

Read only

0 Likes
1,240

hi ,

need to upload XLS file is from application server not from presentation server.

suggestions?

sastry.