文章目录
- 1 Introduction
- 2 Code
- 3 Summary
1 Introduction
In the example we will finish ABLDT function and modify asset value .
2 Code
DATA: key TYPE bapi1022_key,
generaldata TYPE bapi1022_feglg001,
generaldatax TYPE bapi1022_feglg001x,
postinginformation TYPE bapi1022_feglg002,
postinginformationx TYPE bapi1022_feglg002x,
allocations TYPE bapi1022_feglg004,
allocationsx TYPE bapi1022_feglg004x,
timedependentdata TYPE bapi1022_feglg003,
timedependentdatax TYPE bapi1022_feglg003x,
origin TYPE bapi1022_feglg009,
originx TYPE bapi1022_feglg009x,
transactions TYPE STANDARD TABLE OF bapi1022_trtype WITH HEADER LINE,
depreciationareas TYPE STANDARD TABLE OF bapi1022_dep_areas WITH HEADER LINE,
depreciationareasx TYPE STANDARD TABLE OF bapi1022_dep_areasx WITH HEADER LINE,
postedvalues TYPE STANDARD TABLE OF bapi1022_postval WITH HEADER LINE,
cumulatedvalues TYPE STANDARD TABLE OF bapi1022_cumval WITH HEADER LINE,
return TYPE STANDARD TABLE OF bapiret2 WITH HEADER LINE,
extensionin TYPE STANDARD TABLE OF bapiparex WITH HEADER LINE,
lt_investment_support TYPE STANDARD TABLE OF bapi1022_inv_support WITH HEADER LINE.
DATA:companycode LIKE bapi1022_1-comp_code,
asset LIKE bapi1022_1-assetmaino,
subnumber LIKE bapi1022_1-assetsubno.
CLEAR:gv_num,gv_count.
gv_num = lines( i_data )."上传条目数
LOOP AT i_data INTO wa_data.
IF wa_data-name06 IS INITIAL.
wa_data-message = TEXT-009.
wa_data-type = 'E'.
APPEND wa_data TO it_data.
CONTINUE.
ENDIF.
key-companycode = wa_data-name02. "公司代码
key-asset = wa_data-name34. "资产
key-subnumber = '0'. "次级编号
generaldata-assetclass = wa_data-name01. "资产分类
generaldatax-assetclass = 'X'.
generaldata-quantity = wa_data-name08. "数量
generaldatax-quantity = 'X'.
generaldata-base_uom = wa_data-name09. "基本计量单位
generaldatax-base_uom = 'X'.
generaldata-descript = wa_data-name03. "资产描述
generaldatax-descript = 'X'.
generaldata-descript2 = wa_data-name04. "附加资产描述
generaldatax-descript2 = 'X'.
generaldata-main_descript = wa_data-name05. "设备编码
generaldatax-main_descript = 'X'.
generaldata-invent_no = wa_data-name32. "存货号 EAS资产号
generaldatax-invent_no = 'X'.
postinginformation-cap_date = wa_data-name10.
postinginformationx-cap_date = 'X'. "资产资本化日期
timedependentdata-costcenter = wa_data-name11. "成本中心
timedependentdatax-costcenter = 'X'.
timedependentdata-plant = wa_data-name35. "工厂
timedependentdatax-plant = 'X'.
timedependentdata-bus_area = wa_data-name12. "业务范围
timedependentdatax-bus_area = 'X'.
origin-vendor_no = wa_data-name17. "供应商
originx-vendor_no = 'X'. "供应商
origin-manufacturer = wa_data-name33. "制造商 原始资产号
originx-manufacturer = 'X'. "制造商 原始资产号
origin-type_name = wa_data-name28. "类型名 原始购入日期
originx-type_name = 'X'.
allocations-evalgroup1 = wa_data-name16. "评审小组1使用状态
allocationsx-evalgroup1 = 'X'.
allocations-evalgroup2 = wa_data-name06. "评审小组2-资产来源 20200301 add by skyyan
allocationsx-evalgroup2 = 'X'.
" add it by sie_jinggl start 20240123
IF wa_data-name36 IS NOT INITIAL .
CLEAR:depreciationareas ,depreciationareasx , cumulatedvalues,transactions,postedvalues.
CLEAR depreciationareas[].
CLEAR depreciationareasx[].
depreciationareas-area = '01'.
depreciationareas-dep_key = wa_data-name19. "折旧码
depreciationareas-ulife_yrs = wa_data-name20. "计划年使用期
depreciationareas-ulife_prds = wa_data-name21. "计划使用期间
depreciationareas-odep_start_date = wa_data-name38. "折旧计算开始日期
APPEND depreciationareas.
depreciationareasx-area = '01'.
depreciationareasx-dep_key = 'X'. "折旧码
depreciationareasx-ulife_yrs = 'X'. "计划年使用期
depreciationareasx-ulife_prds = 'X'. "计划使用期间
depreciationareasx-exp_ulife_yrs = 'X'. "原始使用年
depreciationareasx-exp_ulife_prds = 'X'. "原始使用期间
depreciationareasx-odep_start_date = 'X'. " "
APPEND depreciationareasx.
CLEAR: cumulatedvalues[].
IF wa_data-name10+0(4) < sy-datum+0(4).
cumulatedvalues-fisc_year = sy-datum+0(4)."'2020'. "年度
cumulatedvalues-area = '01'. "范围
cumulatedvalues-acq_value = wa_data-name37. "购置价值
cumulatedvalues-ord_dep = 0 - wa_data-name26. "累积普通折旧
APPEND cumulatedvalues.
ELSE.
CLEAR transactions[].
IF wa_data-name38 IS NOT INITIAL.
transactions-valuedate = wa_data-name38.
transactions-current_no = '00001'.
transactions-fisc_year = sy-datum+0(4)."'2020'. "会计年
transactions-assettrtyp = '100'. "事物类型
transactions-area = '01'."wa_data-name33'. "折旧范围
transactions-amount = wa_data-name37. "记账金额
APPEND transactions.
ENDIF.
ENDIF.
IF wa_data-name27 <> 0.
CLEAR postedvalues[].
postedvalues-fisc_year = sy-datum+0(4)."'2020'. "年度
postedvalues-area = '01'. "范围
postedvalues-ord_dep = 0 - wa_data-name27. "一般折旧
APPEND postedvalues.
ENDIF.
*
ENDIF.
" add it by sie_jinggl start
" The function is depreciation Range2 .
IF wa_data-name39 IS NOT INITIAL .
CLEAR:depreciationareas ,depreciationareasx , cumulatedvalues,transactions,postedvalues.
depreciationareas-area = '20'.
depreciationareas-dep_key = wa_data-name40. "折旧码
depreciationareas-ulife_yrs = wa_data-name41. "计划年使用期
depreciationareas-ulife_prds = wa_data-name42. "计划使用期间
depreciationareas-odep_start_date = wa_data-name43. "折旧计算开始日期
APPEND depreciationareas.
depreciationareasx-area = '20'.
depreciationareasx-dep_key = 'X'. "折旧码
depreciationareasx-ulife_yrs = 'X'. "计划年使用期
depreciationareasx-ulife_prds = 'X'. "计划使用期间
depreciationareasx-exp_ulife_yrs = 'X'. "原始使用年
depreciationareasx-exp_ulife_prds = 'X'. "原始使用期间
depreciationareasx-odep_start_date = 'X'. "折旧计算开始日
"
APPEND depreciationareasx.
IF wa_data-name10+0(4) < sy-datum+0(4).
cumulatedvalues-fisc_year = sy-datum+0(4)."'2020'. "年度
cumulatedvalues-area = '20'. "范围
cumulatedvalues-acq_value = wa_data-name44. "购置价值
cumulatedvalues-ord_dep = 0 - wa_data-name45. "累积普通折旧
* cumulatedvalues-currency = 'USDT'.
* cumulatedvalues-currency_iso = 'USDT' .
APPEND cumulatedvalues.
ELSE.
IF wa_data-name38 IS NOT INITIAL.
transactions-valuedate = wa_data-name38.
transactions-current_no = '00001'.
transactions-fisc_year = sy-datum+0(4)."'2020'. "会计年
transactions-assettrtyp = '100'. "事物类型
transactions-area = '20'."wa_data-name33'. "折旧范围
transactions-amount = wa_data-name44. "记账金额
APPEND transactions.
ENDIF.
ENDIF.
* CLEAR postedvalues[].
IF wa_data-name46 <> 0.
postedvalues-fisc_year = sy-datum+0(4)."'2020'. "年度
postedvalues-area = '20'. "范围
postedvalues-ord_dep = 0 - wa_data-name46. "一般折旧
*
* postedvalues-currency = 'USDT'.
* postedvalues-currency_iso = 'USDT'.
* cumulatedvalues-currency_iso = 'TRY' .
APPEND postedvalues.
ENDIF.
ENDIF.
" The function is depreciation Range3 .
IF wa_data-name47 IS NOT INITIAL .
CLEAR:depreciationareas ,depreciationareasx , cumulatedvalues,transactions,postedvalues.
depreciationareas-area = '06'.
depreciationareas-dep_key = wa_data-name48. "折旧码
depreciationareas-ulife_yrs = wa_data-name49. "计划年使用期
depreciationareas-ulife_prds = wa_data-name50. "计划使用期间
depreciationareas-odep_start_date = wa_data-name51. "折旧计算开始日期
APPEND depreciationareas.
depreciationareasx-area = '06'.
depreciationareasx-dep_key = 'X'. "折旧码
depreciationareasx-ulife_yrs = 'X'. "计划年使用期
depreciationareasx-ulife_prds = 'X'. "计划使用期间
depreciationareasx-exp_ulife_yrs = 'X'. "原始使用年
depreciationareasx-exp_ulife_prds = 'X'. "原始使用期间
depreciationareasx-odep_start_date = 'X'. "折旧计算开始日
APPEND depreciationareasx.
IF wa_data-name10+0(4) < sy-datum+0(4).
cumulatedvalues-fisc_year = sy-datum+0(4)."'2020'. "年度
cumulatedvalues-area = '06'. "范围
cumulatedvalues-acq_value = wa_data-name52. "购置价值
cumulatedvalues-ord_dep = 0 - wa_data-name53. "累积普通折旧
APPEND cumulatedvalues.
ELSE.
IF wa_data-name38 IS NOT INITIAL.
transactions-valuedate = wa_data-name38.
transactions-current_no = '00001'.
transactions-fisc_year = sy-datum+0(4)."'2020'. "会计年
transactions-assettrtyp = '100'. "事物类型
transactions-area = '06'."wa_data-name33'. "折旧范围
transactions-amount = wa_data-name52. "记账金额
APPEND transactions.
ENDIF.
*
ENDIF.
* CLEAR postedvalues[].
IF wa_data-name54 <> 0 .
postedvalues-fisc_year = sy-datum+0(4)."'2020'. "年度
postedvalues-area = '06'. "范围
postedvalues-ord_dep = 0 - wa_data-name54. "一般折旧
APPEND postedvalues.
ENDIF.
ENDIF.
" The function is depreciation Range4 .
IF wa_data-name55 IS NOT INITIAL .
CLEAR:depreciationareas ,depreciationareasx , cumulatedvalues,transactions,postedvalues.
depreciationareas-area = '30'.
depreciationareas-dep_key = wa_data-name56. "折旧码
depreciationareas-ulife_yrs = wa_data-name57. "计划年使用期
depreciationareas-ulife_prds = wa_data-name58. "计划使用期间
depreciationareas-odep_start_date = wa_data-name59. "折旧计算开始日期
APPEND depreciationareas.
depreciationareasx-area = '30'.
depreciationareasx-dep_key = 'X'. "折旧码
depreciationareasx-ulife_yrs = 'X'. "计划年使用期
depreciationareasx-ulife_prds = 'X'. "计划使用期间
depreciationareasx-exp_ulife_yrs = 'X'. "原始使用年
depreciationareasx-exp_ulife_prds = 'X'. "原始使用期间
depreciationareasx-odep_start_date = 'X'. "折旧计算开始日
APPEND depreciationareasx.
IF wa_data-name10+0(4) < sy-datum+0(4).
cumulatedvalues-fisc_year = sy-datum+0(4)."'2020'. "年度
cumulatedvalues-area = '30'. "范围
cumulatedvalues-acq_value = wa_data-name60. "购置价值
cumulatedvalues-ord_dep = 0 - wa_data-name61. "累积普通折旧
* cumulatedvalues-currency = 'USDT'.
* cumulatedvalues-currency_iso = 'USDT' .
APPEND cumulatedvalues.
ELSE.
IF wa_data-name38 IS NOT INITIAL.
transactions-valuedate = wa_data-name38.
transactions-current_no = '00001'.
transactions-fisc_year = sy-datum+0(4)."'2020'. "会计年
transactions-assettrtyp = '100'. "事物类型
transactions-area = '01'."wa_data-name33'. "折旧范围
transactions-amount = wa_data-name60. "记账金额
APPEND transactions.
ENDIF.
ENDIF.
* CLEAR postedvalues[].
IF wa_data-name62 <> 0 .
postedvalues-fisc_year = sy-datum+0(4)."'2020'. "年度
postedvalues-area = '30'. "范围
postedvalues-ord_dep = 0 - wa_data-name62. "一般折旧
* postedvalues-currency = 'USDT'.
* postedvalues-currency_iso = 'USDT'.
APPEND postedvalues.
ENDIF.
ENDIF.
" add it by sie_jinggl end 20240123
gv_count = gv_count + 1.
gv_prog = '正在处理数据...' && gv_count && '/' && gv_num.
PERFORM frm_show_progress USING gv_prog.
CALL FUNCTION 'BAPI_FIXEDASSET_OVRTAKE_CREATE'
EXPORTING
key = key
generaldata = generaldata
generaldatax = generaldatax
* INVENTORY =
* 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
postedvalues = postedvalues
transactions = transactions
return = return.
APPEND return.
LOOP AT return WHERE type = 'E' OR type = 'A'.
ENDLOOP.
IF sy-subrc NE 0.
CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
EXPORTING
wait = 'X'.
wa_data-message = '成功'.
CONCATENATE asset wa_data-message INTO wa_data-message.
wa_data-type = 'S'.
APPEND wa_data TO it_data.
ELSE.
CALL FUNCTION 'BAPI_TRANSACTION_ROLLBACK'.
wa_data-message = return-message.
wa_data-type = 'E'.
APPEND wa_data TO it_data.
ENDIF.
CLEAR return[].
ENDLOOP.
3 Summary
Curr1 is local currency .
Curr2 is group currency.
If the system tell us htat we don’t changed it . We will cancel the field for deleting .
When the SAP system gets data by exchange rate and we hope we get value from input the following solution is here .
When I debug it and I find the control point is here (The system get data by exchange rate ).
When the field ‘wrtaft’ is not equal ‘00’ and we don’t get value by exchange rate .