Excel Upload (Çoklu deneme & Paketli okuma )
Bazı bilgisayarlarda ms office / sap client sürümünden kaynaklı olarak excel dosyasının açılmasında problemler yaşanmaktadır. ALSM_EXCEL_TO_INTERNAL_TABLE fonksiyonu hata dönmeden dahili tablo boş dönebiliyor.
ALSM_EXCEL_TO_INTERNAL_TABLE fonksiyonunu bir kaç kez çağırmak gerekebiliyor.
Ayrıca toplam satır bilinmiyor ise 1000lik satırlar halinde okumak gereklidir. Aşağıdaki formlar her iki problem içindir.
types: begin of ty_ongoru_ham,
DONEM type zpp_e_donem,
WERKS type WERKS_D,
MATNR type MATNR,
VERSB type VERSB,
PLNMG_B type PLNMG, "Veri tabanındaki miktar
MEINS_HL TYPE MEINS,
TARIH type ZPP_DEG_TARIH,
SAAT type ZPP_DEG_SAAT,
ERNAM type ERNAM,
PRDHA TYPE ZPP_E_PRDHA_10,
PRDHA_T TYPE ZPP_E_PRDHA_10T,
MEINS TYPE MEINS,
MSTAE TYPE MSTAE,
MAKTX TYPE MAKTX,
GJAHR type ZPP_ONGORUYIL,
MONAT type Zpp_ONGORUAY,
PLNMG_A type PLNMG, "yeni veri xls veya alv input
PLNMG_C type PLNMG, "sistemdeki miktar md61
"Marc
marc_werks type werks_d,
marc_MMSTA type MMSTA ,
end of ty_ongoru_ham.
types: tty_ongoru_ham type SORTED TABLE OF ty_ongoru_ham
with unique key DONEM
WERKS
MATNR
VERSB
WITH NON-UNIQUE SORTED KEY key_sistem
COMPONENTS werks matnr versb .
FORM get_data_xls USING prm_filename TYPE rlgrap-filename
CHANGING cht_ongoru_ham TYPE tty_ongoru_ham .
DATA: lt_filename TYPE filetable,
ls_filename TYPE file_table,
lv_filename TYPE string,
lv_rc TYPE i.
DATA :
lt_excel TYPE TABLE OF alsmex_tabline,
lt_excel_pack TYPE TABLE OF alsmex_tabline,
ls_excel TYPE alsmex_tabline,
lv_col TYPE kcd_ex_col_n.
DATA: ls_ongoru_ham TYPE ty_ongoru_ham.
DATA: lv_numc2 TYPE numc2.
DATA:it_raws TYPE truxs_t_text_data.
DATA lt_header TYPE tty_header_row .
DATA ls_header TYPE ty_header_row .
DATA lv_pack_size TYPE I VALUE 3000.
DATA lv_begin_row TYPE I .
DATA lv_end_row TYPE I .
DATA lv_count TYPE I .
DATA lv_readed_rows TYPE I .
REFRESH cht_ongoru_ham.
lv_count = 0.
do.
lv_begin_row = ( lv_count * lv_pack_size ) + 1.
lv_end_row = ( lv_count + 1 ) * lv_pack_size .
lv_count = lv_count + 1.
* excelden verileri okuyarak lt_excel tablosuna at
do 5 TIMES.
refresh lt_excel_pack.
CALL FUNCTION `ALSM_EXCEL_TO_INTERNAL_TABLE`
EXPORTING
filename = prm_filename
i_begin_col = 1
i_begin_row = lv_begin_row
i_end_col = 105 "100 Ay
i_end_row = lv_end_row
TABLES
intern = lt_excel_pack
EXCEPTIONS
inconsistent_parameters = 1
upload_ole = 2
OTHERS = 3.
if lt_excel_pack[] is not INITIAL.
exit.
endif.
enddo.
* IF sy-subrc NE 0.
* MESSAGE `Dosya Okumada Hata!` TYPE `E`.
* ENDIF.
DESCRIBE TABLE lt_excel_pack[] LINES lv_readed_rows.
if lv_readed_rows = 0.
exit.
else.
append LINES OF lt_excel_pack to lt_excel.
if lv_readed_rows < lv_pack_size.
exit.
endif.
endif.
ENDDO.
DATA: lv_tot_row TYPE kcd_ex_row_n,
lv_tot_col TYPE kcd_ex_col_n.
PERFORM f_parse_xls TABLES lt_excel
CHANGING lv_tot_row
lv_tot_col
lt_header .
DATA: lv_tarih TYPE char10.
* tablodaki verileri alarak itabına at
LOOP AT lt_excel INTO ls_excel .
CHECK ls_excel-row NE `0001`.
CASE ls_excel-col.
WHEN `0001`. "ÜY =>>>>
* ls_ongoru_ham-werks = ls_excel-value.
ls_ongoru_ham-werks = p_werks.
WHEN `0002`. "Kod
ls_ongoru_ham-matnr = ls_excel-value.
WHEN `0003`. "versiyon
ls_ongoru_ham-versb = ls_excel-value.
WHEN `0004`."Tek sütunda çalışılacak
READ TABLE lt_header INTO ls_header WITH TABLE KEY col = ls_excel-col.
IF sy-subrc EQ 0.
lv_tarih = ls_header-value.
REPLACE ALL OCCURRENCES OF `.` IN lv_tarih WITH ``.
CONDENSE lv_tarih.
ls_ongoru_ham-donem+0(4) = lv_tarih+4(4).
ls_ongoru_ham-donem+4(2) = lv_tarih+2(2).
ls_ongoru_ham-gjahr = ls_ongoru_ham-donem+0(4).
ls_ongoru_ham-monat = ls_ongoru_ham-donem+4(2).
ls_ongoru_ham-MEINS_HL = `HL`.
ls_ongoru_ham-plnmg_a = ls_excel-value.
ls_ongoru_ham-tarih = sy-datum.
ls_ongoru_ham-saat = sy-uzeit.
ls_ongoru_ham-ernam = sy-uname.
INSERT ls_ongoru_ham INTO TABLE cht_ongoru_ham.
ENDIF.
ENDCASE.
ENDLOOP.
ENDFORM. " GET_DATA
FORM f_parse_xls TABLES prt_excel STRUCTURE alsmex_tabline
CHANGING chn_total_row TYPE kcd_ex_row_n
chn_total_col TYPE kcd_ex_col_n
cht_header TYPE tty_header_row .
DATA: lt_counter_col TYPE tty_sayac.
DATA: lt_counter_row TYPE tty_sayac.
DATA: ls_counter TYPE ty_sayac.
DATA: lv_adet TYPE int4.
DATA: ls_header_row TYPE ty_header_row .
DATA: ls_excel TYPE alsmex_tabline.
REFRESH cht_header.
CLEAR chn_total_row.
CLEAR chn_total_col.
LOOP AT prt_excel INTO ls_excel.
ls_counter-sayac = ls_excel-row. INSERT ls_counter INTO TABLE lt_counter_row.
ls_counter-sayac = ls_excel-col. INSERT ls_counter INTO TABLE lt_counter_col.
CHECK ls_excel-row = `0001`. "Başlık bilgilierini ayıkla
CLEAR ls_header_row.
ls_header_row-col = ls_excel-col.
ls_header_row-value = ls_excel-value.
INSERT ls_header_row INTO TABLE cht_header.
ENDLOOP.
DESCRIBE TABLE lt_counter_row LINES lv_adet.
IF lv_adet > 0.
CLEAR ls_counter.
READ TABLE lt_counter_row INTO ls_counter INDEX lv_adet.
chn_total_row = ls_counter-sayac.
ENDIF.
DESCRIBE TABLE lt_counter_col LINES lv_adet.
IF lv_adet > 0.
CLEAR ls_counter.
READ TABLE lt_counter_col INTO ls_counter INDEX lv_adet.
chn_total_col = ls_counter-sayac.
ENDIF.
ENDFORM.