[ABAP] Datei-Upload

Variante 1 (cl_gui_frontend_services)

DATA: lv_rc TYPE i.
DATA: it_files TYPE filetable.
DATA: lv_action TYPE i.

* FileOpen-Dialog aufrufen
TRY.
        cl_gui_frontend_services=>file_open_dialog( EXPORTING file_filter    = |pdf (*.pdf)\|*.pdf\|{ cl_gui_frontend_services=>filetype_all }|
                                                              multiselection = abap_false
                                                    CHANGING  file_table     = it_files
                                                              rc             = lv_rc
                                                              user_action    = lv_action ).

    IF lv_action = cl_gui_frontend_services=>action_ok.
* wenn Datei ausgewählt wurde
      IF lines( it_files ) > 0.
* ersten Tabelleneintrag lesen
        DATA(lv_filename) = it_files[ 1 ]-filename.

        DATA: lv_filesize TYPE i.
        DATA: it_bin_data TYPE STANDARD TABLE OF raw255.

* Bild auf Appl. Server hochladen (binary)
        cl_gui_frontend_services=>gui_upload( EXPORTING filename   = |{ lv_filename }|
														filetype   = 'BIN'
										      IMPORTING filelength = lv_filesize
										      CHANGING  data_tab   = it_bin_data ).														

        DATA: lv_xstr TYPE xstring.

* RAW (binary) nach xstring
        CALL FUNCTION 'SCMS_BINARY_TO_XSTRING'
          EXPORTING
            input_length = lv_filesize
          IMPORTING
            buffer       = lv_xstr
          TABLES
            binary_tab   = it_bin_data
          EXCEPTIONS
            failed       = 1
            OTHERS       = 2.

        ...
      ENDIF.
    ENDIF.

  CATCH cx_root INTO DATA(e_text).
    MESSAGE e_text->get_text( ) TYPE 'I'.
ENDTRY.

Variante 2 (cl_secxml_helper)

TRY.
    cl_secxml_helper=>file_f4( EXPORTING initial_directory = ''
                                         window_title      = 'Dateiauswahl'
                               IMPORTING filename          = DATA(lv_xfile) ).


    IF lv_xfile IS NOT INITIAL.
      cl_secxml_helper=>upload_file( EXPORTING filename = lv_xfile
                                     IMPORTING bindata  = DATA(lv_data_xstr) ).
      
      ...
    ENDIF.

  CATCH cx_root INTO DATA(e_txt).
    WRITE: / e_txt->get_text( ).
ENDTRY.