Vorlage Upload/Download Datei Frontend
Aus SAP-Wiki
Zur Navigation springenZur Suche springen
Siehe Reporting.
Siehe Report-Vorlage mit Form-Routinen.
Siehe Report-Vorlage mit Lokaler Klasse.
Siehe ALV-Vorlage CL GUI ALV GRID.
Siehe ALV-Vorlage REUSE ALV GRID DISPLAY LVC.
Siehe ALV-Vorlage CL SALV* (Factory).
Siehe Vorlage Upload/Download Datei Frontend.
Siehe Vorlage Upload CSV-Datei mit Job-Steps und Suche nach Stichwort in Programmen.
Siehe Kategorie: ABAP-Vorlagen.
************************************************************************ * Programmname...............: Z/Y * * Entwickler.................: René Eberstein * * Firma......................: * * Projekt....................: * * Ticket.....................: * * Ansprechpartner Berater....: * * Ansprechpartner Fachabt....: * * Erstellt am................: 22.01.2025 * * Online/Batch/USER-EXIT ....: Online * * Tabellen : * * Funktionsbeschreibung .....: * * Es wird eine CSV-Datei hochgeladen * *----------------------------------------------------------------------* *& Ä N D E R U N G E N: * *& <nr>, <sy-uname>, <sy-datum>, <ticket>, <beschreibung> * *&---------------------------------------------------------------------* REPORT Z. **************** * DATA & TYPES * **************** Types: begin of ty_itab, Text type text100, End of ty_itab. Types: tty_itab type STANDARD TABLE OF Ty_itab. TYPES: BEGIN OF Ty_FILE, DATA(900), END OF Ty_FILE. Types: tty_file type STANDARD TABLE OF ty_file. Types: begin of ty_upload, vbeln type likp-vbeln, end of ty_upload. Types: tty_upload type standard table of ty_upload.
DATA: GT_FILE TYPE STANDARD TABLE OF Ty_FILE, GT_UPLOAD type tty_upload, gt_itab type tty_itab, gt_outfile type tty_file. Data: gv_down_file TYPE RLGRAP-FILENAME.
********************** * PARAMETER - SCREEN * ********************** SELECTION-SCREEN BEGIN OF BLOCK b1 WITH FRAME TITLE text-001. "Selektion Parameters: P_FILE TYPE RLGRAP-FILENAME, p_split type char1 default ';'. SELECTION-SCREEN END OF BLOCK b1.
**************************************** * AT SELECTION-SCREEN ON VALUE-REQUEST * **************************************** AT SELECTION-SCREEN ON VALUE-REQUEST FOR P_FILE. * Open-File-Dialog zur Auswahl Inputdatei PERFORM GET_FILENAME.
*********************** * AT SELECTION-SCREEN * *********************** at selection-screen. * Die Download-Datei wird im gleichen Verzeichnis gespeichert * Nur mit zusätzlichen Namen "_conv" und als TXT perform get_down_file using p_file changing gv_down_file.
********************** * START-OF-SELECTION * ********************** start-of-selection. * Datei hochladen in Flatfile von Frontend perform upload_file using P_FILE changing gt_file. * Flatfile in strukturierte interne Tabelle GT_UPLOAD konvertieren perform read_flatfile_into_upload using gt_file changing gt_upload. * Fülle Ausgabestruktur aus Uploaddatei und Headerdaten perform fill_itab using gt_upload changing gt_itab. * Download konvertierte Datei auf Frontend perform download using gv_down_file gt_outfile. message i531(0u) with 'Upload und Download komplett'(002).
*&---------------------------------------------------------------------* *& Form GET_FILENAME *&---------------------------------------------------------------------* * Popupdialog für Uploadpfad in Parameter laden *----------------------------------------------------------------------* FORM GET_FILENAME. DATA: lt_FILE_TABLE TYPE FILETABLE, ls_FILE TYPE FILE_TABLE, lv_RC TYPE I. LS_FILE-FILENAME = P_FILE. APPEND LS_FILE TO LT_FILE_TABLE. CALL METHOD CL_GUI_FRONTEND_SERVICES=>FILE_OPEN_DIALOG * EXPORTING * WINDOW_TITLE = * DEFAULT_EXTENSION = * DEFAULT_FILENAME = * FILE_FILTER = * WITH_ENCODING = * INITIAL_DIRECTORY = * MULTISELECTION = CHANGING FILE_TABLE = LT_FILE_TABLE RC = LV_RC * USER_ACTION = * FILE_ENCODING = 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 "Nachrichtenklasse TYPE sy-msgty "Typ (E = Error, S = Success, I = Info, A = Abbruch) NUMBER sy-msgno "Nachrichtennummer WITH sy-msgv1 "Platzhaltervariable1 sy-msgv2 "Platzhaltervariable2 sy-msgv3 "Platzhaltervariable3 sy-msgv4. "Platzhaltervariable4 MESSAGE i800(29) WITH iv_file. "Die sequentielle Datei & konnte nicht geöffnet werden MESSAGE i821(29). "Verarbeitung wurde abgebrochen LEAVE PROGRAM. ENDIF. READ TABLE LT_FILE_TABLE INTO LS_FILE INDEX 1. IF SY-SUBRC = 0. P_FILE = LS_FILE-FILENAME. ENDIF. ENDFORM. " GET_FILENAME *&---------------------------------------------------------------------* *& Form UPLOAD_FILE *&---------------------------------------------------------------------* * Upload Datei *----------------------------------------------------------------------* FORM upload_file USING iv_file TYPE rlgrap-filename CHANGING ct_file TYPE tty_file. DATA: lv_filename TYPE string. constants: lc_11 type i value 11, lc_12 type i value 12, lc_13 type i value 13, lc_14 type i value 14, lc_15 type i value 15, lc_16 type i value 16, lc_17 type i value 17, lc_18 type i value 18, lc_19 type i value 19. lv_filename = iv_file. CALL METHOD cl_gui_frontend_services=>gui_upload EXPORTING filename = lv_filename * FILETYPE = 'ASC' * HAS_FIELD_SEPARATOR = SPACE * HEADER_LENGTH = 0 * READ_BY_LINE = 'X' * DAT_MODE = SPACE CODEPAGE = '1100' "SAP(ISO)-Codepage 1100 Bezug auf ISO-Codepage 8859-1 (umfasst meiste westeuropäischen Zeichen). Bei Unicode-System Parameter auskommentieren * IGNORE_CERR = ABAP_TRUE * REPLACEMENT = '#' * VIRUS_SCAN_PROFILE = * IMPORTING * FILELENGTH = * HEADER = CHANGING data_tab = ct_file 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 = lc_11 unknown_dp_error = lc_12 access_denied = lc_13 dp_out_of_memory = lc_14 disk_full = lc_15 dp_timeout = lc_16 not_supported_by_gui = lc_17 error_no_gui = lc_18 OTHERS = lc_19. IF sy-subrc <> 0. MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4. ENDIF. ENDFORM. " UPLOAD_FILE
*&---------------------------------------------------------------------* *& Form READ_FLATFILE_INTO_UPLOAD *&---------------------------------------------------------------------* * Flatfile in strukturierte ITAB konvertieren *----------------------------------------------------------------------* FORM READ_FLATFILE_INTO_UPLOAD USING IT_FILE type tty_file CHANGING CT_UPLOAD type tty_upload. Data: ls_file type ty_file, ls_upload type ty_upload. loop at it_file into ls_file. clear ls_upload. split ls_file-data at p_split into ls_upload-feld1 ls_upload-feld2. "Felder Struktur aufführen append ls_upload to ct_upload. endloop. ENDFORM. " READ_FLATFILE_INTO_UPLOAD
*&---------------------------------------------------------------------* *& Form FILL_ITAB *&---------------------------------------------------------------------* * Füllen Interne Tabelle *----------------------------------------------------------------------* FORM FILL_ITAB USING IT_UPLOAD type tty_upload CHANGING CT_ITAB type tty_itab. Data: ls_file type ty_file, ls_itab type Ty_itab. ********************* * Füllen Positionen * ********************* loop at IT_upload ASSIGNING FIELD-SYMBOL(<fs_upload>). check sy-tabix <> 1. "Überschriftenzeile übergehen "Felder CT_ITAB füllen endloop. ENDFORM. " FILL_OUTPUT
*&---------------------------------------------------------------------* *& Form GET_DOWN_FILE *&---------------------------------------------------------------------* * Fülle Pfad für Downloadfile *----------------------------------------------------------------------* FORM GET_DOWN_FILE USING iv_FILE type RLGRAP-FILENAME CHANGING cv_DOWN_FILE TYPE RLGRAP-FILENAME. Data: lv_length type i. lv_length = strlen( iv_file ). * Inputfilepfad kürzen um ".csv" lv_length = lv_length - 4. * Inputfilepfad lediglich ergänzen um "_conv_txt" concatenate iv_file(lv_length) '_conv.txt' into cv_down_file. ENDFORM. " GET_DOWN_FILE
*&---------------------------------------------------------------------* *& Form DOWNLOAD *&---------------------------------------------------------------------* * Download konvertiertes File *----------------------------------------------------------------------* FORM DOWNLOAD USING IV_DOWN_FILE type RLGRAP-FILENAME IT_OUTFILE type tty_file. Data: lv_filename type string. lv_filename = iv_down_file. CALL METHOD CL_GUI_FRONTEND_SERVICES=>GUI_DOWNLOAD EXPORTING * BIN_FILESIZE = FILENAME = lv_filename * FILETYPE = 'ASC' * APPEND = SPACE * WRITE_FIELD_SEPARATOR = SPACE * HEADER = '00' * TRUNC_TRAILING_BLANKS = SPACE * WRITE_LF = 'X' * COL_SELECT = SPACE * COL_SELECT_MASK = SPACE * DAT_MODE = SPACE * CONFIRM_OVERWRITE = SPACE * NO_AUTH_CHECK = SPACE * CODEPAGE = SPACE * IGNORE_CERR = ABAP_TRUE * REPLACEMENT = '#' * WRITE_BOM = SPACE * TRUNC_TRAILING_BLANKS_EOL = 'X' * WK1_N_FORMAT = SPACE * WK1_N_SIZE = SPACE * WK1_T_FORMAT = SPACE * WK1_T_SIZE = SPACE * IMPORTING * FILELENGTH = CHANGING DATA_TAB = it_outfile 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 NOT_SUPPORTED_BY_GUI = 22 ERROR_NO_GUI = 23 OTHERS = 24. IF SY-SUBRC <> 0. MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4. MESSAGE I800(29) WITH iv_down_file. MESSAGE I821(29). "note509559 LEAVE PROGRAM. "note509559 ENDIF. ENDFORM. " DOWNLOAD