ABAP固定资产创建BAPI无法自动写入增强字段处理
Posted SAP剑客
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了ABAP固定资产创建BAPI无法自动写入增强字段处理相关的知识,希望对你有一定的参考价值。
固定资产创建BAPI无法自动写入增强字段处理
通过实现增强点“AIST0002”给SAP固定资产主数据屏幕添加自定义字段(增强实现这里省略)。
(下图的增强字段仅供参考)
目前需要实现的功能是通过自定义程序审核用户上传的固定资产信息,审核通过后最后一个节点自动创建固定资产编号。
创建固定资产BAPI代码如下:
*&---------------------------------------------------------------------*
*& Form create_asset
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* -->PS_LS_ASSET text
* <--PS_LS_ASSET_CREATED text
* <--PS_WS_ERROR text
*----------------------------------------------------------------------*
FORM CREATE_ASSET USING PS_LS_ASSET TYPE ZMJMFIT033
CHANGING PS_LS_ASSET_CREATED TYPE BAPI1022_REFERENCE
PS_WS_ERROR TYPE STRING.
DATA:
LS_KEY TYPE BAPI1022_KEY,
LS_GENERAL_DATA TYPE BAPI1022_FEGLG001,
LS_GENERAL_DATA_X TYPE BAPI1022_FEGLG001X,
LS_INVENTORY TYPE BAPI1022_FEGLG011,
LS_INVENTORY_X TYPE BAPI1022_FEGLG011X,
LS_POSTING_INFORMATION TYPE BAPI1022_FEGLG002,
LS_POSTING_INFORMATION_X TYPE BAPI1022_FEGLG002X,
LS_TIME_DEPENDENT_DATA TYPE BAPI1022_FEGLG003,
LS_TIME_DEPENDENT_DATA_X TYPE BAPI1022_FEGLG003X,
LS_ALLOCATIONS TYPE BAPI1022_FEGLG004,
LS_ALLOCATIONS_X TYPE BAPI1022_FEGLG004X,
LS_ORIGIN TYPE BAPI1022_FEGLG009,
LS_ORIGIN_X TYPE BAPI1022_FEGLG009X,
LS_INVEST_ACCT_ASSIGNMNT TYPE BAPI1022_FEGLG010,
LS_INVEST_ACCT_ASSIGNMNT_X TYPE BAPI1022_FEGLG010X,
LS_REAL_ESTATE TYPE BAPI1022_FEGLG007,
LS_REAL_ESTATE_X TYPE BAPI1022_FEGLG007X,
LS_RETURN TYPE BAPIRET2,
LV_WBS_ELEMENT TYPE PS_POSID."CHAR-24
DATA:LS_EXTENSIONIN TYPE BAPIPAREX,
LT_EXTENSIONIN TYPE STANDARD TABLE OF BAPIPAREX,
LT_DEPRECIATIONAREAS TYPE STANDARD TABLE OF BAPI1022_DEP_AREAS,"折旧信息填制
LS_DEPRECIATIONAREAS LIKE LINE OF LT_DEPRECIATIONAREAS,
LT_DEPRECIATIONAREASX TYPE STANDARD TABLE OF BAPI1022_DEP_AREASX,"折旧信息信息更新
LS_DEPRECIATIONAREASX LIKE LINE OF LT_DEPRECIATIONAREASX,
LS_ANLU TYPE BAPI_TE_ANLU.
"公司代码
LS_KEY-COMPANYCODE = PS_LS_ASSET-BUKRS.
"资产分类
LS_GENERAL_DATA-ASSETCLASS = PS_LS_ASSET-ANLKL.
LS_GENERAL_DATA_X-ASSETCLASS = C_UPDATED.
"资产描述
LS_GENERAL_DATA-DESCRIPT = PS_LS_ASSET-TXT50.
LS_GENERAL_DATA_X-DESCRIPT = C_UPDATED.
"数量
LS_GENERAL_DATA-QUANTITY = PS_LS_ASSET-MENGE.
LS_GENERAL_DATA_X-QUANTITY = C_UPDATED.
"单位
LS_GENERAL_DATA-BASE_UOM = PS_LS_ASSET-MEINS.
LS_GENERAL_DATA_X-BASE_UOM = C_UPDATED.
"历史性管理
LS_GENERAL_DATA-HISTORY = C_UPDATED.
LS_GENERAL_DATA_X-HISTORY = C_UPDATED.
"成本中心
LS_TIME_DEPENDENT_DATA-COSTCENTER = PS_LS_ASSET-KOSTL.
LS_TIME_DEPENDENT_DATA_X-COSTCENTER = C_UPDATED.
"业务范围
LS_TIME_DEPENDENT_DATA-BUS_AREA = PS_LS_ASSET-GSBER.
LS_TIME_DEPENDENT_DATA_X-BUS_AREA = C_UPDATED.
"评估组1
LS_ALLOCATIONS-EVALGROUP1 = PS_LS_ASSET-ORD41.
LS_ALLOCATIONS_X-EVALGROUP1 = C_UPDATED.
"制造商
LS_ORIGIN-MANUFACTURER = PS_LS_ASSET-HERST.
LS_ORIGIN_X-MANUFACTURER = C_UPDATED.
"供应商
LS_ORIGIN-VENDOR_NO = PS_LS_ASSET-LIFNR.
LS_ORIGIN_X-VENDOR_NO = C_UPDATED.
"WBS要素
CALL FUNCTION 'CONVERSION_EXIT_ABPSP_OUTPUT'
EXPORTING
INPUT = PS_LS_ASSET-POSNR
IMPORTING
OUTPUT = LV_WBS_ELEMENT.
LS_INVEST_ACCT_ASSIGNMNT-WBS_ELEMENT = LV_WBS_ELEMENT.
LS_INVEST_ACCT_ASSIGNMNT_X-WBS_ELEMENT = C_UPDATED.
"折旧范围
* CLEAR LS_DEPRECIATIONAREAS.
* LS_DEPRECIATIONAREAS-AREA = '01'."折旧范围
* LS_DEPRECIATIONAREAS-DEP_KEY = PS_LS_ASSET-AFASL."折旧码
* LS_DEPRECIATIONAREAS-ULIFE_YRS = PS_LS_ASSET-NDJAR."使用年限
* APPEND LS_DEPRECIATIONAREAS TO LT_DEPRECIATIONAREAS.
"增强字段传值
CLEAR LS_ANLU.
LS_ANLU-COMP_CODE = PS_LS_ASSET-BUKRS. "公司代码
LS_ANLU-NAME2 = PS_LS_ASSET-NAME2."
LS_ANLU-KTEXT = PS_LS_ASSET-KTEXT."
LS_ANLU-LTEXT = PS_LS_ASSET-LTEXT."
LS_EXTENSIONIN-STRUCTURE = 'BAPI_TE_ANLU'.
LS_EXTENSIONIN-VALUEPART1 = LS_ANLU.
APPEND LS_EXTENSIONIN TO LT_EXTENSIONIN.
"调用BAPI
CALL FUNCTION 'BAPI_FIXEDASSET_CREATE1'
EXPORTING
KEY = LS_KEY
* TESTRUN = 'X'
GENERALDATA = LS_GENERAL_DATA
GENERALDATAX = LS_GENERAL_DATA_X
INVENTORY = LS_INVENTORY
INVENTORYX = LS_INVENTORY_X
POSTINGINFORMATION = LS_POSTING_INFORMATION
POSTINGINFORMATIONX = LS_POSTING_INFORMATION_X
TIMEDEPENDENTDATA = LS_TIME_DEPENDENT_DATA
TIMEDEPENDENTDATAX = LS_TIME_DEPENDENT_DATA_X
ALLOCATIONS = LS_ALLOCATIONS
ALLOCATIONSX = LS_ALLOCATIONS_X
ORIGIN = LS_ORIGIN
ORIGINX = LS_ORIGIN_X
INVESTACCTASSIGNMNT = LS_INVEST_ACCT_ASSIGNMNT
INVESTACCTASSIGNMNTX = LS_INVEST_ACCT_ASSIGNMNT_X
REALESTATE = LS_REAL_ESTATE
REALESTATEX = LS_REAL_ESTATE_X
IMPORTING
ASSETCREATED = PS_LS_ASSET_CREATED
RETURN = LS_RETURN
TABLES
DEPRECIATIONAREAS = LT_DEPRECIATIONAREAS
DEPRECIATIONAREASX = LT_DEPRECIATIONAREASX
EXTENSIONIN = LT_EXTENSIONIN.
IF LS_RETURN-TYPE = 'S'.
CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'.
* WRITE : '资产创建成功:',PS_LS_ASSET_CREATED-COMPANYCODE,
* PS_LS_ASSET_CREATED-ASSET,
* PS_LS_ASSET_CREATED-SUBNUMBER.
ELSE.
CALL FUNCTION 'BAPI_TRANSACTION_ROLLBACK'.
CLEAR: PS_LS_ASSET_CREATED.
MESSAGE ID LS_RETURN-ID TYPE LS_RETURN-TYPE
NUMBER LS_RETURN-NUMBER
WITH LS_RETURN-MESSAGE_V1
LS_RETURN-MESSAGE_V2
LS_RETURN-MESSAGE_V3
LS_RETURN-MESSAGE_V4
INTO PS_WS_ERROR.
ENDIF.
ENDFORM. " create_asset
BAPI执行后成功创建固定资产编号,但是用户自定义字段没有成功写入。
通过查看BAPI“BAPI_FIXEDASSET_CREATE1”代码发现,在Line174会调用Form方法处理增强字段信息。
这里可以清楚的看到该方法会调用用户出口进行字段检查,到这一步就可以发现具体的原因了。
完善上述FM的赋值即可。
以上是关于ABAP固定资产创建BAPI无法自动写入增强字段处理的主要内容,如果未能解决你的问题,请参考以下文章
使用BAPI_MATERIAL_SAVEDATA无法写入扩展字段
使用BAPI_MATERIAL_SAVEDATA无法写入扩展字段