固定资产批导功能

REPORT zqficoc004a.

TABLES: sscrfields.
TYPE-POOLS:slis,truxs,icon .

"加载需要表
TABLES: anlb,anlu.

"Excel上传标准内表
DATA:lt_intern TYPE TABLE OF alsmex_tabline.

"导入Excel转换后内表格式
DATA: BEGIN OF wa_excel,
assetclass LIKE bapi1022_feglg001-assetclass, "资产分类
companycode LIKE bapi1022_key-companycode, "公司代码

    descript2       LIKE bapi1022_feglg001-descript2, "附加资产描述
    descript        LIKE bapi1022_feglg001-descript, "资产描述
    main_descript   LIKE bapi1022_feglg001-main_descript, "资产主号说明
  •    Txa50  Like Bapi1022_feglg001-descript ,"资产描述"资产标签号
    
  •    Anlhtxt  Like Bapi1022_feglg001-main_descript ,"规格型号
      zzjxxbm          LIKE anlu-zzjxxbm, "旧资产编号
      zzyl01          LIKE coas-aufnr, "内部订单号
    
      serial_no       LIKE bapi1022_feglg001-serial_no, "序列号
      invent_no       LIKE bapi1022_feglg001-invent_no, "存货号
      quantity        LIKE bapi1022_feglg001-quantity, "数量
      base_uom        LIKE bapi1022_feglg001-base_uom, "基本计量单位
      cap_date        LIKE bapi1022_feglg002-cap_date, "资产资本化日期
      odep_start_date LIKE bapi1022_dep_areas-odep_start_date,  "折旧开始日期
      costcenter      LIKE bapi1022_feglg003-costcenter, "成本中心
      resp_cctr       LIKE bapi1022_feglg003-resp_cctr, "归口成本中心
      bus_area        LIKE bapi1022_feglg003-bus_area, "业务范围
    

** plant LIKE bapi1022_feglg003-plant, "工厂
*** zproj TYPE char30, "项目
*** zprojname TYPE char50, "项目名称
** room LIKE bapi1022_feglg003-room, "房间
** vendor LIKE bapi1022_feglg009-vendor, "供应商描述

    evalgroup1      LIKE bapi1022_feglg004-evalgroup1 , "使用状态
    evalgroup2      LIKE bapi1022_feglg004-evalgroup2, " 资产使用人

    gdlgrp          LIKE bapi1022_feglg003-location , " 资产地点
    dep_key         LIKE bapi1022_dep_areas-dep_key, "折旧码
    ulife_yrs       LIKE bapi1022_dep_areas-ulife_yrs, "使用年限
    ulife_prds      LIKE bapi1022_dep_areas-ulife_prds, "期间
    exp_ulife_yrs   LIKE bapi1022_dep_areas-exp_ulife_yrs, "在财会年度开始时到期的有用年限
    exp_ulife_prds  LIKE bapi1022_dep_areas-exp_ulife_prds, "会计年起始时到期使用期限
    acq_value       LIKE bapi1022_cumval-acq_value, "原值
    l_ord_dep       LIKE bapi1022_cumval-ord_dep, "累计折旧
    m_ord_dep       LIKE bapi1022_postval-ord_dep, "本年折旧
    scrapvalue      LIKE bapi1022_dep_areas-scrapvalue,  "资产残值
  •    zzranln1       TYPE anlu-zzranln1,
    
  •  zzcanln1       TYPE anlu-zzcanln1,
      "        zzdep          TYPE anlu-zzdep,
    
  •    zzsenr         TYPE anlu-zzsenr,
    
  •    zzlocat        TYPE anlu-zzlocat,
    
  •    zzuser         TYPE anlu-zzuser,
    END OF wa_excel,
    it_excel LIKE STANDARD TABLE OF wa_excel.
    

