*&---------------------------------------------------------------------*
*& Report ZGRP_AC_IMPORT
*&
*&---------------------------------------------------------------------*
*&
*&
*&---------------------------------------------------------------------*
report zgrp_ac_import.
TYPE-POOLS:TRUXS.
* Definition of TYPES
types:
begin of typ_import ,
saknr like glaccount_screen_coa-saknr,
ktopl like glaccount_screen_coa-ktopl,
ktoks like ska1-ktoks,
xplacct like glaccount_screen_coa-xplacct,
xbilk like glaccount_screen_coa-xbilk,
txt20 like skat-txt20,
txt50 like skat-txt50,
vbund like ska1-vbund,
end of typ_import.
* Definition of DATAS
data:
gt_acdata type table of typ_import ,
gui_object type ref to cl_gui_frontend_services,
gt_file_path type filetable with header line ,
line type i,
it_tab type TRUXS_T_TEXT_DATA.
* Batchinputdata of single transaction
data: bdcdata like bdcdata occurs 0 with header line.
* Nodata-Character
data: nodata_character value '/'.
data MESSTAB type table of BDCMSGCOLL with header line.
data p_typ type ctu_mode value 'N'.
* Definition of Symbos
field-symbols :
<gt_acdata> type typ_import .
* Selection Screen
selection-screen begin of block b1 with frame title text-001.
parameters:p_file like rlgrap-filename.
selection-screen end of block b1.
at selection-screen on value-request for p_file .
create object gui_object.
call method cl_gui_frontend_services=>file_open_dialog
exporting
window_title = '选择导入文件'
file_filter = ',Microsoft Excel 文件,*.xls;*.xlsx;*.xlsm'".'
initial_directory = 'C:\'
changing
file_table = gt_file_path[]
rc = line.
if sy-subrc = 0.
read table gt_file_path index 1 .
p_file = gt_file_path-filename.
endif.
start-of-selection .
call function 'TEXT_CONVERT_XLS_TO_SAP'
exporting
* I_FIELD_SEPERATOR =
i_line_header = 'X'
i_tab_raw_data = it_tab
i_filename = p_file
tables
i_tab_converted_data = gt_acdata
exceptions
conversion_failed = 1
others = 2
.
if sy-subrc <> 0.
message id sy-msgid type sy-msgty number sy-msgno
with sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
exit.
endif.
loop at gt_acdata assigning <gt_acdata>.
perform bdc_dynpro using 'SAPLGL_ACCOUNT_MASTER_MAINTAIN' '2001'.
perform bdc_field using 'BDC_OKCODE'
'=ACC_CRE'.
perform bdc_field using 'BDC_CURSOR'
'GLACCOUNT_SCREEN_KEY-KTOPL'.
perform bdc_field using 'GLACCOUNT_SCREEN_KEY-SAKNR'
<gt_acdata>-saknr.
perform bdc_field using 'GLACCOUNT_SCREEN_KEY-KTOPL'
<gt_acdata>-ktopl.
perform bdc_dynpro using 'SAPLGL_ACCOUNT_MASTER_MAINTAIN' '2001'.
perform bdc_field using 'BDC_OKCODE'
'=2102_GROUP'.
perform bdc_field using 'BDC_CURSOR'
'GLACCOUNT_SCREEN_COA-KTOKS'.
perform bdc_field using 'GLACCOUNT_SCREEN_COA-KTOKS'
<gt_acdata>-ktoks.
perform bdc_field using 'GLACCOUNT_SCREEN_COA-XPLACCT'
<gt_acdata>-xplacct.
perform bdc_dynpro using 'SAPLGL_ACCOUNT_MASTER_MAINTAIN' '2001'.
perform bdc_field using 'BDC_OKCODE'
'=2102_BS_PL'.
perform bdc_field using 'BDC_CURSOR'
'GLACCOUNT_SCREEN_COA-XBILK'.
perform bdc_field using 'GLACCOUNT_SCREEN_COA-KTOKS'
<gt_acdata>-ktoks.
perform bdc_field using 'GLACCOUNT_SCREEN_COA-XPLACCT'
<gt_acdata>-xplacct.
perform bdc_field using 'GLACCOUNT_SCREEN_COA-XBILK'
<gt_acdata>-xbilk.
perform bdc_dynpro using 'SAPLGL_ACCOUNT_MASTER_MAINTAIN' '2001'.
perform bdc_field using 'BDC_OKCODE'
'=SAVE'.
perform bdc_field using 'GLACCOUNT_SCREEN_COA-KTOKS'
<gt_acdata>-ktoks.
perform bdc_field using 'GLACCOUNT_SCREEN_COA-XBILK'
<gt_acdata>-xbilk.
perform bdc_field using 'GLACCOUNT_SCREEN_COA-TXT20_ML'
<gt_acdata>-txt20.
perform bdc_field using 'GLACCOUNT_SCREEN_COA-TXT50_ML'
<gt_acdata>-txt50.
perform bdc_field using 'BDC_CURSOR'
'GLACCOUNT_SCREEN_COA-VBUND'.
perform bdc_transaction using 'FSP0' p_typ 'S' .
endloop.
* Definition of Forms
*----------------------------------------------------------------------*
* Start new transaction according to parameters *
*----------------------------------------------------------------------*
form bdc_transaction using tcode p_typ cupdate.
data: l_mstring(480).
data: l_subrc like sy-subrc..
refresh messtab.
call transaction tcode using bdcdata
mode p_typ
update cupdate "更新模式 f1可看
messages into messtab.
if lines( messtab ) > 0.
loop at messtab .
if messtab-msgtyp ne 'E' and messtab-msgtyp ne 'S'.
continue.
endif.
select single text from t100 into l_mstring
where sprsl = messtab-msgspra
and arbgb = messtab-msgid
and msgnr = messtab-msgnr.
if sy-subrc = 0.
if l_mstring cs '&1'. "
replace '&1' with messtab-msgv1 into l_mstring.
replace '&2' with messtab-msgv2 into l_mstring.
replace '&3' with messtab-msgv3 into l_mstring.
replace '&4' with messtab-msgv4 into l_mstring.
else.
replace '&' with messtab-msgv1 into l_mstring.
replace '&' with messtab-msgv2 into l_mstring.
replace '&' with messtab-msgv3 into l_mstring.
replace '&' with messtab-msgv4 into l_mstring.
endif.
condense l_mstring.
write:l_mstring.
endif.
endloop.
endif.
refresh bdcdata.
endform. " BDC_TRANSACTION
*----------------------------------------------------------------------*
* Start new screen *
*----------------------------------------------------------------------*
form bdc_dynpro using program dynpro.
clear bdcdata.
bdcdata-program = program.
bdcdata-dynpro = dynpro.
bdcdata-dynbegin = 'X'.
append bdcdata.
endform.
*----------------------------------------------------------------------*
* Insert field *
*----------------------------------------------------------------------*
form bdc_field using fnam fval.
if fval <> nodata_character.
clear bdcdata.
bdcdata-fnam = fnam.
bdcdata-fval = fval.
append bdcdata.
endif.
endform.
*----------------------------------------------------------------------*
* Insert field *
*----------------------------------------------------------------------*
form bdc_nodata using p_nodata.
nodata_character = p_nodata.
endform.
SAP 合并科目导入
最新推荐文章于 2024-11-13 14:44:50 发布