AS01 创建固定资产卡片 BAPI_FIXEDASSET_CREATE1

1.折旧范围会自己带出来,要改的字段打x就行了

 

demo code

function zfm_erp_012.

*"----------------------------------------------------------------------

*"*"本地接口:

*"  TABLES

*"      T_DATA STRUCTURE  ZFM_ERP_012_DATA

*"----------------------------------------------------------------------

 

  data:

    ls_key                   type bapi1022_key,

    ls_general_data          type bapi1022_feglg001,

    ls_general_data_x        type bapi1022_feglg001x,

    ls_postinginformation    type bapi1022_feglg002,

    ls_postinginformationx   type bapi1022_feglg002x,

    ls_time_dependent_data   type bapi1022_feglg003,

    ls_time_dependent_data_x type bapi1022_feglg003x,

    ls_allocations           type bapi1022_feglg004,

    ls_allocationsx          type bapi1022_feglg004x,

    ls_investacctassignmnt   type bapi1022_feglg010,

    ls_investacctassignmntx  type bapi1022_feglg010x,

    ls_origin                type bapi1022_feglg009, "源

    ls_originx               type bapi1022_feglg009x.

 

***折旧范围

  data:

    lt_depreciationareas  like table of bapi1022_dep_areas,

    ls_epreciationareas   like line of lt_depreciationareas,

    lt_depreciationareasx like table of bapi1022_dep_areasx,

    ls_depreciationareasx like line of lt_depreciationareasx.

 

  "输出

  data:

    ls_return     type bapiret2,

    lv_message    type string,

    lv_assetmaino type bapi1022_1-assetmaino.

 

  do 2 times.

    if sy-index = 1.

      data(testrun) = 'X'.

    else.

      testrun = ''.

      read table t_data with key rtype = 'E'.

      if sy-subrc = 0.

        return.

      endif.

    endif.

  enddo.

  loop at t_data where rtype ne 'S'.

    t_data-anlkl = |{ t_data-anlkl alpha = in }|.

    t_data-eaufn = |{ t_data-eaufn alpha = in }|.

    t_data-kostl = |{ t_data-kostl alpha = in }|.

 

*要创建的关键字字段

    ls_key-companycode = t_data-bukrs." 公司代码

 

*逻辑字段组 001 - 通用数据

    ls_general_data-assetclass = t_data-anlkl.              "资产分类

    ls_general_data_x-assetclass = 'X'."相关用户数据字段的已更新信息

    ls_general_data-descript = t_data-txt50. "必输 描述

    ls_general_data_x-descript =  'X'.

    ls_general_data-descript2 =  t_data-txa50."可选 附加资产描述-填出厂编号

    ls_general_data_x-descript2 = 'X'.

    ls_general_data-serial_no = t_data-sernr ."序列号

    ls_general_data_x-serial_no = 'X'.

    ls_general_data-invent_no = t_data-invnr ."存货号

    ls_general_data_x-invent_no = 'X'.

    ls_general_data-quantity = t_data-menge. "数量

    ls_general_data_x-quantity = 'X'.

    ls_general_data-base_uom = t_data-meins. "基本计量单位

    ls_general_data_x-base_uom = 'X'.

 

*逻辑字段组002 - 记帐信息

    ls_postinginformation-cap_date = t_data-aktiv. "资本化日期

    ls_postinginformationx-cap_date = 'X'.

 

*逻辑字段组003 - 时间相关的数据

*    ls_time_dependent_data-bus_area = t_data-gsber . "业务范围

*    ls_time_dependent_data_x-bus_area = 'X' .

    ls_time_dependent_data-costcenter = t_data-kostl . "必输 成本中心

    ls_time_dependent_data_x-costcenter = 'X' .

 