"以下定义BAPI导入结构
DATA: key LIKE bapi1022_key, "要创建的关键字字段(公司代码、主资产号)
generaldata LIKE bapi1022_feglg001, "资产通用数据
generaldatax LIKE bapi1022_feglg001x, "资产通用数据确定
inventory TYPE bapi1022_feglg011,
inventoryx TYPE bapi1022_feglg011x,
postinginformation LIKE bapi1022_feglg002, "过帐数据
postinginformationx LIKE bapi1022_feglg002x, "过帐数据确定
timedependentdata LIKE bapi1022_feglg003, "资产时间相关数据
timedependentdatax LIKE bapi1022_feglg003x, "资产时间相关数据确定
allocations TYPE bapi1022_feglg004,
allocationsx TYPE bapi1022_feglg004x,
origin LIKE bapi1022_feglg009, "来源数据
originx LIKE bapi1022_feglg009x. "来源数据确定

"以下定义BAPI导入内表
DATA: depreciationareas LIKE STANDARD TABLE OF bapi1022_dep_areas, "资产折旧信息
wa_depreciationareas LIKE bapi1022_dep_areas, "资产折旧信息
depreciationareasx LIKE STANDARD TABLE OF bapi1022_dep_areasx, "资产折旧住处确定
wa_depreciationareasx LIKE bapi1022_dep_areasx, "资产折旧住处确定
cumulatedvalues LIKE STANDARD TABLE OF bapi1022_cumval, "往年折旧计算值
wa_cumulatedvalues LIKE bapi1022_cumval, "往年折旧计算值
postedvalues LIKE STANDARD TABLE OF bapi1022_postval, "当年折旧计算值
wa_postedvalues LIKE bapi1022_postval, "当年折旧计算值
transactions LIKE STANDARD TABLE OF bapi1022_trtype, "当年折旧金额
wa_transactions LIKE bapi1022_trtype. "当年折旧金额

"以下定义BAPI导入时的输出结果
DATA: return LIKE STANDARD TABLE OF bapiret2,
wa_return LIKE bapiret2,
companycode LIKE bapi1022_1-comp_code,
asset LIKE bapi1022_1-assetmaino,
subnumber LIKE bapi1022_1-assetsubno.

"定义消息输出内表
DATA: BEGIN OF wa_tab,
assetclass LIKE bapi1022_feglg001-assetclass, "资产分类
companycode LIKE bapi1022_key-companycode, "公司代码
asset LIKE bapi1022_1-assetmaino,
subnumber LIKE bapi1022_1-assetsubno,
invent_no LIKE bapi1022_feglg001-invent_no,
descript LIKE bapi1022_feglg001-descript, "资产描述
serial_no LIKE bapi1022_feglg001-serial_no, "序列号
zprojname TYPE char50, "项目名称
type LIKE bapiret2-type,
id LIKE bapiret2-id,
number LIKE bapiret2-number,
message LIKE bapiret2-message,
END OF wa_tab,
it_tab LIKE STANDARD TABLE OF wa_tab.

"定义ALV输出所需变量
DATA: fieldcat TYPE slis_t_fieldcat_alv WITH HEADER LINE, " 定义 ALV的有关数据
layout TYPE slis_layout_alv, " 定义 ALV的有关数据
ivariant LIKE disvariant, " 定义 ALV的有关数据
i_repid LIKE sy-repid. " 定义 ALV的有关数据

"定义临时变量
DATA msg TYPE string.

"导入文件选择
SELECTION-SCREEN BEGIN OF BLOCK 1 WITH FRAME TITLE TEXT-001.
PARAMETERS: p_fname LIKE rlgrap-filename. " 获取文件路径
SELECTION-SCREEN END OF BLOCK 1.

"附加条件选择
SELECTION-SCREEN BEGIN OF BLOCK 2 WITH FRAME TITLE TEXT-002.
PARAMETERS: p_ly TYPE gjahr OBLIGATORY,
p_my TYPE gjahr OBLIGATORY,
p_vd TYPE bf_bzdat OBLIGATORY.
SELECT-OPTIONS: dep_area FOR anlb-afabe NO INTERVALS OBLIGATORY .
SELECTION-SCREEN END OF BLOCK 2.

