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

FM UPLOAD!!!!

Former Member
0 Likes
1,396

hello SDN,

I have a query with regard to FM Upload, in our program this FM is working fine for us, I know this has been obsolete.

The problem is if i try to upload the document which is in open state in the system (changing) and then the document is uploaded blank.

Is their any solution to it sap has not provided any exception for it in the FM.

Cheers

Venkata

14 REPLIES 14
Read only

Former Member
0 Likes
1,335

hi,

u cannot upload a file which is in open state.

Try to use gui_upload.

Regards,

Sruhti

Read only

Former Member
0 Likes
1,335

hi Venkat,

Use GUI_UPLOAD instead of UPLOAD FM..

Take a look at this sample program

http://www.sapdevelopment.co.uk/file/file_uptabpc.htm

Regards,

Santosh

Message was edited by:

Santosh Kumar Patha

Read only

Former Member
0 Likes
1,335

Hi venkata,

In the new function modules like GUI_UPLOAD it raises an exception if the file is already raised. Use it instead of UPLOAD.

Regards,

Ravi

Read only

Former Member
0 Likes
1,335

Hi,

Use the GUI_UPLOAD for the UPLOAD.

the document should not be opened while uploading.

regards,

Sreevani

Read only

Former Member
0 Likes
1,335

Hi Venkata,

Please Use

SPRAS = SY-LANGU.

toupload the data.

Thanks

Chidanand

Read only

0 Likes
1,335

Hi Venkata,

Sorry please ignore the above text which iwrote. Use this one

Please Use 
GUI_UPLOAD

toupload the data.

Thanks

Chidanand

Read only

Former Member
0 Likes
1,335

hello friend

i never expected this much quick reply.

Many thanks to all of you.

My problem is the FM has to ask for the file path, i cannot provide another field for the path from where to upload the file. And i think only upload has this functionality.

have your say? Please

Read only

0 Likes
1,335

do this way


*AT SELECTION-SCREEN ON VALUE-REQUEST FOR P_INFILE.
AT SELECTION-SCREEN ON VALUE-REQUEST FOR P_infile.
  CALL FUNCTION 'WS_FILENAME_GET'
       EXPORTING
            def_filename     = p_infile
            mask             = ',*.txt.'
            mode             = 'O'
            title            = 'Upload File'(078)
       IMPORTING
            filename         = p_infile
       EXCEPTIONS
            inv_winsys       = 1
            no_batch         = 2
            selection_cancel = 3
            selection_error  = 4
            OTHERS           = 5.


************************************************************************
*START-OF-SELECTION
START-OF-SELECTION.
  gd_file = p_infile.

  CALL FUNCTION 'GUI_UPLOAD'
    EXPORTING
      filename                = gd_file
      has_field_separator     = 'X'  "file is TAB delimited
    TABLES
      data_tab                = it_record
    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 NE 0.
      write: 'Error ', sy-subrc, 'returned from GUI_UPLOAD FM'.
      skip.
    endif.

Read only

0 Likes
1,335

Hi,

AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_file.

CALL FUNCTION 'F4_FILENAME'

EXPORTING

field_name = 'P_FILE'

IMPORTING

file_name = p_file.

Regards,

Sruthi

Read only

0 Likes
1,335

hello Friends,

I tried your suggestions now using WS_UPLOAD.

data filename type string.

CALL FUNCTION 'WS_FILENAME_GET'

EXPORTING

    • def_filename = p_infile

  • mask = ',*.txt.'

  • mode = 'O'

title = 'Upload File'(078)

IMPORTING

filename = filename

EXCEPTIONS

inv_winsys = 1

no_batch = 2

selection_cancel = 3

selection_error = 4

OTHERS = 5.

.

CALL FUNCTION 'GUI_UPLOAD'

EXPORTING

FILENAME = filename

FILETYPE = 'BIN'

  • HAS_FIELD_SEPARATOR = ' '

  • HEADER_LENGTH = 0

  • READ_BY_LINE = 'X'

  • DAT_MODE = ' '

  • CODEPAGE = ' '

  • IGNORE_CERR = ABAP_TRUE

  • REPLACEMENT = '#'

  • CHECK_BOM = ' '

IMPORTING

FILELENGTH = gui_file_bin_total_bytes

  • HEADER =

TABLES

DATA_TAB = GUI_FILE_BIN

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 'Error Reading file. Possible reason file is open for changes'

type 'W'.

ENDIF.

but the problem persists the system sends a warning message but i still see the document uploaded with 0kb.

but i want it to stop uploading if any exception occurs.

any suggestions Please.

Message was edited by:

VENKATA SUNDER

Read only

0 Likes
1,335

hi,

check this link i think it will be useful for u.

&----


*& Report ZUPLOADTAB *

*& *

&----


*& Example of Uploading tab delimited file *

*& *

&----


REPORT zuploadtab .

PARAMETERS: p_infile LIKE rlgrap-filename

OBLIGATORY DEFAULT '/usr/sap/'..

*DATA: ld_file LIKE rlgrap-filename.

DATA: gd_file type string.

*Internal tabe to store upload data

TYPES: BEGIN OF t_record,

name1 LIKE pa0002-vorna,

name2 LIKE pa0002-name2,

age TYPE i,

END OF t_record.

DATA: it_record TYPE STANDARD TABLE OF t_record INITIAL SIZE 0,

wa_record TYPE t_record.

*Internal table to upload data into

