SAP ABAP - Upload File to OneDrive Folder

 


REPORT yupload_file.
** Data Declarations
DATA: gv_filename    TYPE string,
      lt_data_tab    TYPE TABLE OF x255,
      lv_bin_size    TYPE i,
      lv_file        TYPE string,
      e_filenamefull TYPE string,
      e_filename     TYPE string,
      e_extension    TYPE string.

DATA:
  lv_e_pathname TYPE rstxtlg, "
  lv_i_filepath TYPE rsfilenm, "
  lv_e_filename TYPE rsawbnobjnm. "

** Parameters
PARAMETERS : gv_name TYPE localfile.
** Selection screen value request
AT SELECTION-SCREEN ON VALUE-REQUEST FOR gv_name.
  CALL FUNCTION 'KD_GET_FILENAME_ON_F4'
    EXPORTING
      static    = 'X'
    CHANGING
      file_name = gv_name.
  IF sy-subrc <> 0.
* Implement suitable error handling here
  ENDIF.
START-OF-SELECTION.
  PERFORM upload_attachment.
FORM upload_attachment.
  CLEAR : lv_i_filepath.
  gv_filename   = gv_name.
  lv_i_filepath = gv_name.
** upload the file data from desktop/localfile
  CALL FUNCTION 'GUI_UPLOAD'
    EXPORTING
      filename   = gv_filename
      filetype   = 'BIN'
    IMPORTING
      filelength = lv_bin_size
    TABLES
      data_tab   = lt_data_tab.

  CALL FUNCTION 'RSDS_SPLIT_PATH_TO_FILENAME'  "split file path in file name and path
    EXPORTING
      i_filepath = lv_i_filepath
    IMPORTING
      e_pathname = lv_e_pathname
      e_filename = lv_e_filename
    . " RSDS_SPLIT_PATH_TO_FILENAME
  CLEAR lv_file.
  DATA(dstpatch) = 'XX:OneDrivePath\'.
  lv_file = |{ dstpatch }{ lv_e_filename }|.

  CALL FUNCTION 'GUI_DOWNLOAD'
    EXPORTING
      filename                = lv_file
      filetype                = 'BIN'
    TABLES
      data_tab                = lt_data_tab
    EXCEPTIONS
      file_write_error        = 1
      no_batch                = 2
      gui_refuse_filetransfer = 3
      invalid_type            = 4
      no_authority            = 5
      unknown_error           = 6
      header_not_allowed      = 7
      separator_not_allowed   = 8
      filesize_not_allowed    = 9
      header_too_long         = 10
      dp_error_create         = 11
      dp_error_send           = 12
      dp_error_write          = 13
      unknown_dp_error        = 14
      access_denied           = 15
      dp_out_of_memory        = 16
      disk_full               = 17
      dp_timeout              = 18
      file_not_found          = 19
      dataprovider_exception  = 20
      control_flush_error     = 21
      OTHERS                  = 22.
  IF sy-subrc <> 0.
* Implement suitable error handling here
  ENDIF.
  IF sy-subrc = 0.
    WRITE: / 'Successfully uploaded to One Drive'.
  ENDIF.
ENDFORM.







Comments

Popular posts from this blog

PHP MySql CRUD Dengan Konsep MVC

Laravel - Sistem Informasi Perpustakaan Sederhana Laravel

IT Asset Management Dengan PHP MySQL