"其它附加条件选择
SELECTION-SCREEN BEGIN OF BLOCK 3 WITH FRAME TITLE TEXT-003.

  • PARAMETERS: r_l TYPE c RADIOBUTTON GROUP r1 ,
  •          r_m TYPE c RADIOBUTTON GROUP r1.
    
    PARAMETERS: tr AS CHECKBOX DEFAULT ‘X’.
    SELECTION-SCREEN END OF BLOCK 3.

SELECTION-SCREEN FUNCTION KEY 1.

AT SELECTION-SCREEN ON EXIT-COMMAND .

AT SELECTION-SCREEN.
CASE sy-ucomm.
WHEN ‘ONLI’.
PERFORM frm_input_check.
WHEN ‘FC01’.
PERFORM frm_download_excel_module USING ‘ZQFICOC004A’.
ENDCASE.

AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_fname.
PERFORM frm_get_filename CHANGING p_fname… " 把需要导入的文件的路径 存放在P_name 中

INITIALIZATION.
"自动计算本年与往年
MOVE sy-datum+0(4) TO p_my.
p_ly = p_my - 1.
MOVE ‘下载模板’ TO sscrfields-functxt_01.

START-OF-SELECTION.
PERFORM frm_upload. "通过路径 把EXCEL中的数据导入到 内表iexcel中
PERFORM frm_bapi_ext. "执行BAPI,并输出结果信息
PERFORM frm_alv. "结果输出显示

&---------------------------------------------------------------------
*& Form GET_FILENAME
&---------------------------------------------------------------------

  •   text
    

----------------------------------------------------------------------

  • –> p1 text
  • <-- p2 text
    ----------------------------------------------------------------------
    FORM frm_get_filename CHANGING pe_path.

DATA: lw_rc TYPE i,
lw_user TYPE i,
lit_file TYPE filetable,
liw_file TYPE file_table.

CALL METHOD cl_gui_frontend_services=>file_open_dialog
EXPORTING
window_title = ‘File select’
file_filter = ‘Excel Files (.xlsx)|.xlsx’
CHANGING
file_table = lit_file
rc = lw_rc
user_action = lw_user
EXCEPTIONS
file_open_dialog_failed = 1
cntl_error = 2
error_no_gui = 3
not_supported_by_gui = 4
OTHERS = 5.

IF sy-subrc <> 0.
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ELSE.
CHECK lw_rc = 1
AND lw_user <> 9.
READ TABLE lit_file INTO liw_file INDEX 1.
pe_path = liw_file-filename.
ENDIF.

ENDFORM. " GET_FILENAME
&---------------------------------------------------------------------
*& Form DOWNLOAD_EXCEL_MODULE
&---------------------------------------------------------------------

  •   text
    

----------------------------------------------------------------------
FORM frm_download_excel_module USING pv_obj_name.

DATA: l_v_filename TYPE string,
l_v_path TYPE string,
l_v_fullpath TYPE string,
l_v_filefilter TYPE string,
l_v_user_action TYPE i,
l_v_default_file_name TYPE string,
l_filename TYPE rlgrap-filename. " 文件名
DATA: l_v_obj_name TYPE wwwdata-objid,
l_wa_objdata TYPE wwwdatatab.
DATA: l_v_rc TYPE sy-subrc.
DATA: l_v_window_title TYPE string.

CONCATENATE cl_gui_frontend_services=>filetype_excel
cl_gui_frontend_services=>filetype_all
INTO l_v_filefilter SEPARATED BY space.

CONCATENATE sy-title ‘_’ sy-datum INTO l_v_default_file_name.
l_v_filefilter = ‘Excel Files (.xlsx)|.xlsx’.

CALL METHOD cl_gui_frontend_services=>file_save_dialog
EXPORTING
window_title = l_v_window_title
file_filter = l_v_filefilter
default_file_name = l_v_default_file_name
CHANGING
filename = l_v_filename
path = l_v_path
fullpath = l_v_fullpath
user_action = l_v_user_action
EXCEPTIONS
cntl_error = 1
error_no_gui = 2
not_supported_by_gui = 3
OTHERS = 4.

