目录
1、固定资产导入
*&---------------------------------------------------------------------*
*& Program Name : ZFIB002 *
*& Title : 固定资产导入 *
*& Module Name : FICO *
*& Sub-Module : *
*& Author : *
*& Create Date : 2024-07-08 *
*& Logical DB : NOTHING *
*& Program Type : Report *
*&---------------------------------------------------------------------*
*& REVISION LOG *
*& LOG# DATE AUTHOR DESCRIPTION *
*& ---- ---- ---------- ----------- *
*& *
************************************************************************
REPORT zfib002.
TABLES : sscrfields .
TYPES: BEGIN OF typ_data ,
light TYPE icon-name,
message TYPE string,
anln1 TYPE anla-anln1, "资产主编号
anln2 TYPE anla-anln2, "资产子编号
anlkl TYPE anla-anlkl , "资产分类
bukrs TYPE anla-bukrs, "公司代码
txt50 TYPE anla-txt50, "描述
txa50 TYPE anla-txa50, "附加资产描述
anlhtxt TYPE anlh-anlhtxt, "资产主号文本
sernr TYPE anla-sernr , "序列号
invnr TYPE anla-invnr , "库存编号
INVZU TYPE ANLA-INVZU, "库存注释
menge TYPE anla-menge, "数量
meins TYPE anla-meins, "基本计量单位
aktiv TYPE anla-aktiv, "资本化日期
kostl TYPE anlz-kostl, "成本中心
kostlv TYPE anlz-kostlv, "责任成本中心
caufn TYPE anlz-caufn, "内部订单号
stort TYPE anlz-stort, "位置
raumn TYPE anlz-raumn, "存放地点
ord41 TYPE anla-ord41, "模具分类
ord42 TYPE anla-ord42, "评估小组2
ord43 TYPE anla-ord43, "评估小组3
ord44 TYPE anla-ord44, "评估小组4
gdlgrp TYPE anla-gdlgrp, "评估小组5
lifnr TYPE anla-lifnr, "供应商编号
liefe TYPE anla-liefe, "供应商名称
herst TYPE anla-herst, "制造商
afabe TYPE anlb-afabe, "实际折旧范围
afasl TYPE anlb-afasl, "折旧码
ndjar TYPE anlb-ndjar, "使用期年
ndper TYPE anlb-ndper, "期间
afabg TYPE anlb-afabg, "折旧开始日期
kansw TYPE anlc-kansw, "原值
knafa TYPE anlc-knafa, "累计折旧
nafag TYPE anlc-knafa, "本年折旧
* kaufw TYPE anlc-kaufw, "累计评估
* waers TYPE waers, "币别
* schrw TYPE anlb-schrw, "资产残值
* schrw_proz TYPE anlb-schrw_proz, "资产残值率
* xnega TYPE anlb-xnega, "标志: 允许负值
usnam TYPE sy-uname, "用户账户
zcjrq TYPE sy-datum, "创建日期
zcjsj TYPE sy-uzeit, "创建时间
END OF typ_data .
DATA: gt_data TYPE STANDARD TABLE OF typ_data,
gs_data TYPE typ_data.
DATA: gt_excel_tab LIKE zalsmex_tabline OCCURS 0 WITH HEADER LINE.
DATA:gt_inern TYPE TABLE OF zalsmex_tabline, "获取excel的数据
gs_inern LIKE LINE OF gt_inern.
TYPES: BEGIN OF typ_excel,
anln1 TYPE anla-anln1, "资产主编号
anln2 TYPE anla-anln2, "资产子编号
anlkl TYPE anla-anlkl , "资产分类
bukrs TYPE anla-bukrs, "公司代码
txt50 TYPE anla-txt50, "描述
txa50 TYPE anla-txa50, "附加资产描述
anlhtxt TYPE anlh-anlhtxt, "资产主号文本
sernr TYPE anla-sernr , "序列号
invnr TYPE anla-invnr , "库存编号
INVZU TYPE ANLA-INVZU, "库存注释
menge TYPE anla-menge, "数量
meins TYPE anla-meins, "基本计量单位
aktiv TYPE anla-aktiv, "资本化日期
kostl TYPE anlz-kostl, "成本中心
kostlv TYPE anlz-kostlv, "责任成本中心
caufn TYPE anlz-caufn, "内部订单号
stort TYPE anlz-stort, "位置
raumn TYPE anlz-raumn, "存放地点
ord41 TYPE anla-ord41, "模具分类
ord42 TYPE anla-ord42, "评估小组2
ord43 TYPE anla-ord43, "评估小组3
ord44 TYPE anla-ord44, "评估小组4
gdlgrp TYPE anla-gdlgrp, "评估小组5
lifnr TYPE anla-lifnr, "供应商编号
liefe TYPE anla-liefe, "供应商名称
herst TYPE anla-herst, "制造商
afabe TYPE anlb-afabe, "实际折旧范围
afasl TYPE anlb-afasl, "折旧码
ndjar TYPE anlb-ndjar, "使用期年
ndper TYPE anlb-ndper, "期间
afabg TYPE anlb-afabg, "折旧开始日期
kansw TYPE anlc-kansw, "原值
knafa TYPE anlc-knafa, "累计折旧
nafag TYPE anlc-knafa, "本年折旧
END OF typ_excel .
DATA: gt_excel TYPE TABLE OF typ_excel, "
gs_excel LIKE LINE OF gt_excel.
"ALV的定义
DATA: gt_fieldcat TYPE lvc_t_fcat,
gs_fieldcat TYPE lvc_s_fcat,
gs_layout TYPE lvc_s_layo.
FIELD-SYMBOLS: <data> TYPE typ_data.
*-----------------------------------------------------------------------*
DATA: ls_key TYPE bapi1022_key,
ls_generaldata TYPE bapi1022_feglg001,
ls_generaldatax TYPE bapi1022_feglg001x,
ls_inventory TYPE bapi1022_feglg011,
ls_inventoryx TYPE bapi1022_feglg011x,
ls_timedepend TYPE bapi1022_feglg003,
ls_timedependx TYPE bapi1022_feglg003x,
ls_allocations LIKE bapi1022_feglg004,
ls_allocationsx LIKE bapi1022_feglg004x,
ls_origin LIKE bapi1022_feglg009,
ls_originx LIKE bapi1022_feglg009x,
ls_posting TYPE bapi1022_feglg002,
ls_postingx TYPE bapi1022_feglg002x.
DATA: lt_cumval TYPE STANDARD TABLE OF bapi1022_cumval WITH HEADER LINE,
lt_return TYPE STANDARD TABLE OF bapiret2,
ls_return TYPE bapiret2,
lt_dep_areas TYPE STANDARD TABLE OF bapi1022_dep_areas WITH HEADER LINE,
lt_dep_areasx TYPE STANDARD TABLE OF bapi1022_dep_areasx WITH HEADER LINE,
lt_postval TYPE STANDARD TABLE OF bapi1022_postval WITH HEADER LINE,
lt_trtype TYPE STANDARD TABLE OF bapi1022_trtype WITH HEADER LINE.
DATA: l_companycode TYPE bapi1022_1-comp_code,
l_asset TYPE bapi1022_1-assetmaino,
l_subnumber TYPE bapi1022_1-assetsubno.
DATA: ttl_text TYPE string .
*----------------------------------------------------------------------*
DATA: i_s_log TYPE bal_s_log.
DATA: i_s_msg TYPE bal_s_msg.
DATA: e_log_handle TYPE balloghndl.
DATA: l_s_display_profile TYPE bal_s_prof.
DATA gv_biaoj TYPE c LENGTH 1 VALUE 'X'. "不知道为什么AT SELECTION-SCREEN会运行两次,这里做个标记为空才运行
DATA gv_fname TYPE string . "导出的文件名字
*----------------------------------------------------------------------*
SELECTION-SCREEN FUNCTION KEY 1."数字一到五对应的界面中可以增加的五个按钮
SELECTION-SCREEN BEGIN OF BLOCK b1 WITH FRAME TITLE TEXT-001 .
PARAMETERS: p_file TYPE rlgrap-filename MEMORY ID m1.
PARAMETERS: p_run TYPE c AS CHECKBOX DEFAULT 'X' .
SELECTION-SCREEN END OF BLOCK b1 .
*-----------------------------------------------------------------------*
INITIALIZATION .
WRITE icon_change_text AS ICON TO sscrfields-functxt_01+0(4)." 将图标ICON_CHANGE_TEXT 赋值给前四位
sscrfields-functxt_01+4(*) = '下载模板' . "将文字赋值给后面
* SSCRFIELDS-FUNCTXT_01 = '@0Q@下载模板' . "另一种方法是将图标代码加文字描述直接赋值给参数。
ttl_text = '期初资产导入' .
SET TITLEBAR 'TITLE1000' WITH ttl_text .
AT SELECTION-SCREEN.
CASE sscrfields-ucomm .
WHEN 'FC01' ."第一个自定义的按钮
PERFORM download_template ."下载模板
p_file = gv_fname .
ENDCASE.
AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_file."为文本框添加F4帮助
PERFORM get_file_path ."打开选择文件函数,获取文件路径
START-OF-SELECTION .
PERFORM sub_get_data .
PERFORM sub_check_data .
IF gt_data[] IS NOT INITIAL .
PERFORM create_asset_data .
PERFORM frm_display."ALV展示
ELSE.
MESSAGE '未能读取导入数据!' TYPE 'S' DISPLAY LIKE 'E' .
LEAVE LIST-PROCESSING .
ENDIF.
*&---------------------------------------------------------------------*
*& Form GET_FILE_PATH
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM get_file_path .
DATA: rc TYPE i,
f_table TYPE filetable.
DATA : l_initname TYPE string .
FIELD-SYMBOLS: <f> TYPE file_table .
* IF p EQ 'X'.
* CONCATENATE '' '-' sy-datum sy-uzeit'.xls' INTO l_initname.
* ENDIF .
CALL METHOD cl_gui_frontend_services=>file_open_dialog
EXPORTING
window_title = '选择文件'
default_filename = l_initname
file_filter = 'Excel文件(*.XLS,*.XLSX)|*.XLS;*.XLSX|全部文件 (*.*)|*.*|'
initial_directory = 'C:\'
multiselection = ' '
CHANGING
file_table = f_table
rc = rc
EXCEPTIONS
cntl_error = 1
file_open_dialog_failed = 2
error_no_gui = 3.
CALL METHOD cl_gui_cfw=>flush
EXCEPTIONS
cntl_error = 1
cntl_system_error = 2.
CLEAR: p_file .
READ TABLE f_table ASSIGNING <f> INDEX 1.
IF sy-subrc EQ 0.
p_file = <f>-filename.
ENDIF.
ENDFORM.
*&---------------------------------------------------------------------*
*& Form SUB_GET_DATA
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM sub_get_data .
CLEAR gt_inern[].
*导入文件数据处理
CALL FUNCTION 'ZALSM_EXCEL_TO_INTERNAL_TABLE'
EXPORTING
filename = p_file
i_begin_col = 1
i_begin_row = 7
i_end_col = 40
i_end_row = 65535
* I_SHEETINDEX =
TABLES
intern = gt_inern
EXCEPTIONS
inconsistent_parameters = 1
upload_ole = 2
OTHERS = 3.
IF sy-subrc <> 0.
MESSAGE '数据读取错误' TYPE 'S' DISPLAY LIKE 'E' .
RETURN .
ENDIF.
FREE:gt_excel.
FIELD-SYMBOLS:<row_value> TYPE any.
DATA: lcx_error TYPE REF TO cx_root. "cx_sy_sql_error . "cx_sy_open_sql_db.
DATA: err_text TYPE c LENGTH 1000.
DATA: lv_error TYPE c.
DATA: lv_str TYPE char50.
TRY .
LOOP AT gt_inern INTO gs_inern.
ASSIGN COMPONENT gs_inern-col
OF STRUCTURE gs_excel TO <row_value>.
<row_value> = gs_inern-value.
AT END OF row.
APPEND gs_excel TO gt_excel.
CLEAR gs_excel.
ENDAT.
ENDLOOP.
CATCH cx_root INTO lcx_error.
err_text = lcx_error->get_text( ). " 获取错误消息
MESSAGE err_text TYPE 'E'.
ENDTRY.
IF gt_excel[] IS NOT INITIAL.
MOVE-CORRESPONDING gt_excel[] TO gt_data[].
ENDIF.
* CLEAR: gt_excel_tab[].
* DATA:lv_col TYPE i.
* CALL FUNCTION 'ZALSM_EXCEL_TO_INTERNAL_TABLE3'
* EXPORTING
* filename = p_file
* i_begin_col = 1
* i_begin_row = 7
* i_end_col = 40
* i_end_row = 65535
** I_SHEETINDEX =
* TABLES
* intern = gt_excel_tab
* EXCEPTIONS
* inconsistent_parameters = 1
* upload_ole = 2
* OTHERS = 3.
* IF sy-subrc <> 0.
* MESSAGE '数据读取错误' TYPE 'S' DISPLAY LIKE 'E' .
* RETURN .
* ENDIF.
* LOOP AT gt_excel_tab.
** CASE gt_excel_tab-col.
** WHEN '001'.
** gs_data-anlkl = gt_excel_tab-value.
** WHEN '002'.
** gs_data-bukrs = gt_excel_tab-value.
** WHEN '003'.
** gs_data-txt50 = gt_excel_tab-value.
** WHEN '004'.
** gs_data-txa502 = gt_excel_tab-value.
** WHEN '005'.
** gs_data-txa50 = gt_excel_tab-value.
** WHEN '006'.
** gs_data-sernr = gt_excel_tab-value.
** WHEN '007'.
** gs_data-invnr = gt_excel_tab-value.
** WHEN '008'.
** gs_data-aktiv = gt_excel_tab-value.
** WHEN '009'.
** gs_data-menge = gt_excel_tab-value.
** WHEN '010'.
** gs_data-meins = gt_excel_tab-value.
** IF gs_data-meins IS NOT INITIAL.
** CALL FUNCTION 'CONVERSION_EXIT_CUNIT_INPUT'
** EXPORTING
** input = gs_data-meins
** language = sy-langu
** IMPORTING
** output = gs_data-meins
** EXCEPTIONS
** unit_not_found = 1
** OTHERS = 2.
** IF sy-subrc <> 0.
*** Implement suitable error handling here
** ENDIF.
**
** ENDIF.
** WHEN '011'.
** gs_data-kostl = gt_excel_tab-value.
** WHEN '012'.
** gs_data-kostlv = gt_excel_tab-value.
** WHEN '013'.
** gs_data-caufn = gt_excel_tab-value.
** WHEN '014'.
** gs_data-werks = gt_excel_tab-value.
** WHEN '015'.
** gs_data-raumn = gt_excel_tab-value.
** WHEN '016'.
** gs_data-kfzkz = gt_excel_tab-value.
** WHEN '017'.
** gs_data-ps_psp_pnr2 = gt_excel_tab-value.
** WHEN '018'.
** gs_data-ord41 = gt_excel_tab-value.
** WHEN '019'.
** gs_data-ord42 = gt_excel_tab-value .
** WHEN '020'.
** gs_data-ord43 = gt_excel_tab-value.
** WHEN '021'.
** gs_data-ord44 = gt_excel_tab-value.
** WHEN '022'.
** gs_data-gdlgrp = gt_excel_tab-value.
** WHEN '023'.
** gs_data-lifnr = gt_excel_tab-value.
** WHEN '024'.
** gs_data-liefe = gt_excel_tab-value.
** WHEN '025'.
** gs_data-herst = gt_excel_tab-value.
** WHEN '026'.
** gs_data-eaufn = gt_excel_tab-value.
** WHEN '027'.
** gs_data-posnr = gt_excel_tab-value.
** WHEN '028'.
** gs_data-afabe = gt_excel_tab-value.
** WHEN '029'.
** gs_data-afabg = gt_excel_tab-value.
** WHEN '030'.
** gs_data-afasl = gt_excel_tab-value.
** WHEN '031'.
** gs_data-ndjar = gt_excel_tab-value.
** WHEN '032'.
** gs_data-ndper = gt_excel_tab-value.
** WHEN '033'.
** gs_data-kansw = gt_excel_tab-value.
** WHEN '034'.
** gs_data-knafa = gt_excel_tab-value.
**
** WHEN '035'.
** gs_data-knafa2 = gt_excel_tab-value.
**
** WHEN '036'.
** gs_data-kaufw = gt_excel_tab-value.
**
** WHEN '037'.
** gs_data-waers = gt_excel_tab-value.
**
** WHEN '038'.
** gs_data-schrw = gt_excel_tab-value.
**
** WHEN '039'.
** gs_data-schrw_proz = gt_excel_tab-value.
**
** WHEN '040'.
** gs_data-xnega = gt_excel_tab-value.
** WHEN '041'.
** gs_data-anln1 = gt_excel_tab-value.
** WHEN OTHERS.
** ENDCASE.
*
*
* CASE gt_excel_tab-col.
* WHEN '001'.
* gs_data-anlkl = gt_excel_tab-value.
* WHEN '002'.
* gs_data-bukrs = gt_excel_tab-value.
* WHEN '003'.
* gs_data-txt50 = gt_excel_tab-value.
* WHEN '004'.
* gs_data-txa502 = gt_excel_tab-value.
* WHEN '005'.
* gs_data-txa50 = gt_excel_tab-value.
* WHEN '006'.
* gs_data-sernr = gt_excel_tab-value.
* WHEN '007'.
* gs_data-invnr = gt_excel_tab-value.
* WHEN '008'.
* gs_data-aktiv = gt_excel_tab-value.
* WHEN '009'.
* gs_data-menge = gt_excel_tab-value.
* WHEN '010'.
* gs_data-meins = gt_excel_tab-value.
* IF gs_data-meins IS NOT INITIAL.
* CALL FUNCTION 'CONVERSION_EXIT_CUNIT_INPUT'
* EXPORTING
* input = gs_data-meins
* language = sy-langu
* IMPORTING
* output = gs_data-meins
* EXCEPTIONS
* unit_not_found = 1
* OTHERS = 2.
* IF sy-subrc <> 0.
** Implement suitable error handling here
* ENDIF.
*
* ENDIF.
* WHEN '011'.
* gs_data-kostl = gt_excel_tab-value.
* WHEN '012'.
* gs_data-kostlv = gt_excel_tab-value.
* WHEN '013'.
* gs_data-caufn = gt_excel_tab-value.
* WHEN '014'.
* gs_data-werks = gt_excel_tab-value.
* WHEN '015'.
* gs_data-raumn = gt_excel_tab-value.
** WHEN '016'.
** gs_data-kfzkz = gt_excel_tab-value.
** WHEN '017'.
** gs_data-ps_psp_pnr2 = gt_excel_tab-value.
* WHEN '016'.
* gs_data-ord41 = gt_excel_tab-value.
* WHEN '017'.
* gs_data-ord42 = gt_excel_tab-value .
* WHEN '018'.
* gs_data-ord43 = gt_excel_tab-value.
* WHEN '019'.
* gs_data-ord44 = gt_excel_tab-value.
* WHEN '020'.
* gs_data-gdlgrp = gt_excel_tab-value.
* WHEN '021'.
* gs_data-lifnr = gt_excel_tab-value.
* WHEN '022'.
* gs_data-liefe = gt_excel_tab-value.
* WHEN '023'.
* gs_data-herst = gt_excel_tab-value.
* WHEN '024'.
* gs_data-eaufn = gt_excel_tab-value.
* WHEN '025'.
* gs_data-posnr = gt_excel_tab-value.
* WHEN '026'.
* gs_data-afabe = gt_excel_tab-value.
* WHEN '027'.
* gs_data-afabg = gt_excel_tab-value.
* WHEN '028'.
* gs_data-afasl = gt_excel_tab-value.
* WHEN '029'.
* gs_data-ndjar = gt_excel_tab-value.
* WHEN '030'.
* gs_data-ndper = gt_excel_tab-value.
* WHEN '031'.
* gs_data-kansw = gt_excel_tab-value.
* WHEN '032'.
* gs_data-knafa = gt_excel_tab-value.
*
* WHEN '033'.
* gs_data-knafa2 = gt_excel_tab-value.
*
* WHEN '034'.
* gs_data-kaufw = gt_excel_tab-value.
*
* WHEN '035'.
* gs_data-waers = gt_excel_tab-value.
*
* WHEN '036'.
* gs_data-schrw = gt_excel_tab-value.
*
* WHEN '037'.
* gs_data-schrw_proz = gt_excel_tab-value.
*
* WHEN '038'.
* gs_data-xnega = gt_excel_tab-value.
* WHEN '039'.
* gs_data-anln1 = gt_excel_tab-value.
* WHEN OTHERS.
* ENDCASE.
*
* AT END OF row.
* APPEND gs_data TO gt_data.
* CLEAR gs_data.
* ENDAT.
*
* ENDLOOP.
ENDFORM.
*&---------------------------------------------------------------------*
*& Form CREATE_ASSET_DATA
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM create_asset_data .
DATA:lv_pspnr TYPE prps-pspnr,
lv_pspnr2 TYPE prps-pspnr.
CALL FUNCTION 'BAL_GLB_MEMORY_REFRESH'.
CALL FUNCTION 'BAL_LOG_CREATE'
EXPORTING
i_s_log = i_s_log
IMPORTING
e_log_handle = e_log_handle
EXCEPTIONS
log_header_inconsistent = 1
OTHERS = 2.
SELECT pspnr,poski INTO TABLE @DATA(lt_prps) FROM prps.
SORT lt_prps BY poski.
SELECT bukrs,datum INTO TABLE @DATA(lt_t093c) FROM t093c.
SORT lt_t093c BY bukrs.
LOOP AT gt_data ASSIGNING <data> .
**************************** ITL23 2022/03/23
IF <data>-afabe IS INITIAL.
<data>-afabe = '01'.
ENDIF.
IF <data>-afasl IS INITIAL.
<data>-afasl = 'D002'.
ENDIF.
**************************** ITL23 2022/03/23
ls_key-companycode = <data>-bukrs .
ls_key-asset = <data>-anln1 .
ls_key-subnumber = <data>-anln2 .
*-----------------------------------------------------------------------*
ls_generaldata-assetclass = <data>-anlkl . "资产分类 必填
ls_generaldata-assetclass = |{ ls_generaldata-assetclass ALPHA = IN }|. "添加前导零
ls_generaldatax-assetclass = 'X' .
ls_generaldata-descript = <data>-txt50 . "描述 必填
ls_generaldatax-descript = 'X' .
ls_generaldata-descript2 = <data>-txa50 . "附加资产描述
ls_generaldatax-descript2 = 'X' .
ls_generaldata-main_descript = <data>-anlhtxt . "资产主号文本
ls_generaldatax-main_descript = 'X' .
************************************** ITL23 2022/03/28
* ls_generaldata-descript2 = <data>-txa50 . "募投项目名称 规格类型 选填
* ls_generaldatax-descript2 = 'X' .
************************************** ITL23 2022/03/28
ls_generaldata-serial_no = <data>-sernr . "序列号 必填
ls_generaldatax-serial_no = 'X' .
ls_generaldata-invent_no = <data>-invnr . "库存编号
ls_generaldatax-invent_no = 'X' .
* ls_generaldata-history = <data>-xhist . "历史性管理 不填
* ls_generaldatax-history = 'X' .
ls_posting-cap_date = <data>-aktiv . "资本化日期
ls_postingx-cap_date = 'X' .
* ls_posting-deact_date = <data>-deakt . "不活动日期 不填
* ls_postingx-deact_date = 'X'.
ls_generaldata-quantity = <data>-menge . "数量 选填
ls_generaldatax-quantity = 'X'.
ls_generaldata-base_uom = <data>-meins . "单位 选填
ls_generaldatax-base_uom = 'X'.
ls_generaldata-base_uom_iso = <data>-meins .
ls_generaldatax-base_uom_iso = 'X'.
*-----------------------------------------------------------------------*
* ls_inventory-include_in_list = <data>-inken . "库存标记 不填
ls_inventory-note = <data>-INVZU . "库存注释
* ls_inventoryx-include_in_list = 'X' .
ls_inventoryx-NOTE = 'X' .
*-----------------------------------------------------------------------*
* LS_POSTINGX-INITIAL_ACQ = 'X' .
*-----------------------------------------------------------------------*
ls_timedepend-costcenter = <data>-kostl . "成本中心 必填
ls_timedependx-costcenter = 'X' .
ls_timedepend-resp_cctr = <data>-kostlv . "责任成本中心 必填
ls_timedependx-resp_cctr = 'X' .
ls_timedepend-intern_ord = <data>-caufn . "内部订单号 选填
ls_timedependx-intern_ord = 'X' .
* ls_timedepend-plant = <data>-werks. "工厂 选填
* ls_timedependx-plant = 'X' .
ls_timedepend-location = <data>-stort. "位置
ls_timedependx-location = 'X' .
ls_timedepend-room = <data>-raumn . "存放地点 必填
ls_timedependx-room = 'X' .
* ls_timedepend-plate_no = <data>-kfzkz. "执照牌号/旧系统资产 选填
* ls_timedependx-license_plate_no = 'X'.
ls_allocations-evalgroup1 = <data>-ord41 . "模具分类 选填
ls_allocationsx-evalgroup1 = 'X' .
ls_allocations-evalgroup2 = <data>-ord42 . "评估小组2 选填
ls_allocationsx-evalgroup2 = 'X' .
ls_allocations-evalgroup3 = <data>-ord43 . "评估小组3 选填
ls_allocationsx-evalgroup3 = 'X' .
ls_allocations-evalgroup4 = <data>-ord44 . "评估小组4 选填
ls_allocationsx-evalgroup4 = 'X' .
ls_allocations-evalgroup5 = <data>-gdlgrp . "评估小组5 选填
ls_allocationsx-evalgroup5 = 'X' .
ls_origin-vendor_no = <data>-lifnr . "供应商编号
ls_originx-vendor_no = 'X' .
ls_origin-vendor = <data>-liefe . "供应商名称
ls_originx-vendor = 'X' .
ls_origin-manufacturer = <data>-herst . "制造商 可选
ls_originx-manufacturer = 'X' .
*-----------------------------------------------------------------------*
lt_dep_areas-area = <data>-afabe . "实际折旧范围 必填
lt_dep_areas-odep_start_date = <data>-afabg . "折旧开始日期 必填
* lt_dep_areas-scrapvalue = <data>-schrw .
* lt_dep_areas-scrapvalue_prctg = <data>-schrw_proz. "残值率
lt_dep_areas-dep_key = <data>-afasl . "折旧嘛
lt_dep_areas-ulife_yrs = <data>-ndjar . "使用期年
lt_dep_areas-ulife_prds = <data>-ndper ."期间
* lt_dep_areas-neg_values = <data>-xnega ."2022 06 09 增加允许负值
* lt_dep_areas-currency = <data>-waers .
* lt_dep_areas-currency_iso = <data>-waers .
APPEND lt_dep_areas .
lt_dep_areasx-area = <data>-afabe .
lt_dep_areasx-odep_start_date = 'X' .
* lt_dep_areasx-scrapvalue = 'X' .
* lt_dep_areasx-scrapvalue_prctg = 'X'.
lt_dep_areasx-dep_key = 'X' .
lt_dep_areasx-ulife_yrs = 'X' .
lt_dep_areasx-ulife_prds = 'X' .
* lt_dep_areasx-currency = 'X' .
* lt_dep_areasx-currency_iso = 'X' .
APPEND lt_dep_areasx .
CLEAR: lt_cumval.
READ TABLE lt_t093c INTO DATA(ls_t093c) WITH KEY bukrs = <data>-bukrs.
IF <data>-aktiv+0(4) < ls_t093c-datum+0(4)."SY-DATUM+0(4).
lt_cumval-fisc_year = ls_t093c-datum+0(4) ."SY-DATUM+0(4) - 1 .
* IF <data>-aktiv+0(4) < sy-datum+0(4)."SY-DATUM+0(4).
* lt_cumval-fisc_year = sy-datum+0(4) ."SY-DATUM+0(4) - 1 .
lt_cumval-area = <data>-afabe .
lt_cumval-acq_value = <data>-kansw .
* lt_cumval-rev_repl = <data>-kaufw . "累计评估重置价值/减值准备计提
* lt_cumval-ord_dep = <data>-knafa . ITL23 2022/03/28
lt_cumval-ord_dep = <data>-knafa * -1. "ITL23 2022/03/28
* lt_cumval-currency = <data>-waers .
* lt_cumval-currency_iso = <data>-waers .
APPEND lt_cumval .
ELSE.
lt_trtype-fisc_year = ls_t093c-datum+0(4)."SY-DATUM+0(4) .
* lt_trtype-fisc_year = sy-datum+0(4)."SY-DATUM+0(4) .
lt_trtype-current_no = sy-tabix .
lt_trtype-area = <data>-afabe .
lt_trtype-valuedate = <data>-aktiv.
lt_trtype-assettrtyp = '100' .
lt_trtype-amount = <data>-kansw.
* lt_trtype-currency = <data>-waers .
* lt_trtype-currency_iso = <data>-waers.
APPEND lt_trtype .
ENDIF.
IF <data>-nafag <> 0.
lt_postval-fisc_year = ls_t093c-datum+0(4)."SY-DATUM+0(4)
* lt_postval-fisc_year = sy-datum+0(4)."SY-DATUM+0(4)
lt_postval-area = <data>-afabe .
* IF LINES( LT_POSTVAL[] ) = 0.
* LT_POSTVAL-REV_REPL = <DATA>-KANSW .
* ENDIF.
* lt_postval-ORD_DEP = <data>-knafa2. ITL23 2022/03/28
lt_postval-ord_dep = <data>-nafag * -1. "ITL23 2022/03/28
* lt_postval-currency = <data>-waers .
* lt_postval-currency_iso = <data>-waers .
APPEND lt_postval .
ENDIF.
CALL FUNCTION 'BAPI_FIXEDASSET_OVRTAKE_CREATE'
EXPORTING
key = ls_key
* reference = ls_key
* CREATESUBNUMBER =
* CREATEGROUPASSET =
testrun = p_run
generaldata = ls_generaldata
generaldatax = ls_generaldatax
inventory = ls_inventory
inventoryx = ls_inventoryx
postinginformation = ls_posting
postinginformationx = ls_postingx
timedependentdata = ls_timedepend
timedependentdatax = ls_timedependx
allocations = ls_allocations
allocationsx = ls_allocationsx
origin = ls_origin
originx = ls_originx
* INVESTACCTASSIGNMNT =
* INVESTACCTASSIGNMNTX =
* NETWORTHVALUATION =
* NETWORTHVALUATIONX =
* REALESTATE =
* REALESTATEX =
* INSURANCE =
* INSURANCEX =
* LEASING =
* LEASINGX =
IMPORTING
companycode = l_companycode
asset = l_asset
subnumber = l_subnumber
* ASSETCREATED =
TABLES
depreciationareas = lt_dep_areas
depreciationareasx = lt_dep_areasx
* INVESTMENT_SUPPORT =
* EXTENSIONIN =
cumulatedvalues = lt_cumval[]
postedvalues = lt_postval[]
transactions = lt_trtype[]
* PROPORTIONALVALUES =
return = lt_return[]
* POSTINGHEADERS =
.
IF line_exists( lt_return[ type = 'E' ] ) OR line_exists( lt_return[ type = 'A' ] ).
CALL FUNCTION 'BAPI_TRANSACTION_ROLLBACK'.
<data>-light = icon_red_light.
LOOP AT lt_return INTO ls_return WHERE type = 'E' OR type = 'A'.
IF <data>-message IS INITIAL.
<data>-message = ls_return-message.
ELSE.
<data>-message = <data>-message && '/' && ls_return-message.
ENDIF.
ENDLOOP.
ELSE.
<data>-light = icon_green_light.
<data>-anln1 = l_asset.
IF p_run = 'X'.
<data>-message = '数据测试导入成功!'.
ELSE.
<data>-message = '数据导入成功!'.
ENDIF.
IF p_run IS INITIAL.
CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
EXPORTING
wait = 'X'.
* DO 10 TIMES.
* SELECT SINGLE bukrs,anln1,anln2,eaufn,posnr INTO @DATA(ls_anla) FROM anla WHERE bukrs = @l_companycode AND anln1 = @l_asset AND anln2 = @l_subnumber.
* IF sy-subrc = 0.
* EXIT.
* ELSE.
* WAIT UP TO 1 SECONDS.
* ENDIF.
* ENDDO.
* READ TABLE lt_prps INTO DATA(ls_prps) WITH KEY poski = <data>-posnr BINARY SEARCH.
* IF sy-subrc = 0.
* lv_pspnr = ls_prps-pspnr.
* UPDATE anla SET eaufn = <data>-eaufn posnr = lv_pspnr WHERE bukrs = ls_anla-bukrs AND anln1 = ls_anla-anln1 AND anln2 = ls_anla-anln2.
* IF sy-subrc = 0.
* COMMIT WORK.
* ENDIF.
* CLEAR:ls_anla,ls_prps.
* ENDIF.
* DO 10 TIMES.
* SELECT SINGLE bukrs,anln1,anln2,ps_psp_pnr2 INTO @DATA(ls_anlz) FROM anlz WHERE bukrs = @l_companycode AND anln1 = @l_asset AND anln2 = @l_subnumber.
* IF sy-subrc = 0.
* EXIT.
* ELSE.
* WAIT UP TO 1 SECONDS.
* ENDIF.
* ENDDO.
* READ TABLE lt_prps INTO ls_prps WITH KEY poski = <data>-ps_psp_pnr2 BINARY SEARCH. 注释于 20230823
* IF sy-subrc = 0.
* lv_pspnr2 = ls_prps-pspnr.
* UPDATE anlz SET ps_psp_pnr2 = lv_pspnr2 WHERE bukrs = ls_anlz-bukrs AND anln1 = ls_anlz-anln1 AND anln2 = ls_anlz-anln2.
* IF sy-subrc = 0.
* COMMIT WORK.
* ENDIF.
* CLEAR:ls_anlz,ls_prps.
* ENDIF.
ENDIF.
ENDIF.
CLEAR:ls_key ,
ls_generaldata,
ls_generaldata,
ls_inventory ,
ls_inventoryx ,
ls_timedepend ,
ls_timedependx,
ls_posting ,
ls_postingx ,
lt_postval,lt_postval[],
lt_cumval,lt_cumval[],
lt_return,lt_return[] ,
lt_dep_areas,lt_dep_areas[],
lt_dep_areasx,lt_dep_areasx[],
lt_postval,lt_postval[],
lt_trtype,lt_trtype[],
lv_pspnr,lv_pspnr2.
CLEAR:ls_t093c. "清空临时字段
ENDLOOP.
ENDFORM.
*&---------------------------------------------------------------------*
*& Form SUB_CHECK_DATA
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM sub_check_data .
DATA: lt_data TYPE STANDARD TABLE OF typ_data,
ls_data TYPE typ_data.
DATA: l_line TYPE i,
l_row TYPE string.
* DESCRIBE TABLE gt_data LINES l_line .
lt_data = gt_data .
SORT lt_data BY bukrs .
DELETE ADJACENT DUPLICATES FROM lt_data COMPARING bukrs .
DESCRIBE TABLE lt_data LINES l_line .
IF l_line > 1 .
MESSAGE '一次只能导入一个公司数据!' TYPE 'S' DISPLAY LIKE 'E' .
LEAVE LIST-PROCESSING .
ENDIF.
CLEAR: lt_data,l_row.
LOOP AT gt_data INTO gs_data .
ADD 1 TO l_row .
IF gs_data-anlkl IS INITIAL.
MESSAGE |第 { l_row }行资产分类为空!| TYPE 'S' DISPLAY LIKE 'E' .
LEAVE LIST-PROCESSING .
ENDIF.
IF gs_data-bukrs IS INITIAL.
MESSAGE |第 { l_row }行公司代码为空!| TYPE 'S' DISPLAY LIKE 'E' .
LEAVE LIST-PROCESSING .
ELSE.
SELECT SINGLE bukrs FROM t001 INTO @DATA(lv_bukrs) WHERE bukrs = @gs_data-bukrs .
IF sy-subrc NE 0.
MESSAGE |第 { l_row }行公司代码{ gs_data-bukrs }不存在!| TYPE 'S' DISPLAY LIKE 'E' .
LEAVE LIST-PROCESSING .
ENDIF.
ENDIF.
IF gs_data-anln1 IS NOT INITIAL.
SELECT SINGLE anln1 FROM anla INTO @DATA(lv_anln1)
WHERE bukrs = @gs_data-bukrs
AND anln1 = @gs_data-anln1
AND anln2 = @gs_data-anln2.
IF sy-subrc = 0.
MESSAGE |第 { l_row }行资产{ gs_data-anln1 }已存在!| TYPE 'S' DISPLAY LIKE 'E' .
LEAVE LIST-PROCESSING .
ENDIF.
ENDIF.
IF gs_data-txt50 IS INITIAL.
MESSAGE |第 { l_row }行资产描述为空!| TYPE 'S' DISPLAY LIKE 'E' .
LEAVE LIST-PROCESSING .
ENDIF.
IF gs_data-meins IS INITIAL.
MESSAGE |第 { l_row }行基本计量单位为空!| TYPE 'S' DISPLAY LIKE 'E' .
LEAVE LIST-PROCESSING .
ENDIF.
IF gs_data-aktiv IS INITIAL OR gs_data-aktiv = '00000000'.
MESSAGE |第 { l_row }行资本化日期为空!| TYPE 'S' DISPLAY LIKE 'E' .
LEAVE LIST-PROCESSING .
ENDIF.
IF gs_data-kostl IS INITIAL.
MESSAGE |第 { l_row }行成本中心为空!| TYPE 'S' DISPLAY LIKE 'E' .
LEAVE LIST-PROCESSING .
ELSE.
DATA(lv_kostl) = |{ gs_data-kostl ALPHA = IN }|.
SELECT SINGLE kostl FROM csks INTO @DATA(fv_kostl)
WHERE kostl = @lv_kostl
AND kokrs = 'SXSW'.
* AND datbi >= @sy-datum.
IF sy-subrc NE 0.
MESSAGE |第 { l_row }行成本中心{ gs_data-kostl }不存在!| TYPE 'S' DISPLAY LIKE 'E' .
LEAVE LIST-PROCESSING .
ENDIF.
ENDIF.
IF gs_data-afabe IS INITIAL.
MESSAGE |第 { l_row }行实际折旧范围为空!| TYPE 'S' DISPLAY LIKE 'E' .
LEAVE LIST-PROCESSING .
ENDIF.
IF gs_data-afasl IS INITIAL.
MESSAGE |第 { l_row }行折旧码为空!| TYPE 'S' DISPLAY LIKE 'E' .
LEAVE LIST-PROCESSING .
ENDIF.
* IF gs_data-ndjar IS INITIAL.
* MESSAGE |第 { l_row }行使用期年为空!| TYPE 'S' DISPLAY LIKE 'E' .
* LEAVE LIST-PROCESSING .
* ENDIF.
* IF gs_data-ndper IS INITIAL.
* MESSAGE |第 { l_row }行期间为空!| TYPE 'S' DISPLAY LIKE 'E' .
* LEAVE LIST-PROCESSING .
* ENDIF.
* IF gs_data-afabg IS INITIAL OR gs_data-afabg = '00000000'.
* MESSAGE |第 { l_row }行折旧开始日期为空!| TYPE 'S' DISPLAY LIKE 'E' .
* LEAVE LIST-PROCESSING .
* ENDIF.
* IF gs_data-kansw IS INITIAL.
* MESSAGE |第 { l_row }行原值为空!| TYPE 'S' DISPLAY LIKE 'E' .
* LEAVE LIST-PROCESSING .
* ENDIF.
* IF gs_data-knafa IS INITIAL.
* MESSAGE |第 { l_row }行累计折旧为空!| TYPE 'S' DISPLAY LIKE 'E' .
* LEAVE LIST-PROCESSING .
* ENDIF.
*
* IF gs_data-nafag IS INITIAL.
* MESSAGE |第 { l_row }行本年折旧为空!| TYPE 'S' DISPLAY LIKE 'E' .
* LEAVE LIST-PROCESSING .
* ENDIF.
* IF ( gs_data-ps_psp_pnr2 IS NOT INITIAL OR gs_data-posnr IS NOT INITIAL ) AND gs_data-eaufn IS NOT INITIAL . 注释于 20230823
* MESSAGE s001(00) WITH '第' l_row '行投资订单和WBS元素不能同时填入!' DISPLAY LIKE 'E' .
* LEAVE LIST-PROCESSING .
* ENDIF.
* IF gs_data-invnr = space .
* l_row = l_row + 2 .
** MESSAGE s001(00) WITH '第' l_row '行旧资产编号不能为空!' DISPLAY LIKE 'E' .
** LEAVE LIST-PROCESSING .
* ENDIF.
* READ TABLE lt_data INTO ls_data WITH KEY invnr = gs_data-invnr .
* IF sy-subrc = 0 .
* l_row = l_row + 2 .
** MESSAGE s001(00) WITH '第' l_row '行旧资产编号为重复项!' DISPLAY LIKE 'E' .
** LEAVE LIST-PROCESSING .
* ELSE .
* APPEND gs_data TO lt_data .
* ENDIF.
CLEAR gs_data.
ENDLOOP.
ENDFORM.
*&---------------------------------------------------------------------*
*& Form DOWNLOAD_TEMPLATE
*&---------------------------------------------------------------------*
*& text
*&---------------------------------------------------------------------*
*& --> p1 text
*& <-- p2 text
*&---------------------------------------------------------------------*
FORM download_template .
DATA: lo_objdata LIKE wwwdatatab,
lo_mime LIKE w3mime,
lc_filename TYPE string VALUE '资产期初导入',
lc_fullpath TYPE string VALUE 'F:\固定资产导入\固定资产导入',
lc_path TYPE string VALUE 'F:\固定资产导入\',
ls_destination LIKE rlgrap-filename,
ls_objnam TYPE string,
li_rc LIKE sy-subrc,
ls_errtxt TYPE string.
DATA: p_objid TYPE wwwdatatab-objid,
p_dest LIKE sapb-sappfad.
gv_biaoj = 'X' .
p_objid = 'ZFIB002' . "此处为excel模板名称
CALL METHOD cl_gui_frontend_services=>file_save_dialog "执行打开选择文件输入框
EXPORTING
default_extension = 'xlsx' "传出默认的文件扩展名
default_file_name = lc_filename "默认的文件名
CHANGING
filename = lc_filename "文件名更改存储
path = lc_path "文件目录更改存储
fullpath = lc_fullpath
EXCEPTIONS
cntl_error = 1
error_no_gui = 2
not_supported_by_gui = 3
OTHERS = 4.
IF lc_fullpath = '' .
MESSAGE '不能打开excel' TYPE 'S' DISPLAY LIKE 'E'.
ENDIF.
***************************选择模板文件
IF sy-subrc = 0.
p_dest = lc_fullpath.
* CONCATENATE P_OBJID '.XLS' INTO LS_OBJNAM.
CONDENSE ls_objnam NO-GAPS.
SELECT SINGLE relid objid FROM wwwdata INTO CORRESPONDING FIELDS OF lo_objdata
WHERE srtf2 = 0 AND relid = 'MI' AND objid = p_objid.
*********检查表wwwdata中是否存在指定的模板文件
IF sy-subrc NE 0 OR lo_objdata-objid EQ space.
CONCATENATE '模板文件' ls_objnam '不存在' INTO ls_errtxt.
MESSAGE ls_errtxt TYPE 'I'.
ENDIF.
ls_destination = p_dest. "保存路径
*******************如果存在,调用download_web_object 函数下载模板到路径下
CALL FUNCTION 'DOWNLOAD_WEB_OBJECT'
EXPORTING
key = lo_objdata
destination = ls_destination
IMPORTING
rc = li_rc.
IF li_rc NE 0.
CONCATENATE '模板文件' ls_objnam '下载失败' INTO ls_errtxt.
MESSAGE ls_errtxt TYPE 'E'.
ENDIF.
gv_fname = ls_destination.
ENDIF.
ENDFORM.
*&---------------------------------------------------------------------*
*& Form frm_display
*&---------------------------------------------------------------------*
*& text
*&---------------------------------------------------------------------*
*& --> p1 text
*& <-- p2 text
*&---------------------------------------------------------------------*
FORM frm_display .
PERFORM frm_set_layout.
PERFORM frm_set_fieldcat.
PERFORM frm_display_alv.
ENDFORM.
FORM frm_set_layout .
gs_layout-zebra = 'X'."斑马线
gs_layout-cwidth_opt = 'X'."适宽
ENDFORM.
FORM frm_set_fieldcat.
DATA: lv_name TYPE lvc_s_fcat-fieldname,
lv_scrtext TYPE lvc_s_fcat-scrtext_l.
REFRESH:gt_fieldcat.
PERFORM frm_build_fieldcat USING :
'LIGHT' '' '' '' '' '' '' '状态',
'MESSAGE' '' '' '' '' '' '' '消息文本',
'ANLN1' '' '' '' 'ANLA' 'ANLN1' '' '主要资产编号',
'ANLN2' '' '' '' 'ANLA' 'ANLN2' '' '子资产编号',
'ANLKL' '' '' '' 'ANLA' 'ANLKL' '' '资产分类',
'BUKRS' '' '' '' 'ANLA' 'BUKRS' '' '公司代码',
'TXT50' '' '' '' 'ANLA' 'TXT50' '' '描述',
'TXA50' '' '' '' 'ANLA' 'TXA50' '' '附加资产描述',
'ANLHTXT' '' '' '' 'ANLH' 'ANLHTXT' '' '资产主号文本',
'SERNR' '' '' '' 'ANLA' 'SERNR' '' '序列号',
'INVNR' '' '' '' 'ANLA' 'INVNR' '' '库存编号',
'INVZU' '' '' '' 'ANLA' 'INVZU' '' '库存注释',
'MENGE' '' '' '' 'ANLA' 'MENGE' '' '数量',
'MEINS' '' '' '' 'ANLA' 'MEINS' '' '基本计量单位',
'AKTIV' '' '' '' 'ANLA' 'AKTIV' '' '资本化日期',
'KOSTL' '' '' '' 'ANLZ' 'KOSTL' '' '成本中心',
'KOSTLV' '' '' '' 'ANLZ' 'KOSTLV' '' '责任成本中心',
'CAUFN' '' '' '' 'ANLZ' 'CAUFN' '' '内部订单号',
'STORT' '' '' '' 'ANLZ' 'STORT' '' '位置',
* 'WERKS' '' '' '' 'ANLZ' 'WERKS' '' '工厂',
'RAUMN' '' '' '' 'ANLZ' 'RAUMN' '' '存放地点',
* 'KFZKZ' '' '' '' 'ANLZ' 'KFZKZ' '' '执照牌号/旧系统资产',
* 'PS_PSP_PNR2' '' '' '' '' '' '' 'WBS要素',
'ORD41' '' '' '' 'ANLA' 'ORD41' '' '模具分类',"'机器设备小类',
'ORD42' '' '' '' 'ANLA' 'ORD42' '' '评审小组2',"'在建工程/电脑设备',
'ORD43' '' '' '' 'ANLA' 'ORD43' '' '评审小组3',"'低易品小类/是否保税',
'ORD44' '' '' '' 'ANLA' 'ORD44' '' '评审小组4',"'备用1/设备类型',
'GDLGRP' '' '' '' 'ANLA' 'GDLGRP' '' '评估小组5',"'备用2/使用情况',
'LIFNR' '' '' '' 'ANLA' 'LIFNR' '' '供应商编号',
'LIEFE' '' '' '' 'ANLA' 'LIEFE' '' '供应商名称',
'HERST' '' '' '' 'ANLA' 'HERST' '' '制造商',
* 'EAUFN' '' '' '' 'ANLA' 'EAUFN' '' '投资订单',
* 'POSNR' '' '' '' '' 'POSNR' '' 'WBS要素',"'WBS要素(CSMC)',
'AFABE' '' '' '' 'ANLB' 'AFABE' '' '实际折旧范围',
'AFABG' '' '' '' 'ANLB' 'AFABG' '' '折旧开始日期',
'AFASL' '' '' '' 'ANLB' 'AFASL' '' '折旧码',
'NDJAR' '' '' '' 'ANLB' 'NDJAR' '' '使用期年',
'NDPER' '' '' '' 'ANLB' 'NDPER' '' '期间',
'KANSW' '' '' '' 'ANLC' 'KANSW' '' '原值',
'KNAFA' '' '' '' 'ANLC' 'KNAFA' '' '累计折旧',
'NAFAG' '' '' '' 'ANLC' 'KNAFA' '' '本年折旧',
* 'KAUFW' '' '' '' 'ANLC' 'KAUFW' '' '累计评估重置价值',
* 'WAERS' '' '' '' 'MATDOC' 'WAERS' '' '币别',
* 'SCHRW' '' '' '' 'ANLB' 'SCHRW' '' '资产残值',
* 'SCHRW_PROZ' '' '' '' 'ANLB' 'SCHRW_PROZ' '' '资产残值率',
* 'XNEGA' '' '' '' 'ANLB' 'XNEGA' '' '标志:允许负值',
'USNAM' '' '' '' '' '' '' '用户账户',
'ZCJRQ' '' '' '' '' '' '' '创建日期',
'ZCJSJ' '' '' '' '' '' '' '创建时间'.
ENDFORM.
*&---------------------------------------------------------------------*
*& Form frm_build_fieldcat
*&---------------------------------------------------------------------*
*& text
*&---------------------------------------------------------------------*
*& --> p1 text
*& <-- p2 text
*&---------------------------------------------------------------------*
FORM frm_build_fieldcat USING pv_fieldname
pv_edit
pv_no_out
pv_no_zero
pv_ref_table
pv_ref_field
pv_f4
pv_reptext.
CLEAR gs_fieldcat.
gs_fieldcat-fieldname = pv_fieldname.
gs_fieldcat-edit = pv_edit.
gs_fieldcat-no_out = pv_no_out.
gs_fieldcat-no_zero = pv_no_zero.
gs_fieldcat-ref_table = pv_ref_table.
gs_fieldcat-ref_field = pv_ref_field.
gs_fieldcat-f4availabl = pv_f4.
gs_fieldcat-coltext = pv_reptext.
gs_fieldcat-reptext = pv_reptext.
gs_fieldcat-scrtext_l = pv_reptext.
gs_fieldcat-scrtext_m = pv_reptext.
gs_fieldcat-scrtext_s = pv_reptext.
APPEND gs_fieldcat TO gt_fieldcat.
ENDFORM.
FORM frm_display_alv.
CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY_LVC'
EXPORTING
i_callback_program = sy-repid
* i_callback_pf_status_set = 'FRM_SET_STATUS'
* i_callback_user_command = 'ALV_USER_COMMAND'
is_layout_lvc = gs_layout
it_fieldcat_lvc = gt_fieldcat
TABLES
t_outtab = gt_data
EXCEPTIONS
program_error = 1
OTHERS = 2.
IF sy-subrc <> 0.
* Implement suitable error handling here
ENDIF.
ENDFORM.
FORM frm_set_status USING rt_extab TYPE slis_t_extab.
SET PF-STATUS 'STATUS_1000'. "从标准拷出来并修改的STATUS
IF p_run = 'X'.
SET TITLEBAR 'TITLE_1000'.
ELSE.
SET TITLEBAR 'TITLE_1001'.
ENDIF.
ENDFORM.
屏幕可设计成这样
2、扩展质量视图
批量导人相对简单,只要将找到相应的bapi,对应着参数中的表将数据填进去就好,上面如果看不太懂,可以对应下面这个来看。
扩展质量视图,需要用到BAPI_MATERIAL_SAVEDATA这个bapi,之后只需要填一下下面这三个字段,模板输入只需要plant工厂和material物料编码。【这段程序可用作物料主数据的导入】
*&---------------------------------------------------------------------*
*& Report ZMME065
*&---------------------------------------------------------------------*
*& 物料主数据批量导入
*&---------------------------------------------------------------------*
REPORT zqme042.
TABLES : sscrfields .
TYPES: BEGIN OF typ_data ,
light TYPE icon-name,
message TYPE string,
plant TYPE marc-werks, "工厂
material TYPE marc-matnr, "物料号
END OF typ_data .
DATA: gt_data TYPE STANDARD TABLE OF typ_data,
gs_data TYPE typ_data.
DATA: gt_excel_tab LIKE zalsmex_tabline OCCURS 0 WITH HEADER LINE.
DATA:gt_inern TYPE TABLE OF zalsmex_tabline, "获取excel的数据
gs_inern LIKE LINE OF gt_inern.
TYPES: BEGIN OF typ_excel,
plant TYPE werks_d, "工厂
material TYPE matnr, "物料号
END OF typ_excel .
DATA: gt_excel TYPE TABLE OF typ_excel, "
gs_excel LIKE LINE OF gt_excel.
"ALV的定义
DATA: gt_fieldcat TYPE lvc_t_fcat,
gs_fieldcat TYPE lvc_s_fcat,
gs_layout TYPE lvc_s_layo.
FIELD-SYMBOLS: <data> TYPE typ_data.
*-----------------------------------------------------------------------*
*输入参数
DATA: headdata TYPE bapimathead, "表头数据
clientdata TYPE bapi_mara, "基本数据
clientdatax TYPE bapi_marax,
plantdata TYPE bapi_marc, "工厂级别数据
plantdatax TYPE bapi_marcx,
forecastparameters TYPE bapi_mpop, "预测
forecastparametersx TYPE bapi_mpopx,
planningdata TYPE bapi_mpgd, "计划
planningdatax TYPE bapi_mpgdx,
storagelocationdata TYPE bapi_mard, "存储位置
storagelocationdatax TYPE bapi_mardx,
valuationdata TYPE bapi_mbew, "评估数据
valuationdatax TYPE bapi_mbewx,
warehousenumberdata TYPE bapi_mlgn, "仓库数据
warehousenumberdatax TYPE bapi_mlgnx,
salesdata TYPE bapi_mvke, "销售数据
salesdatax TYPE bapi_mvkex,
storagetypedata TYPE bapi_mlgt, "存储类型数据
storagetypedatax TYPE bapi_mlgtx.
*Table参数
DATA: materialdescription TYPE TABLE OF bapi_makt WITH HEADER LINE, "描述
unitsofmeasure TYPE TABLE OF bapi_marm WITH HEADER LINE, "单位 "维护 毛重和体积单位
unitsofmeasurex TYPE TABLE OF bapi_marmx WITH HEADER LINE,
taxclassifications TYPE TABLE OF bapi_mlan WITH HEADER LINE. "税分类
*Return
DATA: return TYPE TABLE OF bapiret2.
DATA: ls_return TYPE bapiret2.
*----------------------------------------------------------------------*
DATA: ttl_text TYPE string .
DATA: i_s_log TYPE bal_s_log.
DATA: i_s_msg TYPE bal_s_msg.
DATA: e_log_handle TYPE balloghndl.
DATA: l_s_display_profile TYPE bal_s_prof.
DATA gv_biaoj TYPE c LENGTH 1 VALUE 'X'. "不知道为什么AT SELECTION-SCREEN会运行两次,这里做个标记为空才运行
DATA gv_fname TYPE string . "导出的文件名字
*----------------------------------------------------------------------*
SELECTION-SCREEN FUNCTION KEY 1."数字一到五对应的界面中可以增加的五个按钮
SELECTION-SCREEN BEGIN OF BLOCK b1 WITH FRAME TITLE TEXT-001 .
PARAMETERS: p_file TYPE rlgrap-filename MEMORY ID m1.
PARAMETERS: p_run TYPE c AS CHECKBOX DEFAULT 'X' .
SELECTION-SCREEN END OF BLOCK b1 .
*-----------------------------------------------------------------------*
INITIALIZATION .
WRITE icon_change_text AS ICON TO sscrfields-functxt_01+0(4)." 将图标ICON_CHANGE_TEXT 赋值给前四位
sscrfields-functxt_01+4(*) = '下载模板' . "将文字赋值给后面
* SSCRFIELDS-FUNCTXT_01 = '@0Q@下载模板' . "另一种方法是将图标代码加文字描述直接赋值给参数。
ttl_text = '物料主数据批量导入' .
SET TITLEBAR 'TITLE1000' WITH ttl_text .
AT SELECTION-SCREEN.
CASE sscrfields-ucomm .
WHEN 'FC01' ."第一个自定义的按钮
PERFORM download_template ."下载模板
p_file = gv_fname .
ENDCASE.
AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_file."为文本框添加F4帮助
PERFORM get_file_path ."打开选择文件函数,获取文件路径
START-OF-SELECTION .
PERFORM sub_get_data .
PERFORM sub_check_data .
IF gt_data[] IS NOT INITIAL .
PERFORM create_asset_data .
PERFORM frm_display."ALV展示
ELSE.
MESSAGE '未能读取导入数据!' TYPE 'S' DISPLAY LIKE 'E' .
LEAVE LIST-PROCESSING .
ENDIF.
*&---------------------------------------------------------------------*
*& Form GET_FILE_PATH
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM get_file_path .
DATA: rc TYPE i,
f_table TYPE filetable.
DATA : l_initname TYPE string .
FIELD-SYMBOLS: <f> TYPE file_table .
* IF p EQ 'X'.
* CONCATENATE '' '-' sy-datum sy-uzeit'.xls' INTO l_initname.
* ENDIF .
CALL METHOD cl_gui_frontend_services=>file_open_dialog
EXPORTING
window_title = '选择文件'
default_filename = l_initname
file_filter = 'Excel文件(*.XLS,*.XLSX)|*.XLS;*.XLSX|全部文件 (*.*)|*.*|'
initial_directory = 'C:\'
multiselection = ' '
CHANGING
file_table = f_table
rc = rc
EXCEPTIONS
cntl_error = 1
file_open_dialog_failed = 2
error_no_gui = 3.
CALL METHOD cl_gui_cfw=>flush
EXCEPTIONS
cntl_error = 1
cntl_system_error = 2.
CLEAR: p_file .
READ TABLE f_table ASSIGNING <f> INDEX 1.
IF sy-subrc EQ 0.
p_file = <f>-filename.
ENDIF.
ENDFORM.
*&---------------------------------------------------------------------*
*& Form SUB_GET_DATA
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM sub_get_data .
CLEAR gt_inern[].
*导入文件数据处理
CALL FUNCTION 'ZALSM_EXCEL_TO_INTERNAL_TABLE'
EXPORTING
filename = p_file
i_begin_col = 2
i_begin_row = 4
i_end_col = 3
i_end_row = 65535
* I_SHEETINDEX =
TABLES
intern = gt_inern
EXCEPTIONS
inconsistent_parameters = 1
upload_ole = 2
OTHERS = 3.
IF sy-subrc <> 0.
MESSAGE '数据读取错误' TYPE 'S' DISPLAY LIKE 'E' .
RETURN .
ENDIF.
FREE:gt_excel.
FIELD-SYMBOLS:<row_value> TYPE any.
DATA: lcx_error TYPE REF TO cx_root. "cx_sy_sql_error . "cx_sy_open_sql_db.
DATA: err_text TYPE c LENGTH 1000.
DATA: lv_error TYPE c.
DATA: lv_str TYPE char50.
TRY .
LOOP AT gt_inern INTO gs_inern.
ASSIGN COMPONENT gs_inern-col
OF STRUCTURE gs_excel TO <row_value>.
<row_value> = gs_inern-value.
AT END OF row.
APPEND gs_excel TO gt_excel.
CLEAR gs_excel.
ENDAT.
ENDLOOP.
CATCH cx_root INTO lcx_error.
err_text = lcx_error->get_text( ). " 获取错误消息
MESSAGE err_text TYPE 'E'.
ENDTRY.
IF gt_excel[] IS NOT INITIAL.
MOVE-CORRESPONDING gt_excel[] TO gt_data[].
ENDIF.
ENDFORM.
*&---------------------------------------------------------------------*
*& Form CREATE_ASSET_DATA
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM create_asset_data .
DATA:lv_pspnr TYPE prps-pspnr,
lv_pspnr2 TYPE prps-pspnr.
CALL FUNCTION 'BAL_GLB_MEMORY_REFRESH'.
CALL FUNCTION 'BAL_LOG_CREATE'
EXPORTING
i_s_log = i_s_log
IMPORTING
e_log_handle = e_log_handle
EXCEPTIONS
log_header_inconsistent = 1
OTHERS = 2.
LOOP AT gt_data ASSIGNING <data> .
CLEAR headdata.
CLEAR plantdata.
CLEAR plantdatax.
headdata-material = <data>-material.
headdata-quality_view = 'X'.
plantdata-plant = <data>-plant.
plantdatax-plant = <data>-plant.
*-----------------------------------------------------------------------*
CALL FUNCTION 'BAPI_MATERIAL_SAVEDATA'
EXPORTING
headdata = headdata
* CLIENTDATA =
* CLIENTDATAX =
plantdata = plantdata
plantdatax = plantdatax
* FORECASTPARAMETERS =
* FORECASTPARAMETERSX =
* PLANNINGDATA =
* PLANNINGDATAX =
* STORAGELOCATIONDATA =
* STORAGELOCATIONDATAX =
* VALUATIONDATA =
* VALUATIONDATAX =
* WAREHOUSENUMBERDATA =
* WAREHOUSENUMBERDATAX =
* SALESDATA =
* SALESDATAX =
* STORAGETYPEDATA =
* STORAGETYPEDATAX =
* FLAG_ONLINE = ' '
* FLAG_CAD_CALL = ' '
* NO_DEQUEUE = ' '
* NO_ROLLBACK_WORK = ' '
* CLIENTDATACWM =
* CLIENTDATACWMX =
* VALUATIONDATACWM =
* VALUATIONDATACWMX =
* MATPLSTADATA =
* MATPLSTADATAX =
* MARC_APS_EXTDATA =
* MARC_APS_EXTDATAX =
IMPORTING
return = ls_return
* TABLES
* MATERIALDESCRIPTION =
* UNITSOFMEASURE =
* UNITSOFMEASUREX =
* INTERNATIONALARTNOS =
* MATERIALLONGTEXT =
* TAXCLASSIFICATIONS =
* RETURNMESSAGES =
* PRTDATA =
* PRTDATAX =
* EXTENSIONIN =
* EXTENSIONINX =
* UNITSOFMEASURECWM =
* UNITSOFMEASURECWMX =
* SEGMRPGENERALDATA =
* SEGMRPGENERALDATAX =
* SEGMRPQUANTITYDATA =
* SEGMRPQUANTITYDATAX =
* SEGVALUATIONTYPE =
* SEGVALUATIONTYPEX =
* SEGSALESSTATUS =
* SEGSALESSTATUSX =
* SEGWEIGHTVOLUME =
* SEGWEIGHTVOLUMEX =
* DEMAND_PENALTYDATA =
* DEMAND_PENALTYDATAX =
* NFMCHARGEWEIGHTS =
* NFMCHARGEWEIGHTSX =
* NFMSTRUCTURALWEIGHTS =
* NFMSTRUCTURALWEIGHTSX =
.
IF ls_return-type = 'E' OR ls_return-type = 'A'.
CALL FUNCTION 'BAPI_TRANSACTION_ROLLBACK'.
<data>-light = icon_red_light.
<data>-message = ls_return-message.
ELSE.
<data>-light = icon_green_light.
IF p_run = 'X'.
<data>-message = '数据测试导入成功!'.
ELSE.
<data>-message = '数据导入成功!'.
ENDIF.
IF p_run IS INITIAL.
CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
EXPORTING
wait = 'X'.
ENDIF.
ENDIF.
ENDLOOP.
ENDFORM.
*&---------------------------------------------------------------------*
*& Form SUB_CHECK_DATA
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM sub_check_data .
DATA: lt_data TYPE STANDARD TABLE OF typ_data,
ls_data TYPE typ_data.
DATA: l_line TYPE i,
l_row TYPE string.
lt_data = gt_data .
* SORT LT_DATA BY BUKRS .
* DELETE ADJACENT DUPLICATES FROM LT_DATA COMPARING BUKRS .
* DESCRIBE TABLE LT_DATA LINES L_LINE .
* IF L_LINE > 1 .
* MESSAGE '一次只能导入一个公司数据!' TYPE 'S' DISPLAY LIKE 'E' .
* LEAVE LIST-PROCESSING .
* ENDIF.
CLEAR: lt_data,l_row.
LOOP AT gt_data INTO gs_data .
ADD 1 TO l_row .
IF gs_data-plant IS INITIAL.
MESSAGE |第 { l_row }行工厂为空!| TYPE 'S' DISPLAY LIKE 'E' .
LEAVE LIST-PROCESSING .
ENDIF.
IF gs_data-material IS INITIAL.
MESSAGE |第 { l_row }行物料编号为空!| TYPE 'S' DISPLAY LIKE 'E' .
LEAVE LIST-PROCESSING .
ENDIF.
CLEAR gs_data.
ENDLOOP.
ENDFORM.
*&---------------------------------------------------------------------*
*& Form DOWNLOAD_TEMPLATE
*&---------------------------------------------------------------------*
*& text
*&---------------------------------------------------------------------*
*& --> p1 text
*& <-- p2 text
*&---------------------------------------------------------------------*
FORM download_template .
DATA: lo_objdata LIKE wwwdatatab,
lo_mime LIKE w3mime,
lc_filename TYPE string VALUE '物料主数据批量导入',
lc_fullpath TYPE string VALUE 'F:\物料\物料',
lc_path TYPE string VALUE 'F:\物料\',
ls_destination LIKE rlgrap-filename,
ls_objnam TYPE string,
li_rc LIKE sy-subrc,
ls_errtxt TYPE string.
DATA: p_objid TYPE wwwdatatab-objid,
p_dest LIKE sapb-sappfad.
gv_biaoj = 'X' .
p_objid = 'ZMME065' . "此处为excel模板名称
CALL METHOD cl_gui_frontend_services=>file_save_dialog "执行打开选择文件输入框
EXPORTING
default_extension = 'xlsx' "传出默认的文件扩展名
default_file_name = lc_filename "默认的文件名
CHANGING
filename = lc_filename "文件名更改存储
path = lc_path "文件目录更改存储
fullpath = lc_fullpath
EXCEPTIONS
cntl_error = 1
error_no_gui = 2
not_supported_by_gui = 3
OTHERS = 4.
IF lc_fullpath = '' .
MESSAGE '不能打开excel' TYPE 'S' DISPLAY LIKE 'E'.
ENDIF.
***************************选择模板文件
IF sy-subrc = 0.
p_dest = lc_fullpath.
* CONCATENATE P_OBJID '.XLS' INTO LS_OBJNAM.
CONDENSE ls_objnam NO-GAPS.
SELECT SINGLE relid objid FROM wwwdata INTO CORRESPONDING FIELDS OF lo_objdata
WHERE srtf2 = 0 AND relid = 'MI' AND objid = p_objid.
*********检查表wwwdata中是否存在指定的模板文件
IF sy-subrc NE 0 OR lo_objdata-objid EQ space.
CONCATENATE '模板文件' ls_objnam '不存在' INTO ls_errtxt.
MESSAGE ls_errtxt TYPE 'I'.
ENDIF.
ls_destination = p_dest. "保存路径
*******************如果存在,调用download_web_object 函数下载模板到路径下
CALL FUNCTION 'DOWNLOAD_WEB_OBJECT'
EXPORTING
key = lo_objdata
destination = ls_destination
IMPORTING
rc = li_rc.
IF li_rc NE 0.
CONCATENATE '模板文件' ls_objnam '下载失败' INTO ls_errtxt.
MESSAGE ls_errtxt TYPE 'E'.
ENDIF.
gv_fname = ls_destination.
ENDIF.
ENDFORM.
*&---------------------------------------------------------------------*
*& Form frm_display
*&---------------------------------------------------------------------*
*& text
*&---------------------------------------------------------------------*
*& --> p1 text
*& <-- p2 text
*&---------------------------------------------------------------------*
FORM frm_display .
PERFORM frm_set_layout.
PERFORM frm_set_fieldcat.
PERFORM frm_display_alv.
ENDFORM.
FORM frm_set_layout .
gs_layout-zebra = 'X'."斑马线
gs_layout-cwidth_opt = 'X'."适宽
ENDFORM.
FORM frm_set_fieldcat.
DATA: lv_name TYPE lvc_s_fcat-fieldname,
lv_scrtext TYPE lvc_s_fcat-scrtext_l.
REFRESH:gt_fieldcat.
PERFORM frm_build_fieldcat USING :
'LIGHT' '' '' '' '' '' '' '状态',
'MESSAGE' '' '' '' '' '' '' '消息文本',
'PLANT' '' '' '' 'MARC' 'WERKS' '' '工厂',
'MATERIAL' '' '' '' 'MARC' 'MATNR' '' '物料编号'.
ENDFORM.
*&---------------------------------------------------------------------*
*& Form frm_build_fieldcat
*&---------------------------------------------------------------------*
*& text
*&---------------------------------------------------------------------*
*& --> p1 text
*& <-- p2 text
*&---------------------------------------------------------------------*
FORM frm_build_fieldcat USING pv_fieldname
pv_edit
pv_no_out
pv_no_zero
pv_ref_table
pv_ref_field
pv_f4
pv_reptext.
CLEAR gs_fieldcat.
gs_fieldcat-fieldname = pv_fieldname.
gs_fieldcat-edit = pv_edit.
gs_fieldcat-no_out = pv_no_out.
gs_fieldcat-no_zero = pv_no_zero.
gs_fieldcat-ref_table = pv_ref_table.
gs_fieldcat-ref_field = pv_ref_field.
gs_fieldcat-f4availabl = pv_f4.
gs_fieldcat-coltext = pv_reptext.
gs_fieldcat-reptext = pv_reptext.
gs_fieldcat-scrtext_l = pv_reptext.
gs_fieldcat-scrtext_m = pv_reptext.
gs_fieldcat-scrtext_s = pv_reptext.
APPEND gs_fieldcat TO gt_fieldcat.
ENDFORM.
FORM frm_display_alv.
CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY_LVC'
EXPORTING
i_callback_program = sy-repid
* i_callback_pf_status_set = 'FRM_SET_STATUS'
* i_callback_user_command = 'ALV_USER_COMMAND'
is_layout_lvc = gs_layout
it_fieldcat_lvc = gt_fieldcat
TABLES
t_outtab = gt_data
EXCEPTIONS
program_error = 1
OTHERS = 2.
IF sy-subrc <> 0.
* Implement suitable error handling here
ENDIF.
ENDFORM.
FORM frm_set_status USING rt_extab TYPE slis_t_extab.
SET PF-STATUS 'STATUS_1000'. "从标准拷出来并修改的STATUS
IF p_run = 'X'.
SET TITLEBAR 'TITLE_1000'.
ELSE.
SET TITLEBAR 'TITLE_1001'.
ENDIF.
ENDFORM.