Code: Alles auswählen.
REPORT zuploadtimeevents.
INCLUDE <icon>.
CLASS lcl_events DEFINITION.
PUBLIC SECTION.
CONSTANTS: cobtnloadtodb TYPE string VALUE 'BTNLOADDB'.
CLASS-METHODS: ontoolbarclick FOR EVENT added_function OF cl_salv_events_table
IMPORTING
e_salv_function
sender.
ENDCLASS.
CLASS lcl_events IMPLEMENTATION.
METHOD ontoolbarclick.
CASE e_salv_function.
WHEN cobtnloadtodb.
PERFORM uploadtodb.
ENDCASE.
ENDMETHOD.
ENDCLASS.
TYPES:
BEGIN OF ty_teven,
mandt TYPE mandt,
pdsnr TYPE pdsnr_d,
pernr TYPE pernr_d,
zausw TYPE dzausw,
ldate TYPE ldate,
ltime TYPE ltime,
erdat TYPE phdat,
ertim TYPE phtim,
satza TYPE retyp,
terid TYPE terid,
abwgr TYPE abwgr,
origf TYPE origf,
dallf TYPE dallf,
pdc_otype TYPE otype,
pdc_plans TYPE plans,
otype TYPE otype,
plans TYPE plans,
pdc_usrup TYPE pdc_usrup,
user2 TYPE hr_usrfld,
indeu TYPE indeu,
bukrs TYPE bukrs,
gsber TYPE gsber,
kostl TYPE kostl,
ltlst TYPE lstar,
aufnr TYPE aufnr,
kstrg TYPE kstrg,
posid TYPE ps_posid,
nplnr TYPE nplnr,
vornr TYPE vornr,
kdauf TYPE kdauf,
kdpos TYPE kdpos,
prznr TYPE co_prznr,
fistl TYPE fistl,
geber TYPE bp_geber,
skost TYPE kostl,
sbukr TYPE bukrs,
sgsbr TYPE gsber,
sgtxt TYPE sgtxt,
dart TYPE dart,
udart TYPE udart,
budget_pd TYPE fm_budget_period,
trfgr TYPE trfgr,
trfst TYPE trfst,
prakn TYPE prakn,
prakz TYPE prakz,
aufkz TYPE aufkn,
bwgrl TYPE ptm_vbas7s, " Use the actual data element from the table
waers TYPE waers,
END OF ty_teven.
DATA:
lt_itab TYPE TABLE OF string,
lttimeevents TYPE TABLE OF ty_teven,
lv_filename TYPE string,
watimeevent TYPE ty_teven.
DATA:
ltfiletable TYPE filetable,
lwfileline TYPE string,
lv_rc TYPE i,
lw_file TYPE string.
PARAMETERS: p_file TYPE string OBLIGATORY.
AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_file.
DATA: lt_files TYPE filetable.
CALL METHOD cl_gui_frontend_services=>file_open_dialog
EXPORTING
window_title = 'Select File'
default_extension = 'csv'
CHANGING
file_table = lt_files
rc = lv_rc
EXCEPTIONS
file_open_dialog_failed = 1
cntl_error = 2
error_no_gui = 3
not_supported_by_gui = 4
OTHERS = 5.
IF sy-subrc = 0 AND lv_rc = 0.
READ TABLE lt_files INDEX 1 INTO lw_file.
IF sy-subrc = 0.
p_file = lw_file.
ELSE.
MESSAGE 'No file selected!' TYPE 'W'.
ENDIF.
ELSE.
MESSAGE 'File selection canceled or error occurred.' TYPE 'I'.
ENDIF.
START-OF-SELECTION.
TRY.
CALL METHOD cl_gui_frontend_services=>gui_upload
EXPORTING
filename = p_file
filetype = 'ASC'
CHANGING
data_tab = lt_itab
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.
CATCH cx_sy_no_handler.
MESSAGE 'Unexpected error during file upload!' TYPE 'E'.
EXIT.
ENDTRY.
IF sy-subrc <> 0.
MESSAGE 'Error during file upload!' TYPE 'E'.
EXIT.
ENDIF.
LOOP AT lt_itab INTO DATA(line).
CLEAR watimeevent.
" Änderungen: Felder durch Komma getrennt
SPLIT line AT ',' INTO
watimeevent-mandt " Mandant
watimeevent-pdsnr " Nummer
watimeevent-pernr " Personalnummer
watimeevent-zausw " Zeitausweisnummer
watimeevent-ldate " Logisches Datum
watimeevent-ltime " Logische Uhrzeit
watimeevent-erdat " Erfassungsdatum
watimeevent-ertim " Erfassungszeit
watimeevent-satza " Zeitereignisart
watimeevent-terid " Terminal-ID
watimeevent-abwgr " An/Abwesenheitsgrund
watimeevent-origf " Herkunft
watimeevent-dallf " Tageszuordnung
watimeevent-pdc_otype " Objekttyp
watimeevent-pdc_plans " Planstelle
watimeevent-otype " Objekttyp
watimeevent-plans " Planstelle
watimeevent-user2 " Kundenfeld
watimeevent-indeu " Kundenfeld
watimeevent-pdc_usrup " I/D/U-Kennzeichen
watimeevent-bukrs " Buchungskreis
watimeevent-gsber " Geschäftsbereich
watimeevent-kostl " Kostenstelle
watimeevent-ltlst " Leistungsart
watimeevent-aufnr " Auftrag
watimeevent-kstrg " Kostenträger
watimeevent-posid " PSP-Element
watimeevent-nplnr " Netzplan
watimeevent-vornr " Vorgang
watimeevent-kdauf " Kundenauftrag
watimeevent-kdpos " Kundenauftrag-Pos
watimeevent-prznr " Geschäftsprozess
watimeevent-fistl " Finanzstelle
watimeevent-geber " Fonds
watimeevent-skost " Kostenstelle
watimeevent-sbukr " Buchungskreis
watimeevent-sgsbr " Geschäftsbereich
watimeevent-sgtxt " Text
watimeevent-dart " Dienstart
watimeevent-udart " Unterdienstart
watimeevent-budget_pd " Budgetperiode
watimeevent-trfgr " Tarifgruppe
watimeevent-trfst " Tarifstufe
watimeevent-prakn " Prämiennummer
watimeevent-prakz " Prämienkennzeichen
watimeevent-aufkz " Aufgeldkennzeichen
watimeevent-waers. " Währung
IF watimeevent-mandt IS NOT INITIAL.
APPEND watimeevent TO lttimeevents.
ENDIF.
ENDLOOP.
DATA lo_alv TYPE REF TO cl_salv_table.
TRY.
cl_salv_table=>factory(
EXPORTING
r_container = cl_gui_container=>default_screen
IMPORTING
r_salv_table = lo_alv
CHANGING
t_table = lttimeevents ).
DATA lo_columns TYPE REF TO cl_salv_columns_table.
lo_columns = lo_alv->get_columns( ).
DATA lo_column TYPE REF TO cl_salv_column.
lo_columns->set_optimize( abap_true ).
lo_column = lo_columns->get_column( 'LDATE' ).
lo_column->set_short_text( |Datum| ).
lo_column = lo_columns->get_column( 'LTIME' ).
lo_column->set_short_text( |Uhrzeit| ).
lo_column = lo_columns->get_column( 'SATZA' ).
lo_column->set_short_text( |Zeiter Art| ).
DATA lo_functions TYPE REF TO cl_salv_functions.
lo_functions = lo_alv->get_functions( ).
lo_functions->set_all( abap_true ).
lo_functions->add_function(
name = 'BTNLOADDB'
icon = '@08@'
text = 'Load to DB'
tooltip = 'Lädt die Daten in die Datenbank'
position = if_salv_c_function_position=>right_of_salv_functions ).
DATA(lo_events) = lo_alv->get_event( ).
SET HANDLER lcl_events=>ontoolbarclick FOR lo_events.
lo_alv->display( ).
WRITE space.
CATCH cx_salv_msg INTO DATA(lx_msg).
MESSAGE lx_msg->get_text( ) TYPE 'E'.
CATCH cx_salv_not_found.
MESSAGE 'ALV Grid/Table could not be created.' TYPE 'E'.
CATCH cx_salv_wrong_call.
MESSAGE 'Wrong call to SALV function.' TYPE 'E'.
CATCH cx_salv_existing.
MESSAGE 'SALV object already exists.' TYPE 'E'.
CATCH cx_salv_method_not_supported INTO DATA(lx_unsupported).
MESSAGE lx_unsupported->get_text( ) TYPE 'E'.
ENDTRY.
FORM uploadtodb.
INSERT cc1tev FROM TABLE lttimeevents.
IF sy-subrc <> 0.
MESSAGE 'Error during database insertion!' TYPE 'E'.
EXIT.
ENDIF.
COMMIT WORK.
MESSAGE 'Data successfully loaded into database!' TYPE 'S'.
ENDFORM.
Code: Alles auswählen.
IF sy-subrc = 0 AND lv_rc > 0.
READ TABLE lt_files INDEX 1 INTO lw_file.
IF sy-subrc = 0.
p_file = lw_file.
ELSE.
MESSAGE 'No file selected!' TYPE 'W'.
ENDIF.
ELSE.
MESSAGE 'File selection canceled or error occurred.' TYPE 'I'.
ENDIF.
Folgende Benutzer bedankten sich beim Autor IHe für den Beitrag:
DavidFaude