CHECK l_v_user_action = 0.

l_v_obj_name = pv_obj_name.

*&—检查表wwwdata中是否存在所指定的模板文件
SELECT SINGLE relid
objid
FROM wwwdata "存对象模板的表
INTO CORRESPONDING FIELDS OF l_wa_objdata
WHERE srtf2 = 0
AND relid = ‘MI’ "有三种类型 HT MI IT
AND objid = l_v_obj_name.

IF sy-subrc <> 0.
MESSAGE e005(zqmm01) WITH l_v_obj_name.
EXIT.
ENDIF.
IF l_wa_objdata-objid = space .
MESSAGE e005(zqmm01) WITH l_v_obj_name.
EXIT.
ENDIF.

*&—下载模板到指定路径
l_filename = l_v_fullpath.
p_fname = l_v_fullpath.
CALL FUNCTION ‘DOWNLOAD_WEB_OBJECT’
EXPORTING
key = l_wa_objdata
destination = l_filename
IMPORTING
rc = l_v_rc.
IF l_v_rc <> 0.
MESSAGE e406(/sc1/otc01) WITH l_v_obj_name.
EXIT.
ENDIF.

ENDFORM. " DOWNLOAD_EXCEL_MODULE

FORM frm_upload.
FIELD-SYMBOLS:.
DATA lo_oref TYPE REF TO cx_root.
DATA text TYPE string.

"上载文件
CALL FUNCTION ‘ALSM_EXCEL_TO_INTERNAL_TABLE’
EXPORTING
filename = p_fname
i_begin_col = 1
i_begin_row = 2
i_end_col = 35
i_end_row = 9999
TABLES
intern = lt_intern
EXCEPTIONS
inconsistent_parameters = 1
upload_ole = 2
OTHERS = 3.
CASE sy-subrc.
WHEN 1.
MESSAGE s004(zqmm01) RAISING alsm_excel_to_internal_table
DISPLAY LIKE ‘E’.
STOP.
WHEN 2.
MESSAGE s003(zqmm01) RAISING upload_ole
DISPLAY LIKE ‘E’.
STOP.
WHEN OTHERS.
ENDCASE.

"检查Excel数据内表
IF lt_intern IS INITIAL.
MESSAGE s002(zqmm01) DISPLAY LIKE ‘E’."清单中无数据
ENDIF.

SORT lt_intern BY row col.

LOOP AT lt_intern INTO DATA(ls_intern).

ASSIGN COMPONENT ls_intern-col OF STRUCTURE wa_excel TO  .
IF sy-subrc EQ 0.

  TRY.
      CONDENSE ls_intern NO-GAPS.
       = ls_intern-value.
    CATCH cx_sy_conversion_no_number INTO lo_oref.
      text = lo_oref->get_text( ).
      CONCATENATE 'CX_SY_CONVERSION_NO_NUMBER:' text INTO text.
      MESSAGE s005(zqmm01) WITH text DISPLAY LIKE 'E'.
      STOP.
  ENDTRY.

ENDIF.


AT END OF row.  " 在每一行结束的时候 把工作区域WA_EXCEL中的值写到内表IT_EXCEL中
  APPEND wa_excel TO it_excel.
  CLEAR wa_excel.
ENDAT.

ENDLOOP.

LOOP AT it_excel INTO wa_excel.
IF wa_excel-odep_start_date IS INITIAL.
MESSAGE s006(zqmm01) WITH text DISPLAY LIKE ‘E’.
STOP.
ENDIF.
ENDLOOP.

ENDFORM.