DATA: BEGIN OF it_datatab OCCURS 0,

row(500) TYPE c,

END OF it_datatab.

*Text version of data table

TYPES: BEGIN OF t_uploadtxt,

name1(10) TYPE c,

name2(15) TYPE c,

age(5) TYPE c,

END OF t_uploadtxt.

DATA: wa_uploadtxt TYPE t_uploadtxt.

*String value to data in initially.

DATA: wa_string(255) TYPE c.

CONSTANTS: con_tab TYPE x VALUE '09'.

*If you have Unicode check active in program attributes then you will

*need to declare constants as follows:

*class cl_abap_char_utilities definition load.

*constants:

  • con_tab type c value cl_abap_char_utilities=>HORIZONTAL_TAB.

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

*AT SELECTION-SCREEN ON VALUE-REQUEST FOR P_INFILE.

AT SELECTION-SCREEN ON VALUE-REQUEST FOR P_infile.

CALL FUNCTION 'WS_FILENAME_GET'

EXPORTING

def_filename = p_infile

mask = ',*.txt.'

mode = 'O'

title = 'Upload File'(078)

IMPORTING

filename = p_infile

EXCEPTIONS

inv_winsys = 1

no_batch = 2

selection_cancel = 3

selection_error = 4

OTHERS = 5.

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

*START-OF-SELECTION

START-OF-SELECTION.

gd_file = p_infile.

CALL FUNCTION 'GUI_UPLOAD'

EXPORTING

filename = gd_file

has_field_separator = 'X' "file is TAB delimited

TABLES

data_tab = it_record

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 NE 0.

write: 'Error ', sy-subrc, 'returned from GUI_UPLOAD FM'.

skip.

endif.

  • Alternative method, where by you split fields at each TAB after you

  • have returned the data. No point unless you dont have access to

  • GUI_UPLOAD but just included for information

*

  • CALL FUNCTION 'GUI_UPLOAD'

  • EXPORTING

  • filename = gd_file

  • filetype = 'ASC'

  • TABLES

  • data_tab = it_datatab "ITBL_IN_RECORD[]

  • EXCEPTIONS

  • file_open_error = 1

  • OTHERS = 2.

  • IF sy-subrc NE 0.

  • ELSE.

  • LOOP AT it_datatab.

  • CLEAR: wa_string, wa_uploadtxt.

  • wa_string = it_datatab.

  • SPLIT wa_string AT con_tab INTO wa_uploadtxt-name1

  • wa_uploadtxt-name2

  • wa_uploadtxt-age.

  • MOVE-CORRESPONDING wa_uploadtxt TO wa_record.

  • APPEND wa_record TO it_record.

  • ENDLOOP.

  • ENDIF.

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

*END-OF-SELECTION

END-OF-SELECTION.

*!! Text data is now contained within the internal table IT_RECORD

  • Display report data for illustration purposes

LOOP AT it_record INTO wa_record.

WRITE:/ sy-vline,

(10) wa_record-name1, sy-vline,

(10) wa_record-name2, sy-vline,

(10) wa_record-age, sy-vline.

ENDLOOP.

http://www.sapdevelopment.co.uk/file/file_uploadpc.htm

http://www.sapdevelopment.co.uk/file/file_updown.htm

Regards,

Sruthi

Read only

0 Likes
1,335

hi Venkat,

check ou the file format and change the file format accordingly ..

FILENAME = filename
FILETYPE = 'ASC'

Reward helpul answers

Regards,

Santosh

Read only

0 Likes
1,335

I THINK thts all we can do here if sy-subrc <> 0.

Error or warning message but the FM will still go through uploading file with no data in it.

is it possible to check for the file path provided if the file is in open state in the system?

Cheers

venkata

Read only

Former Member
0 Likes
1,335

or else do this way..

*  CALL FUNCTION 'UPLOAD'
*       EXPORTING
*            FILENAME = PR_IFILE
*            FILETYPE = 'ASC'
*       TABLES
*            DATA_TAB = ITAB_INFILE.
  DATA ITAB_FILE1_TABLE TYPE FILETABLE.
  DATA W_WSU_FILENAME01 TYPE STRING.
  DATA RC_FILE TYPE I.

  W_WSU_FILENAME01 = PR_IFILE.

  CALL METHOD CL_GUI_FRONTEND_SERVICES=>FILE_OPEN_DIALOG
    EXPORTING
       DEFAULT_FILENAME        = W_WSU_FILENAME01
    CHANGING
       FILE_TABLE              = ITAB_FILE1_TABLE
       RC                      = RC_FILE
     EXCEPTIONS
       FILE_OPEN_DIALOG_FAILED = 1
       CNTL_ERROR              = 2
       ERROR_NO_GUI            = 3
       NOT_SUPPORTED_BY_GUI    = 4
       others                  = 5.
  IF SY-SUBRC <> 0.
*   MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
*              WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
  ENDIF.


  DATA W_WSU_FILENAME02 TYPE STRING.
  DATA W_WSU_FILETYPE02 TYPE CHAR10.

  W_WSU_FILETYPE02 = 'ASC'.

  READ TABLE ITAB_FILE1_TABLE INDEX 1 INTO W_WSU_FILENAME02.

  CALL FUNCTION 'GUI_UPLOAD'
    EXPORTING
      FILENAME                      = W_WSU_FILENAME02
      FILETYPE                      = W_WSU_FILETYPE02
    TABLES
      DATA_TAB                      = ITAB_INFILE
    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.