DB Import Programı
*&---------------------------------------------------------------------*
*& Report ZTR_DB_IMPORT
*&
*&---------------------------------------------------------------------*
*&
*&
*&---------------------------------------------------------------------*
REPORT ZTR_DB_IMPORT.
*data: gt_master type tty_master.
******Dinamik Tablo Değişkenleri
data: gt_dyntable type ref to data .
data: gt_subtable type ref to data .
field-symbols:
field-symbols:
******Dinamik Tablo Değişkenleri
constants c_msg_id type symsgid value `ZTR_BASIS`.
data: gv_precheck type c.
parameters: p_file type ibipparms-path obligatory.
parameters: p_dbname type tabname16 obligatory memory id zdb_name .
parameters: p_rowsze type int4
obligatory memory id zdb_rsze . "Satır sayısı
at selection-screen on value-request for p_file.
data: lv_rc type i.
data: lt_file_table type filetable,
ls_file_table type file_table.
call method cl_gui_frontend_services=>file_open_dialog
exporting
window_title = `Select a file`
changing
file_table = lt_file_table
rc = lv_rc.
if sy-subrc = 0.
read table lt_file_table into ls_file_table index 1.
p_file = ls_file_table-filename.
endif.
start-of-selection.
perform f_check_input changing gv_precheck .
end-of-selection.
if gv_precheck is initial.
perform f_file_to_db.
endif.
*&---------------------------------------------------------------------*
*& Form f_check_input
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* <--CHN_ERR text
*----------------------------------------------------------------------*
form f_check_input changing chn_err type c.
data: lvl_dosya_adi type string.
data: lv_result type abap_bool.
clear chn_err .
data: lv_new_file_name type fileextern .
lvl_dosya_adi = p_file.
call method cl_gui_frontend_services=>file_exist
exporting
file = lvl_dosya_adi
receiving
result = lv_result
exceptions
cntl_error = 1
error_no_gui = 2
wrong_parameter = 3
not_supported_by_gui = 4
others = 5.
if sy-subrc ne 0.
chn_err = `X`."Dosya bulunamadı :&
perform f_show_message_vl_1 using `005` p_dbname.
endif.
data: ls_dd02l type dd02l.
select single * into ls_dd02l from dd02l where tabname = p_dbname
and as4local = `A` and not ( tabclass = `APPEND`
or tabclass = `INTTAB` ) .
if sy-subrc ne 0.
chn_err = `X`."Veritabanı tablosu bulunamadı :&
perform f_show_message_vl_1 using `004` p_dbname.
endif.
endform. "f_check_input
*&---------------------------------------------------------------------*
*& Form f_show_message
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* -->PRM_TITLE text
* -->PRM_MSGID text
* -->PRM_MSGTY text
* -->PRM_MSGNO text
* -->PRM_MSGV1 text
* -->PRM_MSGV2 text
* -->PRM_MSGV3 text
* -->PRM_MSGV4 text
*----------------------------------------------------------------------*
form f_show_message using prm_title prm_msgid prm_msgty prm_msgno
prm_msgv1 prm_msgv2 prm_msgv3 prm_msgv4.
data: lv_title type string,
lv_msgid type symsgid,
lv_msgty type symsgty,
lv_msgno type symsgno,
lv_msgv1 type symsgv,
lv_msgv2 type symsgv,
lv_msgv3 type symsgv,
lv_msgv4 type symsgv.
lv_title = prm_title.
lv_msgid = prm_msgid.
lv_msgty = prm_msgty.
lv_msgno = prm_msgno.
lv_msgv1 = prm_msgv1.
lv_msgv2 = prm_msgv2.
lv_msgv3 = prm_msgv3.
lv_msgv4 = prm_msgv4.
call function `POPUP_DISPLAY_MESSAGE`
exporting
titel = lv_title
msgid = lv_msgid
msgty = lv_msgty
msgno = lv_msgno
msgv1 = lv_msgv1
msgv2 = lv_msgv2
msgv3 = lv_msgv3
msgv4 = lv_msgv4.
endform. "f_show_message
*&---------------------------------------------------------------------*
*& Form f_show_message_vl_0
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* -->PRM_MSGNO text
*----------------------------------------------------------------------*
form f_show_message_vl_0 using prm_msgno .
perform f_show_message using text-err c_msg_id `E` prm_msgno
`` `` `` ``.
endform. "f_show_message_vl_0
*&---------------------------------------------------------------------*
*& Form f_show_message_vl_1
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* -->PRM_MSGNO text
* -->PRM_MSGV1 text
*----------------------------------------------------------------------*
form f_show_message_vl_1 using prm_msgno prm_msgv1.
perform f_show_message using text-err c_msg_id `E` prm_msgno
prm_msgv1 `` `` ``.
endform. "f_show_message_vl_1
*&---------------------------------------------------------------------*
*& Form f_show_message_vl_2
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* -->PRM_MSGNO text
* -->PRM_MSGV1 text
* -->PRM_MSGV2 text
*----------------------------------------------------------------------*
form f_show_message_vl_2 using prm_msgno prm_msgv1 prm_msgv2.
perform f_show_message using text-err c_msg_id `E` prm_msgno
prm_msgv1 prm_msgv2 `` ``.
endform. "f_show_message_vl_2
*&---------------------------------------------------------------------*
*& Form f_file_to_db
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
form f_file_to_db.
perform f_create_dynamic_table using p_dbname .
perform f_fill_table .
perform f_save_db .
if
refresh
unassign
endif.
if
refresh
unassign
endif.
endform. "f_file_to_db
form f_create_dynamic_table using prm_tabname type tabname16.
data: lv_structure type dd02l-tabname .
create data gt_dyntable type standard table of (prm_tabname).
assign gt_dyntable->* to
create data gt_subtable type standard table of (prm_tabname).
assign gt_subtable->* to
endform. "f_create_dynamic_table
form f_fill_table.
DATA: lv_file TYPE string.
lv_file = p_file.
CALL METHOD cl_gui_frontend_services=>gui_upload
EXPORTING
filename = lv_file
filetype = `DAT`
CHANGING
data_tab =
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
not_supported_by_gui = 17
error_no_gui = 18
OTHERS = 19.
ENDFORM.
form f_save_db.
DATA: lv_count TYPE int4.
DATA: lv_total_count TYPE int4.
DATA: lv_file TYPE string.
data: lv_sayac type numc3.
DATA: lv_xndx TYPE int4.
FIELD-SYMBOLS:
DESCRIBE TABLE
lv_sayac = 0.
loop at
lv_xndx = sy-tabix.
append
DESCRIBE TABLE
if lv_count = p_rowsze or lv_xndx = lv_total_count .
lv_sayac = lv_sayac + 1.
modify (p_dbname) from TABLE
COMMIT WORK AND WAIT.
"write db
refresh
endif.
ENDLOOP.
ENDFORM.