FORM frm_alv.
PERFORM fieldcat_init.
layout-colwidth_optimize = ‘X’. "设置自动调整列宽
layout-zebra = ‘X’. " 设置相邻行颜色不同 这样便于观看
i_repid = sy-repid.
CALL FUNCTION ‘REUSE_ALV_GRID_DISPLAY’
EXPORTING
i_callback_program = i_repid
it_fieldcat = fieldcat[]
is_variant = ivariant
is_layout = layout
TABLES
t_outtab = it_tab
EXCEPTIONS
program_error = 1
OTHERS = 2.
ENDFORM.

FORM fieldcat_init.
PERFORM frm_catlg_set USING:
‘ASSETCLASS’ ‘资产分类’, " ‘’ 里面的字母需要大写
‘COMPANYCODE’ ‘公司代码’,
‘ASSET’ ‘资产编码’,
‘SUBNUMBER’ ‘资产子编码’,
‘INVENT_NO’ ‘存货号’,
‘ZPROJNAME’ ‘使用项目名称’,
‘DESCRIPT’ ‘资产描述’,
‘SERIAL_NO’ ‘预留字段1’,
‘TYPE’ ‘消息类型’,
‘ID’ ‘消息ID’,
‘NUMBER’ ‘消息编码’,
‘MESSAGE’ ‘消息文本’.

ENDFORM.

FORM frm_catlg_set USING p_field p_text.
DATA: temp_fieldcat TYPE slis_fieldcat_alv.
temp_fieldcat-fieldname = p_field.
temp_fieldcat-seltext_l = p_text.
APPEND temp_fieldcat TO fieldcat.
CLEAR temp_fieldcat.
ENDFORM.

&---------------------------------------------------------------------
*& Form FRM_BAPI_EXT
&---------------------------------------------------------------------

  •   text
    

----------------------------------------------------------------------

  • –> p1 text

  • <-- p2 text
    ----------------------------------------------------------------------
    FORM frm_bapi_ext .
    DATA:ls_anlu TYPE anlu.
    "循环内表数据,准备导入
    DATA:ls_exanlu TYPE bapi_te_anlu.
    DATA:ls_ex TYPE ci_anlu.
    DATA:ls_extension TYPE bapiparex,
    lt_extension TYPE STANDARD TABLE OF bapiparex.
    DATA extensionin LIKE TABLE OF bapiparex WITH HEADER LINE.
    LOOP AT it_excel INTO wa_excel.
    "输出处理信息
    msg = sy-tabix.
    CONCATENATE TEXT-s03 msg TEXT-s04 INTO msg.
    "处理数据提示
    CALL FUNCTION ‘SAPGUI_PROGRESS_INDICATOR’
    EXPORTING
    text = msg.

    "处理关键值数据
    key-companycode = wa_excel-companycode.

  • KEY-ASSET = WA_EXCEL-ANLN1. "主资产号

  • KEY-SUBNUMBER = WA_EXCEL-ANLN2. "资产次级编号
    "对资产类增加前导0
    CALL FUNCTION ‘CONVERSION_EXIT_ALPHA_INPUT’
    EXPORTING
    input = wa_excel-assetclass
    IMPORTING
    output = generaldata-assetclass.

wa_excel-zzyl01 = |{ wa_excel-zzyl01 ALPHA = IN }|.
"处理一般数据
generaldata-assetclass    = wa_excel-assetclass.
generaldata-descript      = wa_excel-descript.
generaldata-descript2     = wa_excel-descript2.
generaldata-main_descript = wa_excel-main_descript.
generaldata-serial_no     = wa_excel-serial_no.
generaldata-invent_no     = wa_excel-invent_no.
generaldata-acct_detrm    = wa_excel-assetclass.
generaldata-quantity      = wa_excel-quantity.
IF wa_excel-base_uom IS NOT INITIAL.
  CALL FUNCTION 'CONVERSION_EXIT_CUNIT_INPUT'
    EXPORTING
      input          = wa_excel-base_uom
      language       = sy-langu
    IMPORTING
      output         = generaldata-base_uom             "基本计量单位
    EXCEPTIONS
      unit_not_found = 1
      OTHERS         = 2.
ENDIF.