*逻辑字段组004 - 分配

    ls_allocations-inv_reason = t_data-izwek. "投资原因

    ls_allocationsx-inv_reason = 'X'.

    ls_allocations-evalgroup1 = t_data-ord41 . "使用状态

    ls_allocationsx-evalgroup1 = 'X'.

    ls_allocations-evalgroup2 = t_data-ord42 . "经济用途

    ls_allocationsx-evalgroup2 = 'X'.

 

*逻辑字段组010 - 投资科目分配

    ls_investacctassignmnt-invest_ord = t_data-eaufn. "投资订单

    ls_investacctassignmntx-invest_ord = 'X'.

 

*折旧范围

    ls_epreciationareas-area = '01'. "实际折旧范围

    ls_epreciationareas-odep_start_date = t_data-afabg. "折旧计算开始日期

    append ls_epreciationareas to  lt_depreciationareas.

    ls_depreciationareasx-area = '01'.

    ls_depreciationareasx-odep_start_date =  'X'.

    append ls_depreciationareasx to lt_depreciationareasx.

    ls_epreciationareas-area = '02'. "实际折旧范围

    ls_epreciationareas-odep_start_date = t_data-afabg. "折旧计算开始日期

    append ls_epreciationareas to  lt_depreciationareas.

    ls_depreciationareasx-area = '02'.

    ls_depreciationareasx-odep_start_date =  'X'.

    append ls_depreciationareasx to lt_depreciationareasx.

    ls_epreciationareas-area = '03'. "实际折旧范围

    ls_epreciationareas-odep_start_date = t_data-afabg. "折旧计算开始日期

    append ls_epreciationareas to  lt_depreciationareas.

    ls_depreciationareasx-area = '03'.

    ls_depreciationareasx-odep_start_date =  'X'.

    append ls_depreciationareasx to lt_depreciationareasx.

    ls_epreciationareas-area = '04'. "实际折旧范围

    ls_epreciationareas-odep_start_date = t_data-afabg. "折旧计算开始日期

    append ls_epreciationareas to  lt_depreciationareas.

    ls_depreciationareasx-area = '04'.

    ls_depreciationareasx-odep_start_date =  'X'.

    append ls_depreciationareasx to lt_depreciationareasx.

 

*源

    ls_origin-vendor = t_data-lifnr. "供应商名称

    ls_originx-vendor = 'X'.

    ls_origin-manufacturer = t_data-herst. "资产制造商

    ls_originx-manufacturer = 'X'.

 

    call function 'BAPI_FIXEDASSET_CREATE1'

      exporting

        testrun              = testrun

        key                  = ls_key

        origin               = ls_origin

        originx              = ls_originx

        generaldata          = ls_general_data

        generaldatax         = ls_general_data_x

        postinginformation   = ls_postinginformation

        postinginformationx  = ls_postinginformationx

        allocations          = ls_allocations

        allocationsx         = ls_allocationsx

        investacctassignmnt  = ls_investacctassignmnt

        investacctassignmntx = ls_investacctassignmntx

        timedependentdata    = ls_time_dependent_data

        timedependentdatax   = ls_time_dependent_data_x

      importing

        asset                = lv_assetmaino

        return               = ls_return

      tables

        depreciationareas    = lt_depreciationareas

        depreciationareasx   = lt_depreciationareasx.

 

    if ls_return-type = 'S'.

      if testrun is initial.

        call function 'BAPI_TRANSACTION_COMMIT'

          exporting

            wait = 'X'.

        t_data-rtype = 'S'.

        t_data-rtmsg = '成功'.

        t_data-anln1 = |{ lv_assetmaino alpha = out }|.

      endif.

      if ls_return is not initial.

        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 lv_message.

      endif.

    else.

      call function 'BAPI_TRANSACTION_ROLLBACK'.

      if ls_return is not initial.

        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 lv_message.

      endif.

      t_data-rtype = 'E'.

      t_data-rtmsg = lv_message.

    endif.

    modify t_data.

  endloop.

 

 

 

endfunction.

 

猜你喜欢

转载自blog.csdn.net/cylcylcylcylwo/article/details/114077533