generaldatax-assetclass    = 'X'.
generaldatax-descript      = 'X'.
generaldatax-descript2     = 'X'.
generaldatax-main_descript = 'X'.
generaldatax-serial_no     = 'X'.
generaldatax-invent_no     = 'X'.
generaldatax-quantity      = 'X'.
generaldatax-base_uom      = 'X'.

*INVENTORY

  • INVENTORY-NOTE = WA_EXCEL-INVZU. "补充库存说明
    **INVENTORYX
  • INVENTORYX-NOTE = ‘X’.
"处理过帐数据
postinginformation-cap_date = wa_excel-cap_date.
postinginformationx-cap_date = 'X'.

"成本中心数据
timedependentdata-costcenter  = wa_excel-costcenter.
timedependentdata-resp_cctr   = wa_excel-resp_cctr.
timedependentdata-bus_area   = wa_excel-bus_area.
  • timedependentdata-plant = wa_excel-plant.

  • timedependentdata-room = wa_excel-room.

  • timedependentdata-shutdown = wa_excel-ord41 . " 资产停用

  • timedependentdata-person_no = wa_excel-ord42. "员工号

timedependentdatax-costcenter = 'X'.
timedependentdatax-resp_cctr  = 'X'.
timedependentdatax-bus_area   = 'X'.
  • timedependentdatax-plant = ‘X’.
  • timedependentdatax-room = ‘X’.
  • timedependentdatax-shutdown = ‘X’. " 资产停用
  • timedependentdatax-person_no = ‘X’. "员工号

*ALLOCATIONS

  • ALLOCATIONS-EVALGROUP3 = WA_EXCEL-ORD43. "资产位置
    allocations-evalgroup1 = wa_excel-evalgroup1. "资产来源
    allocations-evalgroup2 = wa_excel-evalgroup2. "资产用途
    allocations-evalgroup5 = wa_excel-gdlgrp. "存放地点
    *ALLOCATIONSX
  • ALLOCATIONSX-EVALGROUP3 = ‘X’.
    allocationsx-evalgroup1 = ‘X’.
    allocationsx-evalgroup2 = ‘X’.
    allocationsx-evalgroup5 = ‘X’.
"处理供应商数据  供应商描述
"  origin-vendor = wa_excel-vendor.
"  originx-vendor = 'X'.

"循环处理折旧范围数据
" LOOP AT DEP_AREA.
"增加折旧范围数据
wa_depreciationareas-area            = dep_area-low.
wa_depreciationareas-dep_key         = wa_excel-dep_key.
wa_depreciationareas-ulife_yrs       = wa_excel-ulife_yrs.
wa_depreciationareas-ulife_prds      = wa_excel-ulife_prds.
wa_depreciationareas-exp_ulife_yrs   = wa_excel-exp_ulife_yrs.
wa_depreciationareas-exp_ulife_prds  = wa_excel-exp_ulife_prds.
wa_depreciationareas-scrapvalue      = wa_excel-scrapvalue .
wa_depreciationareas-odep_start_date = wa_excel-odep_start_date.
wa_depreciationareasx-area           = dep_area-low.
wa_depreciationareasx-dep_key        = 'X'.
wa_depreciationareasx-ulife_yrs      = 'X'.
wa_depreciationareasx-ulife_prds     = 'X'.
wa_depreciationareasx-exp_ulife_yrs  = 'X'.
wa_depreciationareasx-exp_ulife_prds = 'X'.
wa_depreciationareasx-scrapvalue     = 'X'.
wa_depreciationareasx-odep_start_date = 'X'.
APPEND wa_depreciationareas TO depreciationareas.
APPEND wa_depreciationareasx TO depreciationareasx.
"处理资产价值接管数据
"   IF r_l = 'X'. "处理往年数据
"增加累计折旧
  •  wa_cumulatedvalues-fisc_year = p_ly.
    
  •  wa_cumulatedvalues-area      = dep_area-low.
    
  •  wa_cumulatedvalues-acq_value = wa_excel-acq_value .
    
  •  wa_cumulatedvalues-ord_dep   = wa_excel-l_ord_dep * -1.
    
  •  " wa_cumulatedvalues-spe_dep = abs( wa_excel-ksafa ) * -1. " 以前年度特殊折旧
    
  •  APPEND wa_cumulatedvalues TO cumulatedvalues.
    
  •  "增加正常折旧
    
  •  wa_postedvalues-fisc_year = p_my.
    
  •  wa_postedvalues-area      = dep_area-low.
    
  •  wa_postedvalues-ord_dep   = wa_excel-m_ord_dep * -1.
    
  •  APPEND wa_postedvalues TO postedvalues.
    

    " ELSE. "处理当年数据

  • IF wa_excel-cap_date+0(4) <> 2021. " 写代码的时候是2021年 2021年是当年,当是当年时不需要累计折旧,往年才需要
    IF ( wa_excel-acq_value > 0 OR wa_excel-l_ord_dep <> 0 ) AND wa_excel-cap_date <= ‘20211231’. " 写代码的时候是2021年 2021年是当年,当是当年时不需要累计折旧,往年才需要

    "增加累计折旧
    wa_cumulatedvalues-fisc_year = p_my.
    wa_cumulatedvalues-area = dep_area-low.
    wa_cumulatedvalues-acq_value = wa_excel-acq_value .

  •  wa_cumulatedvalues-acq_value = wa_excel-l_ord_dep .
    wa_cumulatedvalues-ord_dep   = wa_excel-l_ord_dep * -1.
    
    " wa_cumulatedvalues-spe_dep = abs( wa_excel-ksafa ) * -1. " 以前年度特殊折旧
    APPEND wa_cumulatedvalues TO cumulatedvalues.
    

    ENDIF.

    "增加正常折旧
    IF wa_excel-m_ord_dep <> 0.
    wa_postedvalues-fisc_year = p_my.
    wa_postedvalues-area = dep_area-low.
    wa_postedvalues-ord_dep = wa_excel-m_ord_dep * -1.
    APPEND wa_postedvalues TO postedvalues.
    ENDIF.

    "增加购置价值

  • IF wa_excel-acq_value <> 0.

  •  wa_transactions-fisc_year  = p_my.
    
  •  wa_transactions-area       = dep_area-low.
    
  •  wa_transactions-current_no = sy-tabix.
    

** wa_transactions-valuedate = p_vd.

  •  wa_transactions-valuedate  = wa_excel-cap_date.
    
  •  wa_transactions-assettrtyp = '100'.
    
  •  wa_transactions-amount     = wa_excel-acq_value.
    
  •  APPEND wa_transactions TO transactions.
    
  • ENDIF.
    " ENDIF.
    "增强字段
    CLEAR:lt_extension.
    MOVE-CORRESPONDING wa_excel TO ls_exanlu.
    ls_extension-structure = ‘BAPI_TE_ANLU’.
    CALL METHOD cl_abap_container_utilities=>fill_container_c
    EXPORTING
    im_value = ls_exanlu
    IMPORTING
    ex_container = ls_extension-valuepart1
    EXCEPTIONS
    illegal_parameter_type = 1
    OTHERS = 2.
    APPEND ls_extension TO lt_extension .
    CLEAR ls_extension.
    CLEAR:ls_exanlu.
"清空结构体中的数据
CLEAR: wa_depreciationareas,
       wa_depreciationareasx,
       wa_cumulatedvalues,
       wa_postedvalues,
       wa_transactions.
" ENDLOOP.

"调用系统标准BAPI
CALL FUNCTION 'BAPI_FIXEDASSET_OVRTAKE_CREATE'
  EXPORTING
    key                 = key
    testrun             = tr
    generaldata         = generaldata
    generaldatax        = generaldatax
    inventory           = inventory
    inventoryx          = inventoryx
    postinginformation  = postinginformation
    postinginformationx = postinginformationx
    timedependentdata   = timedependentdata
    timedependentdatax  = timedependentdatax
    allocations         = allocations
    allocationsx        = allocationsx
    origin              = origin
    originx             = originx
  IMPORTING
    companycode         = companycode
    asset               = asset
    subnumber           = subnumber
  TABLES
    depreciationareas   = depreciationareas
    depreciationareasx  = depreciationareasx
    cumulatedvalues     = cumulatedvalues
    extensionin         = lt_extension
    postedvalues        = postedvalues
    transactions        = transactions
    return              = return.
READ TABLE return INTO wa_return INDEX 1.
IF wa_return-type EQ 'S'.
  "提交作业
  COMMIT WORK AND WAIT.
  •  IF asset IS NOT INITIAL.
    
  •    ls_anlu-bukrs = wa_excel-companycode.
    
  •    ls_anlu-anln1 =  asset.
    
  •    ls_anlu-anln2 = subnumber.
    

** ls_anlu-zzproj = wa_excel-zproj.
** ls_anlu-zzprojname = wa_excel-zprojname.
** ls_anlu-zzranln1 = wa_excel-zzranln1.
** ls_anlu-zzcanln1 = wa_excel-zzcanln1.
** ls_anlu-zzdep = wa_excel-zzdep.
** ls_anlu-zzsenr = wa_excel-zzsenr.
** ls_anlu-zzlocat = wa_excel-zzlocat.
** ls_anlu-zzuser = wa_excel-zzuser.

  •    MODIFY anlu FROM ls_anlu.
    

** CLEAR:ls_anlu.

  •  ENDIF.
    

    ELSE.
    ROLLBACK WORK.
    ENDIF.

    "处理输出消息
    wa_tab-assetclass = wa_excel-assetclass.
    wa_tab-companycode = wa_excel-companycode.
    wa_tab-asset = asset.
    wa_tab-subnumber = subnumber.
    wa_tab-invent_no = wa_excel-invent_no.
    wa_tab-descript = wa_excel-descript.
    READ TABLE return INTO wa_return INDEX 1.
    IF sy-subrc = 0.
    wa_tab-type = wa_return-type.
    wa_tab-id = wa_return-id.
    wa_tab-number = wa_return-number.
    wa_tab-message = wa_return-message.
    ENDIF.
    APPEND wa_tab TO it_tab.

    "清空所有临时数据
    CLEAR: wa_excel,
    generaldata,
    generaldatax,
    postinginformation,
    postinginformationx,
    timedependentdata,
    timedependentdatax,
    origin,
    originx,
    depreciationareas,
    depreciationareasx,
    cumulatedvalues,
    postedvalues,
    transactions,
    return,
    wa_return,
    wa_tab.
    ENDLOOP.
    ENDFORM.
    &---------------------------------------------------------------------
    *& Form FRM_INPUT_CHECK
    &---------------------------------------------------------------------
    *& text
    &---------------------------------------------------------------------
    *& --> p1 text
    *& <-- p2 text
    &---------------------------------------------------------------------
    FORM frm_input_check .
    IF p_fname IS INITIAL.
    MESSAGE ‘请输入文件路径’ TYPE ‘E’.
    ENDIF.

  • IF r_l = ‘X’ AND p_ly IS INITIAL.

  • MESSAGE ‘请输入往年’ TYPE ‘E’.

  • ENDIF.

  • IF r_m = ‘X’ AND p_my IS INITIAL.

  • MESSAGE ‘请输入当年’ TYPE ‘E’.

  • ENDIF.

  • IF r_m = ‘X’ AND p_vd IS INITIAL.

  • MESSAGE ‘请输入参考日期’ TYPE ‘E’.

  • ENDIF.
    ENDFORM.
    *DEP_AREA 折旧范围
    *P_FNAME 文件路径
    *P_LY 往年
    *P_MY 当年
    *P_VD 参考日期
    *R_L 处理往年数据
    *R_M 处理当年数据
    *TR 测试执行

你可能感兴趣的:(SAP-ABAP,sap)